diff options
| author | sigoden <sigoden@gmail.com> | 2023-10-29 17:22:23 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-29 17:22:23 +0800 |
| commit | 1ced15a2098f1469b2dd7d59636fdcdc710efc22 (patch) | |
| tree | 159b76ea877291741903f97f873e28bcb259a8e3 /src/config/mod.rs | |
| parent | 10b1d4b4de521a48747c73d29e9fe3f06db48a32 (diff) | |
| download | aichat-1ced15a2098f1469b2dd7d59636fdcdc710efc22.tar.gz | |
feat: autodetect light theme on unix-like os (#168)
Diffstat (limited to 'src/config/mod.rs')
| -rw-r--r-- | src/config/mod.rs | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index 64a3299..922fb0a 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -129,6 +129,7 @@ impl Config { config.merge_env_vars(); config.load_roles()?; config.ensure_sessions_dir()?; + config.check_term_theme()?; Ok(config) } @@ -546,9 +547,6 @@ impl Config { } fn merge_env_vars(&mut self) { - if let Ok(value) = env::var(get_env_name("light_theme")) { - set_bool(&mut self.light_theme, &value); - } if let Ok(value) = env::var("NO_COLOR") { let mut no_color = false; set_bool(&mut no_color, &value); @@ -568,6 +566,23 @@ impl Config { Ok(()) } + fn check_term_theme(&mut self) -> Result<()> { + if self.light_theme { + return Ok(()); + } + if let Ok(value) = env::var(get_env_name("light_theme")) { + set_bool(&mut self.light_theme, &value); + return Ok(()); + } + #[cfg(not(target_os = "windows"))] + if let Ok(crate::utils::termbg::Theme::Light) = + crate::utils::termbg::theme(std::time::Duration::from_millis(200)) + { + self.light_theme = true; + } + Ok(()) + } + fn compat_old_config(&mut self, config_path: &PathBuf) -> Result<()> { let content = read_to_string(config_path)?; let value: serde_json::Value = serde_yaml::from_str(&content)?; |
