diff --git a/src/app.rs b/src/app.rs index c7e8a9d2..7cd78f48 100644 --- a/src/app.rs +++ b/src/app.rs @@ -85,6 +85,17 @@ impl App { .long("list-languages") .help("Displays supported languages"), ) + .arg( + Arg::with_name("theme") + .long("theme") + .takes_value(true) + .help("Set the theme for highlighting"), + ) + .arg( + Arg::with_name("list-themes") + .long("list-themes") + .help("Displays supported themes"), + ) .subcommand( SubCommand::with_name("cache") .about("Modify the syntax-definition and theme cache") @@ -143,6 +154,7 @@ impl App { }, term_width: Term::stdout().size().1 as usize, files, + theme: self.matches.value_of("theme"), }) } @@ -185,6 +197,7 @@ pub struct Config<'a> { pub paging: bool, pub term_width: usize, pub files: Vec>, + pub theme: Option<&'a str>, } fn is_truecolor_terminal() -> bool { diff --git a/src/assets.rs b/src/assets.rs index 147e0bd5..1bf60780 100644 --- a/src/assets.rs +++ b/src/assets.rs @@ -126,11 +126,13 @@ impl HighlightingAssets { Ok(()) } - pub fn default_theme(&self) -> Result<&Theme> { - Ok(self.theme_set - .themes - .get("Default") - .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Could not find 'Default' theme"))?) + 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), + ) + })?) } } diff --git a/src/main.rs b/src/main.rs index e0639af0..bcac470c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -223,7 +223,7 @@ fn run() -> Result<()> { let config = app.config()?; let assets = HighlightingAssets::new(); - let theme = assets.default_theme()?; + let theme = assets.get_theme(config.theme.unwrap_or("Default"))?; if app.matches.is_present("list-languages") { let languages = assets.syntax_set.syntaxes(); @@ -269,6 +269,14 @@ fn run() -> Result<()> { return Ok(()); } + if app.matches.is_present("list-themes") { + let themes = &assets.theme_set.themes; + for (theme, _) in themes.iter() { + println!("{}", theme); + } + return Ok(()); + } + let mut output_type = get_output_type(config.paging); let handle = output_type.handle()?; let mut printer = Printer::new(handle, &config);