mirror of
https://github.com/sharkdp/bat.git
synced 2025-04-14 06:40:39 +01:00
Always show a warning when theme is unknown
This commit is contained in:
parent
c899849101
commit
28397b8f78
14
src/app.rs
14
src/app.rs
@ -1,4 +1,3 @@
|
|||||||
use assets::HighlightingAssets;
|
|
||||||
use atty::{self, Stream};
|
use atty::{self, Stream};
|
||||||
use clap::{App as ClapApp, AppSettings, Arg, ArgGroup, ArgMatches, SubCommand};
|
use clap::{App as ClapApp, AppSettings, Arg, ArgGroup, ArgMatches, SubCommand};
|
||||||
use console::Term;
|
use console::Term;
|
||||||
@ -287,15 +286,8 @@ impl App {
|
|||||||
.matches
|
.matches
|
||||||
.value_of("theme")
|
.value_of("theme")
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
.or_else(|| {
|
.or_else(|| env::var("BAT_THEME").ok())
|
||||||
env::var("BAT_THEME").ok().and_then(|theme_name_env| {
|
.unwrap_or(String::from("Default")),
|
||||||
if HighlightingAssets::new().theme_exists(&theme_name_env) {
|
|
||||||
Some(theme_name_env)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
line_range: transpose(self.matches.value_of("line-range").map(LineRange::from))?,
|
line_range: transpose(self.matches.value_of("line-range").map(LineRange::from))?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -349,7 +341,7 @@ pub struct Config<'a> {
|
|||||||
pub paging_mode: PagingMode,
|
pub paging_mode: PagingMode,
|
||||||
pub term_width: usize,
|
pub term_width: usize,
|
||||||
pub files: Vec<Option<&'a str>>,
|
pub files: Vec<Option<&'a str>>,
|
||||||
pub theme: Option<String>,
|
pub theme: String,
|
||||||
pub line_range: Option<LineRange>,
|
pub line_range: Option<LineRange>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ use directories::ProjectDirs;
|
|||||||
use errors::*;
|
use errors::*;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use syntect::dumps::{dump_to_file, from_binary, from_reader};
|
use syntect::dumps::{dump_to_file, from_binary, from_reader};
|
||||||
use syntect::highlighting::{Theme, ThemeSet};
|
use syntect::highlighting::{Theme, ThemeSet};
|
||||||
@ -123,17 +122,19 @@ impl HighlightingAssets {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_theme(&self, theme: &str) -> Result<&Theme> {
|
pub fn get_theme(&self, theme: &str) -> &Theme {
|
||||||
Ok(self.theme_set.themes.get(theme).ok_or_else(|| {
|
match self.theme_set.themes.get(theme) {
|
||||||
io::Error::new(
|
Some(theme) => theme,
|
||||||
io::ErrorKind::Other,
|
None => {
|
||||||
format!("Could not find '{}' theme", theme),
|
use ansi_term::Colour::Yellow;
|
||||||
)
|
eprintln!(
|
||||||
})?)
|
"{}: Unknown theme '{}', using default.",
|
||||||
}
|
Yellow.paint("[bat warning]"),
|
||||||
|
theme
|
||||||
pub fn theme_exists(&self, theme: &str) -> bool {
|
);
|
||||||
self.theme_set.themes.contains_key(theme)
|
&self.theme_set.themes["Default"]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_syntax(&self, language: Option<&str>, filename: Option<&str>) -> &SyntaxDefinition {
|
pub fn get_syntax(&self, language: Option<&str>, filename: Option<&str>) -> &SyntaxDefinition {
|
||||||
|
@ -57,10 +57,7 @@ pub fn list_languages(assets: &HighlightingAssets, term_width: usize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_files(assets: &HighlightingAssets, config: &Config) -> Result<bool> {
|
pub fn print_files(assets: &HighlightingAssets, config: &Config) -> Result<bool> {
|
||||||
let theme = assets.get_theme(match config.theme {
|
let theme = assets.get_theme(&config.theme);
|
||||||
Some(ref theme_name) => theme_name,
|
|
||||||
None => "Default",
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut output_type = OutputType::from_mode(config.paging_mode);
|
let mut output_type = OutputType::from_mode(config.paging_mode);
|
||||||
let handle = output_type.handle()?;
|
let handle = output_type.handle()?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user