diff options
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/mod.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index 9f4a11a..c84a6fb 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -25,6 +25,11 @@ use std::{ process::exit, sync::Arc, }; +use syntect::highlighting::ThemeSet; + +/// Monokai Extended +const DARK_THEME: &[u8] = include_bytes!("../../assets/monokai-extended.theme.bin"); +const LIGHT_THEME: &[u8] = include_bytes!("../../assets/monokai-extended-light.theme.bin"); const CONFIG_FILE_NAME: &str = "config.yaml"; const ROLES_FILE_NAME: &str = "roles.yaml"; @@ -522,13 +527,32 @@ impl Config { } } - pub fn get_render_options(&self) -> RenderOptions { + pub fn get_render_options(&self) -> Result<RenderOptions> { + let theme = if self.highlight { + let theme_mode = if self.light_theme { "light" } else { "dark" }; + let theme_filename = format!("{theme_mode}.tmTheme"); + let theme_path = Self::local_path(&theme_filename)?; + if theme_path.exists() { + let theme = ThemeSet::get_theme(&theme_path) + .with_context(|| format!("Invalid theme at {}", theme_path.display()))?; + Some(theme) + } else { + let theme = if self.light_theme { + bincode::deserialize_from(LIGHT_THEME).expect("Invalid builtin light theme") + } else { + bincode::deserialize_from(DARK_THEME).expect("Invalid builtin dark theme") + }; + Some(theme) + } + } else { + None + }; let wrap = if stdout().is_terminal() { self.wrap.clone() } else { None }; - RenderOptions::new(self.highlight, self.light_theme, wrap, self.wrap_code) + Ok(RenderOptions::new(theme, wrap, self.wrap_code)) } pub fn maybe_print_send_tokens(&self, input: &str) { |
