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