1
0
mirror of https://github.com/sharkdp/bat synced 2026-08-08 19:41:45 +00:00

Allow specifying the theme via the BAT_THEME environment variable

The `--theme` command line option stills takes precedence and this
change preserves how errors are handled when it's used: If a theme name
that doesn't exist is specified using the argument, this error is fatal.
However, if a theme that doesn't exist is specified using the environment
variable, the error is logged to `stderr` and the "Default" theme is
loaded as a fallback.
This commit is contained in:
Armando Perez
2018-07-20 23:26:24 -07:00
committed by David Peter
parent 6b57f4eebc
commit c68aa0f424
3 changed files with 23 additions and 3 deletions
+5 -1
View File
@@ -57,7 +57,11 @@ pub fn list_languages(assets: &HighlightingAssets, term_width: usize) {
}
pub fn print_files(assets: &HighlightingAssets, config: &Config) -> Result<bool> {
let theme = assets.get_theme(config.theme.unwrap_or("Default"))?;
let theme = assets.get_theme(match config.theme {
Some(ref theme_name) => theme_name,
None => "Default",
})?;
let mut output_type = OutputType::from_mode(config.paging_mode);
let handle = output_type.handle()?;
let mut printer = Printer::new(handle, &config);