Skip to content

Commit

Permalink
#235 improving colorterm test by separating into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
atluft committed Oct 16, 2020
1 parent 074e238 commit c0735e1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/onefetch/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ macro_rules! define_languages {
$( Language::$name => $colors, )*
Language::Unknown => define_colors!( [Color::White] ),
};
let use_true_color = env::var("COLORTERM");
if use_true_color.is_ok() && use_true_color.unwrap().to_lowercase() == "truecolor" && colors.true_colors.is_some() {
colors.true_colors.unwrap()
} else {
colors.basic_colors
match colors.true_colors {
Some( true_colors ) if is_truecolor_terminal() => true_colors,
_ => colors.basic_colors,
}
}
}

fn is_truecolor_terminal() -> bool {
env::var("COLORTERM")
.map( |colorterm| colorterm == "truecolor" || colorterm == "24bit" )
.unwrap_or(false)
}

fn get_all_language_types() -> Vec<tokei::LanguageType> {
vec![ $( tokei::LanguageType::$name ,)* ]
}
Expand Down

0 comments on commit c0735e1

Please sign in to comment.