on master help sign in
Added BAT_STYLE env variable functionality
commit9d6bde48fa69adcc14633adc46025d9d68239159 authorms2300 <matt.sewall@gmail.com> dateSun 9 Sep 2018, 18:28 (8 years ago) parentd6c8fee
2 files changed+16−3
src/app.rs+15−3 src/assets.rs+1
src/app.rs+15−3
@@ -1,6 +1,7 @@
11use std::collections::HashSet;
22use std::env;
33use std::path::Path;
4+use std::str::FromStr;
45
56use atty::{self, Stream};
67
@@ -11,7 +12,7 @@ use console::Term;
1112#[cfg(windows)]
1213use ansi_term;
1314
14−use assets::BAT_THEME_DEFAULT;
15+use assets::{BAT_THEME_DEFAULT, BAT_STYLE_DEFAULT};
1516use errors::*;
1617use line_range::LineRange;
1718use style::{OutputComponent, OutputComponents, OutputWrap};
@@ -174,7 +175,7 @@ impl App {
174175 .takes_value(true)
175176 .possible_values(&[
176177 "auto", "full", "plain", "changes", "header", "grid", "numbers",
177− ]).default_value("auto")
178+ ])
178179 .help("Comma-separated list of style elements to display.")
179180 .long_help(
180181 "Configure which elements (line numbers, file headers, grid \
@@ -428,7 +429,7 @@ impl App {
428429 [OutputComponent::Numbers].iter().cloned().collect()
429430 } else if matches.is_present("plain") {
430431 [OutputComponent::Plain].iter().cloned().collect()
431− } else {
432+ } else if matches.is_present("style") {
432433 values_t!(matches.values_of("style"), OutputComponent)?
433434 .into_iter()
434435 .map(|style| style.components(self.interactive_output))
@@ -436,6 +437,17 @@ impl App {
436437 acc.extend(components.iter().cloned());
437438 acc
438439 })
440+ } else {
441+ let style = env::var("BAT_STYLE").unwrap_or(String::from(BAT_STYLE_DEFAULT));
442+ match OutputComponent::from_str(&style) {
443+ Ok(s) => [s].iter()
444+ .map(|style| style.components(self.interactive_output))
445+ .fold(HashSet::new(), |mut acc, components| {
446+ acc.extend(components.iter().cloned());
447+ acc
448+ }),
449+ Err(_) => HashSet::new(),
450+ }
439451 },
440452 ))
441453 }
src/assets.rs+1
@@ -18,6 +18,7 @@ lazy_static! {
1818 ProjectDirs::from("", "", crate_name!()).expect("Could not get home directory");
1919}
2020
21+pub const BAT_STYLE_DEFAULT: &str = "auto";
2122pub const BAT_THEME_DEFAULT: &str = "Monokai Extended";
2223
2324pub struct HighlightingAssets {