diff options
| author | sigoden <sigoden@gmail.com> | 2023-03-05 19:48:22 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-05 19:48:22 +0800 |
| commit | 957ea431c23dd6cbaa512e6a67b4a25e2adf08e4 (patch) | |
| tree | 334182bf2e730f8d422e855e120df9de94bed534 | |
| parent | aadffb17a3cbbfc5e3c0dad4c8587eff79aaae9b (diff) | |
| download | aichat-957ea431c23dd6cbaa512e6a67b4a25e2adf08e4.tar.gz | |
refactor: rename config.no_highlight to highlight (#19)
| -rw-r--r-- | src/config.rs | 8 | ||||
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | 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<String>, /// 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<Config>, role: Option<Role>) -> Result<Self> { - 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 { |
