1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-14 01:02:25 +01:00

Always show a warning when theme is unknown

This commit is contained in:
sharkdp
2018-07-23 21:38:45 +02:00
committed by David Peter
parent c899849101
commit 28397b8f78
3 changed files with 17 additions and 27 deletions

View File

@@ -2,7 +2,6 @@ use directories::ProjectDirs;
use errors::*;
use std::borrow::Cow;
use std::fs::{self, File};
use std::io;
use std::path::{Path, PathBuf};
use syntect::dumps::{dump_to_file, from_binary, from_reader};
use syntect::highlighting::{Theme, ThemeSet};
@@ -123,17 +122,19 @@ impl HighlightingAssets {
Ok(())
}
pub fn get_theme(&self, theme: &str) -> Result<&Theme> {
Ok(self.theme_set.themes.get(theme).ok_or_else(|| {
io::Error::new(
io::ErrorKind::Other,
format!("Could not find '{}' theme", theme),
)
})?)
}
pub fn theme_exists(&self, theme: &str) -> bool {
self.theme_set.themes.contains_key(theme)
pub fn get_theme(&self, theme: &str) -> &Theme {
match self.theme_set.themes.get(theme) {
Some(theme) => theme,
None => {
use ansi_term::Colour::Yellow;
eprintln!(
"{}: Unknown theme '{}', using default.",
Yellow.paint("[bat warning]"),
theme
);
&self.theme_set.themes["Default"]
}
}
}
pub fn get_syntax(&self, language: Option<&str>, filename: Option<&str>) -> &SyntaxDefinition {