mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-03 11:29:24 +01:00
Merge pull request #298 from ms2300/bat_style
#208 Added BAT_STYLE env variable functionality
This commit is contained in:
commit
ea369ee17f
19
src/app.rs
19
src/app.rs
@ -1,6 +1,7 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use atty::{self, Stream};
|
use atty::{self, Stream};
|
||||||
|
|
||||||
@ -178,14 +179,15 @@ impl App {
|
|||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.possible_values(&[
|
.possible_values(&[
|
||||||
"auto", "full", "plain", "changes", "header", "grid", "numbers",
|
"auto", "full", "plain", "changes", "header", "grid", "numbers",
|
||||||
]).default_value("auto")
|
])
|
||||||
.help("Comma-separated list of style elements to display.")
|
.help("Comma-separated list of style elements to display.")
|
||||||
.long_help(
|
.long_help(
|
||||||
"Configure which elements (line numbers, file headers, grid \
|
"Configure which elements (line numbers, file headers, grid \
|
||||||
borders, Git modifications, ..) to display in addition to the \
|
borders, Git modifications, ..) to display in addition to the \
|
||||||
file contents. The argument is a comma-separated list of \
|
file contents. The argument is a comma-separated list of \
|
||||||
components to display (e.g. 'numbers,changes,grid') or a \
|
components to display (e.g. 'numbers,changes,grid') or a \
|
||||||
pre-defined style ('full')",
|
pre-defined style ('full'). To set a default theme, export the \
|
||||||
|
BAT_STYLE environment variable (e.g.: export BAT_STYLE=\"numbers\").",
|
||||||
),
|
),
|
||||||
).arg(
|
).arg(
|
||||||
Arg::with_name("plain")
|
Arg::with_name("plain")
|
||||||
@ -462,7 +464,18 @@ impl App {
|
|||||||
} else if matches.is_present("plain") {
|
} else if matches.is_present("plain") {
|
||||||
[OutputComponent::Plain].iter().cloned().collect()
|
[OutputComponent::Plain].iter().cloned().collect()
|
||||||
} else {
|
} else {
|
||||||
values_t!(matches.values_of("style"), OutputComponent)?
|
let env_style_components: Option<Vec<OutputComponent>> =
|
||||||
|
transpose(env::var("BAT_STYLE").ok().map(|style_str| {
|
||||||
|
style_str
|
||||||
|
.split(",")
|
||||||
|
.map(|x| OutputComponent::from_str(&x))
|
||||||
|
.collect::<Result<Vec<OutputComponent>>>()
|
||||||
|
}))?;
|
||||||
|
|
||||||
|
values_t!(matches.values_of("style"), OutputComponent)
|
||||||
|
.ok()
|
||||||
|
.or(env_style_components)
|
||||||
|
.unwrap_or(vec![OutputComponent::Full])
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|style| style.components(self.interactive_output))
|
.map(|style| style.components(self.interactive_output))
|
||||||
.fold(HashSet::new(), |mut acc, components| {
|
.fold(HashSet::new(), |mut acc, components| {
|
||||||
|
@ -54,7 +54,8 @@ impl FromStr for OutputComponent {
|
|||||||
"header" => Ok(OutputComponent::Header),
|
"header" => Ok(OutputComponent::Header),
|
||||||
"numbers" => Ok(OutputComponent::Numbers),
|
"numbers" => Ok(OutputComponent::Numbers),
|
||||||
"full" => Ok(OutputComponent::Full),
|
"full" => Ok(OutputComponent::Full),
|
||||||
"plain" | _ => Ok(OutputComponent::Plain),
|
"plain" => Ok(OutputComponent::Plain),
|
||||||
|
_ => Err(format!("Unknown style '{}'", s).into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user