mirror of
https://github.com/sharkdp/bat.git
synced 2024-12-24 15:28:51 +01:00
Use a more streamlined version of style-component collection
This commit is contained in:
parent
7897260bf0
commit
dccf8d8221
29
src/app.rs
29
src/app.rs
@ -12,7 +12,7 @@ use console::Term;
|
||||
#[cfg(windows)]
|
||||
use ansi_term;
|
||||
|
||||
use assets::{BAT_STYLE_DEFAULT, BAT_THEME_DEFAULT};
|
||||
use assets::BAT_THEME_DEFAULT;
|
||||
use errors::*;
|
||||
use line_range::LineRange;
|
||||
use style::{OutputComponent, OutputComponents, OutputWrap};
|
||||
@ -430,26 +430,25 @@ impl App {
|
||||
[OutputComponent::Numbers].iter().cloned().collect()
|
||||
} else if matches.is_present("plain") {
|
||||
[OutputComponent::Plain].iter().cloned().collect()
|
||||
} else if matches.is_present("style") {
|
||||
values_t!(matches.values_of("style"), OutputComponent)?
|
||||
} else {
|
||||
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()
|
||||
.map(|style| style.components(self.interactive_output))
|
||||
.fold(HashSet::new(), |mut acc, components| {
|
||||
acc.extend(components.iter().cloned());
|
||||
acc
|
||||
})
|
||||
} else {
|
||||
let style_str = env::var("BAT_STYLE").unwrap_or(String::from(BAT_STYLE_DEFAULT));
|
||||
style_str
|
||||
.split(",")
|
||||
.map(|x| OutputComponent::from_str(&x))
|
||||
.map(|s| match s {
|
||||
Ok(style) => style.components(self.interactive_output),
|
||||
Err(_) => &[],
|
||||
}).fold(HashSet::new(), |mut acc, components| {
|
||||
acc.extend(components.iter().cloned());
|
||||
acc
|
||||
})
|
||||
},
|
||||
))
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ lazy_static! {
|
||||
ProjectDirs::from("", "", crate_name!()).expect("Could not get home directory");
|
||||
}
|
||||
|
||||
pub const BAT_STYLE_DEFAULT: &str = "auto";
|
||||
pub const BAT_THEME_DEFAULT: &str = "Monokai Extended";
|
||||
|
||||
pub struct HighlightingAssets {
|
||||
|
@ -54,7 +54,8 @@ impl FromStr for OutputComponent {
|
||||
"header" => Ok(OutputComponent::Header),
|
||||
"numbers" => Ok(OutputComponent::Numbers),
|
||||
"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