mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-23 00:03:27 +01:00
Automatically disable wrapping when style is plain.
This commit is contained in:
parent
fb61aa4f60
commit
d8030626f8
24
src/app.rs
24
src/app.rs
@ -190,11 +190,10 @@ impl App {
|
|||||||
.long("plain")
|
.long("plain")
|
||||||
.conflicts_with("style")
|
.conflicts_with("style")
|
||||||
.conflicts_with("number")
|
.conflicts_with("number")
|
||||||
.conflicts_with("wrap")
|
.help("Show plain style (alias for '--style=plain'.")
|
||||||
.help("Show plain style (alias for '--style=plain' and '--wrap=never').")
|
|
||||||
.long_help(
|
.long_help(
|
||||||
"Only show plain style, no decorations, no wrapping. This is an alias for \
|
"Only show plain style, no decorations. This is an alias for \
|
||||||
'--style=plain' and '--wrap=never'",
|
'--style=plain'",
|
||||||
),
|
),
|
||||||
).arg(
|
).arg(
|
||||||
Arg::with_name("number")
|
Arg::with_name("number")
|
||||||
@ -264,8 +263,8 @@ impl App {
|
|||||||
.overrides_with("wrap")
|
.overrides_with("wrap")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("mode")
|
.value_name("mode")
|
||||||
.possible_values(&["character", "never"])
|
.possible_values(&["auto", "never", "character"])
|
||||||
.default_value("character")
|
.default_value("auto")
|
||||||
.help("Specify the text-wrapping mode.")
|
.help("Specify the text-wrapping mode.")
|
||||||
.long_help("Specify the text-wrapping mode."),
|
.long_help("Specify the text-wrapping mode."),
|
||||||
).arg(
|
).arg(
|
||||||
@ -340,22 +339,24 @@ impl App {
|
|||||||
|
|
||||||
pub fn config(&self) -> Result<Config> {
|
pub fn config(&self) -> Result<Config> {
|
||||||
let files = self.files();
|
let files = self.files();
|
||||||
|
let output_components = self.output_components()?;
|
||||||
|
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
true_color: is_truecolor_terminal(),
|
true_color: is_truecolor_terminal(),
|
||||||
output_components: self.output_components()?,
|
|
||||||
language: self.matches.value_of("language"),
|
language: self.matches.value_of("language"),
|
||||||
output_wrap: if !self.interactive_output {
|
output_wrap: if !self.interactive_output {
|
||||||
// We don't have the tty width when piping to another program.
|
// We don't have the tty width when piping to another program.
|
||||||
// There's no point in wrapping when this is the case.
|
// There's no point in wrapping when this is the case.
|
||||||
OutputWrap::None
|
OutputWrap::None
|
||||||
} else if self.matches.is_present("plain") {
|
|
||||||
// No point in wrapping when it's plain.
|
|
||||||
OutputWrap::None
|
|
||||||
} else {
|
} else {
|
||||||
match self.matches.value_of("wrap") {
|
match self.matches.value_of("wrap") {
|
||||||
Some("character") => OutputWrap::Character,
|
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") {
|
colored_output: match self.matches.value_of("color") {
|
||||||
@ -397,6 +398,7 @@ impl App {
|
|||||||
.or_else(|| env::var("BAT_THEME").ok())
|
.or_else(|| env::var("BAT_THEME").ok())
|
||||||
.unwrap_or(String::from(BAT_THEME_DEFAULT)),
|
.unwrap_or(String::from(BAT_THEME_DEFAULT)),
|
||||||
line_range: transpose(self.matches.value_of("line-range").map(LineRange::from))?,
|
line_range: transpose(self.matches.value_of("line-range").map(LineRange::from))?,
|
||||||
|
output_components,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,4 +78,8 @@ impl OutputComponents {
|
|||||||
pub fn numbers(&self) -> bool {
|
pub fn numbers(&self) -> bool {
|
||||||
self.0.contains(&OutputComponent::Numbers)
|
self.0.contains(&OutputComponent::Numbers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn plain(&self) -> bool {
|
||||||
|
self.0.is_empty()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user