Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable wrapping when --plain is used. (Fixes #289) #291

Merged
merged 5 commits into from
Sep 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ impl App {
.overrides_with("wrap")
.takes_value(true)
.value_name("mode")
.possible_values(&["character", "never"])
.default_value("character")
.possible_values(&["auto", "never", "character"])
.default_value("auto")
.help("Specify the text-wrapping mode.")
.long_help("Specify the text-wrapping mode."),
).arg(
Expand Down Expand Up @@ -339,10 +339,10 @@ impl App {

pub fn config(&self) -> Result<Config> {
let files = self.files();
let output_components = self.output_components()?;

Ok(Config {
true_color: is_truecolor_terminal(),
output_components: self.output_components()?,
language: self.matches.value_of("language"),
output_wrap: if !self.interactive_output {
// We don't have the tty width when piping to another program.
Expand All @@ -351,7 +351,12 @@ impl App {
} else {
match self.matches.value_of("wrap") {
Some("character") => OutputWrap::Character,
Some("never") | _ => OutputWrap::None,
Some("never") => OutputWrap::None,
Some("auto") | _ => if output_components.plain() {
OutputWrap::None
} else {
OutputWrap::Character
},
}
},
colored_output: match self.matches.value_of("color") {
Expand Down Expand Up @@ -395,6 +400,7 @@ impl App {
.or_else(|| env::var("BAT_THEME").ok())
.unwrap_or(String::from(BAT_THEME_DEFAULT)),
line_range: transpose(self.matches.value_of("line-range").map(LineRange::from))?,
output_components,
})
}

Expand Down
4 changes: 4 additions & 0 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ impl OutputComponents {
pub fn numbers(&self) -> bool {
self.0.contains(&OutputComponent::Numbers)
}

pub fn plain(&self) -> bool {
self.0.is_empty()
}
}