From 957ea431c23dd6cbaa512e6a67b4a25e2adf08e4 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 5 Mar 2023 19:48:22 +0800 Subject: refactor: rename config.no_highlight to highlight (#19) --- src/config.rs | 8 ++++++-- src/main.rs | 2 +- src/repl.rs | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/config.rs b/src/config.rs index 61a6998..802f376 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,8 +27,8 @@ pub struct Config { #[serde(default)] pub save: bool, /// Whether to disable highlight - #[serde(default)] - pub no_highlight: bool, + #[serde(default = "highlight_value")] + pub highlight: bool, /// Set proxy pub proxy: Option, /// Used only for debugging @@ -195,3 +195,7 @@ fn create_config_file(config_path: &Path) -> Result<()> { std::fs::write(config_path, raw_config).with_context(|| "Failed to write to config file")?; Ok(()) } + +fn highlight_value() -> bool { + true +} diff --git a/src/main.rs b/src/main.rs index 917a20f..4f5198c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -60,7 +60,7 @@ fn start_directive( let role_name = role.as_ref().map(|v| v.name.to_string()); let output = client.acquire(input, prompt)?; let output = output.trim(); - if !config.no_highlight && stdout().is_terminal() { + if config.highlight && stdout().is_terminal() { let markdown_render = MarkdownRender::init()?; markdown_render.print(output)?; } else { diff --git a/src/repl.rs b/src/repl.rs index b507d89..98f43f1 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -257,10 +257,10 @@ struct ReplCmdHandlerState { impl ReplCmdHandler { pub fn init(client: ChatGptClient, config: Arc, role: Option) -> Result { - let render = if config.no_highlight { - None - } else { + let render = if config.highlight { Some(Arc::new(MarkdownRender::init()?)) + } else { + None }; let save_file = config.open_message_file()?; let ctrlc = Arc::new(AtomicBool::new(false)); @@ -367,7 +367,7 @@ impl ReplCmdHandler { .unwrap_or_default(), ), ("save messages", self.config.save.to_string()), - ("highlight", (!self.config.no_highlight).to_string()), + ("highlight", (self.config.highlight).to_string()), ]; let mut info = String::new(); for (name, value) in items { -- cgit v1.2.3