summaryrefslogtreecommitdiffstats
path: root/src/config/mod.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-03-11 21:45:34 +0800
committerGitHub <noreply@github.com>2023-03-11 21:45:34 +0800
commit4aab872ee1033df31827a35a1af2ee9f1ec2e2e7 (patch)
tree3e8f8dae818103fc551589d22b15c68068498921 /src/config/mod.rs
parentcfb6ce6958751da5e13683ea07f42a5dbc4eae01 (diff)
downloadaichat-4aab872ee1033df31827a35a1af2ee9f1ec2e2e7.tar.gz
feat: add support for NO_COLOR (#67)
Diffstat (limited to 'src/config/mod.rs')
-rw-r--r--src/config/mod.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 96f19db..b0cd6c0 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -10,7 +10,7 @@ use crate::utils::now;
use anyhow::{anyhow, bail, Context, Result};
use inquire::{Confirm, Text};
-use parking_lot::Mutex;
+use parking_lot::RwLock;
use serde::Deserialize;
use std::{
env,
@@ -85,7 +85,7 @@ impl Default for Config {
}
}
-pub type SharedConfig = Arc<Mutex<Config>>;
+pub type SharedConfig = Arc<RwLock<Config>>;
impl Config {
pub fn init(is_interactive: bool) -> Result<Self> {
@@ -284,6 +284,7 @@ impl Config {
("highlight", self.highlight.to_string()),
("proxy", proxy),
("conversation_first", self.conversation_first.to_string()),
+ ("light_theme", self.light_theme.to_string()),
("dry_run", self.dry_run.to_string()),
];
let mut output = String::new();
@@ -378,6 +379,10 @@ impl Config {
Ok(())
}
+ pub fn get_render_options(&self) -> (bool, bool) {
+ (self.highlight, self.light_theme)
+ }
+
fn open_message_file(&self) -> Result<File> {
let path = Config::messages_file()?;
ensure_parent_exists(&path)?;
@@ -417,6 +422,13 @@ impl Config {
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);
+ if no_color {
+ self.highlight = false;
+ }
+ }
}
}