From 4aab872ee1033df31827a35a1af2ee9f1ec2e2e7 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 11 Mar 2023 21:45:34 +0800 Subject: feat: add support for NO_COLOR (#67) --- src/config/mod.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/config/mod.rs') 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>; +pub type SharedConfig = Arc>; impl Config { pub fn init(is_interactive: bool) -> Result { @@ -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 { 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; + } + } } } -- cgit v1.2.3