From cfb6ce6958751da5e13683ea07f42a5dbc4eae01 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 11 Mar 2023 18:53:36 +0800 Subject: feat: support light theme (#65) There are two ways to enable the light theme: - add `light_theme: true` to config.yaml - use `AICHAT_LIGHT_THEME=true` env var --- src/config/mod.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/config') diff --git a/src/config/mod.rs b/src/config/mod.rs index a670d00..96f19db 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -54,6 +54,8 @@ pub struct Config { pub dry_run: bool, /// If set ture, start a conversation immediately upon repl pub conversation_first: bool, + /// Is ligth theme + pub light_theme: bool, /// Predefined roles #[serde(skip)] pub roles: Vec, @@ -75,6 +77,7 @@ impl Default for Config { proxy: None, dry_run: false, conversation_first: false, + light_theme: false, roles: vec![], role: None, conversation: None, @@ -409,11 +412,10 @@ impl Config { fn merge_env_vars(&mut self) { if let Ok(value) = env::var(get_env_name("dry_run")) { - match value.as_str() { - "1" | "true" => self.dry_run = true, - "0" | "false" => self.dry_run = false, - _ => {} - } + set_bool(&mut self.dry_run, &value); + } + if let Ok(value) = env::var(get_env_name("light_theme")) { + set_bool(&mut self.light_theme, &value); } } } @@ -479,3 +481,11 @@ fn get_env_name(key: &str) -> String { key.to_ascii_uppercase(), ) } + +fn set_bool(target: &mut bool, value: &str) { + match value { + "1" | "true" => *target = true, + "0" | "false" => *target = false, + _ => {} + } +} -- cgit v1.2.3