From 1af9ded3ce71eecade534dbc2124d7dc9e1c58c8 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 12 Jan 2020 21:53:59 -0800 Subject: [PATCH] Add color_scheme configuration option I'll write up more comprehensive docs once CI has proven that the color schemes are packaged correctly. The gist of it is that you can now specify: ``` color_scheme = "Batman" ``` to specify the default color palette. The name corresponds to one of the color schemes from the `assets/colors` directory. That directory is packaged and installed by the CI deployment script, but we're also able to load them from the source dir if you're running from in the wezterm source tree. You can see previews of the various schemes here: In addition to loading from those that path, wezterm will search: * In the `config` dir that is a sibling to `wezterm.exe` on windows (not yet tested!) * The directories specified in your `color_scheme_dirs` config setting (multiple paths can be specified) * You may also define schemes directly inline in your config file using syntax like this: ``` [color_schemes."My Name"] foreground = "#4a4543" background = "#f7f7f7" ``` --- src/config/mod.rs | 12 ++++++++++++ src/config/terminal.rs | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 44ef0dc45..d28eed157 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -275,6 +275,10 @@ pub struct Config { /// The color palette pub colors: Option, + /// Use a named color scheme rather than the palette specified + /// by the colors setting. + pub color_scheme: Option, + /// Named color schemes #[serde(default)] pub color_schemes: HashMap, @@ -641,6 +645,14 @@ impl Config { cfg.load_color_schemes(&cfg.compute_color_scheme_dirs()) .ok(); + if let Some(scheme) = cfg.color_scheme.as_ref() { + if !cfg.color_schemes.contains_key(scheme) { + log::error!("Your configuration specifies \ + color_scheme=\"{}\" but that scheme \ + was not found", scheme); + } + } + cfg } diff --git a/src/config/terminal.rs b/src/config/terminal.rs index 71953d37d..0fdd61c7a 100644 --- a/src/config/terminal.rs +++ b/src/config/terminal.rs @@ -22,7 +22,15 @@ impl term::TerminalConfiguration for TermConfig { } fn color_palette(&self) -> ColorPalette { - configuration() + let config = configuration(); + + if let Some(scheme_name) = config.color_scheme.as_ref() { + if let Some(palette) = config.color_schemes.get(scheme_name) { + return palette.clone().into(); + } + } + + config .colors .as_ref() .cloned()