diff options
| author | sigoden <sigoden@gmail.com> | 2023-03-04 09:22:55 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-04 09:22:55 +0800 |
| commit | dbdb2ed125214d7dab9dd2ef6ed03e1062b7cc27 (patch) | |
| tree | 678fe6be7439c31e5cc804cf20d9cf30ccbff3d1 | |
| parent | 0fa1ae215ac1434591968818f8f75ad5b35d52ec (diff) | |
| download | aichat-dbdb2ed125214d7dab9dd2ef6ed03e1062b7cc27.tar.gz | |
refactor: replace config.highlight with config.no_highlight (#4)
* refactor: replace config.highlight with config.no_highlight
* update readme
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | src/config.rs | 12 | ||||
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | src/repl.rs | 6 |
4 files changed, 7 insertions, 15 deletions
@@ -48,7 +48,7 @@ After setting, it will automatically create the configuration file. Of course, y api_key: "<YOUR SECRET API KEY>" # Request via https://platform.openai.com/account/api-keys temperature: 1.0 # optional, see https://platform.openai.com/docs/api-reference/chat/create#chat/create-temperature save: true # optional, If set to true, aichat will save chat messages to message.md -highlight: true # optional, Whether to highlight reply message. +no_highlight: false # optional, Whether to disable highlight proxy: "socks5://127.0.0.1:1080" # optional, set proxy server. e.g. http://127.0.0.1:8080 or socks5://127.0.0.1:1080 ``` diff --git a/src/config.rs b/src/config.rs index cce6b6a..1c6abc5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,9 +24,9 @@ pub struct Config { /// Whether to persistently save chat messages #[serde(default)] pub save: bool, - /// Whether to highlight reply message + /// Whether to disable highlight #[serde(default)] - pub highlight: bool, + pub no_highlight: bool, /// Set proxy pub proxy: Option<String>, /// Used only for debugging @@ -175,14 +175,6 @@ fn create_config_file(config_path: &Path) -> Result<()> { raw_config.push_str("save: true\n"); } - let ans = Confirm::new("Whether to highlight reply message?") - .with_default(true) - .prompt() - .map_err(confirm_map_err)?; - if ans { - raw_config.push_str("highlight: true\n"); - } - std::fs::write(config_path, raw_config) .map_err(|err| anyhow!("Failed to write to config file, {err}"))?; Ok(()) diff --git a/src/main.rs b/src/main.rs index 893850a..2d72c3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,7 @@ fn start_directive( let mut file = config.open_message_file()?; let output = client.acquire(input, role.map(|v| v.prompt))?; let output = output.trim(); - if config.highlight && stdout().is_terminal() { + if !config.no_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 f8a10a3..bb33bc1 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -196,10 +196,10 @@ struct ReplCmdHandlerState { impl ReplCmdHandler { pub fn init(client: ChatGptClient, config: Arc<Config>, role: Option<Role>) -> Result<Self> { - let render = if config.highlight { - Some(Arc::new(MarkdownRender::init()?)) - } else { + let render = if config.no_highlight { None + } else { + Some(Arc::new(MarkdownRender::init()?)) }; let prompt = role.map(|v| v.prompt).unwrap_or_default(); let save_file = config.open_message_file()?; |
