diff options
| author | sigoden <sigoden@gmail.com> | 2023-03-04 09:02:57 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-04 09:02:57 +0800 |
| commit | 0fa1ae215ac1434591968818f8f75ad5b35d52ec (patch) | |
| tree | 2417bc0e95fad6886dd414cf407bb9fc0dbf3108 /src/main.rs | |
| parent | 3ffebce8bbc530429086302ec4f9a95268c25d07 (diff) | |
| download | aichat-0fa1ae215ac1434591968818f8f75ad5b35d52ec.tar.gz | |
feat: support highlight reply markdown (#3)
* feat: support highlight reply markdown
* migrate markdown highlighter from termimad to mdcat
* optimize render
No need to clear screen when there is no newline in reply token
* handle ctrl-c when rendering stream
* update readme
* fix ctrlc don't abort acquire_stream when establish connection
* ensure render_stream's dtect_ctrlc is exit before next readline
This will make reedline don't throw err 'The cursor position could not be read within a normal duration'
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index ddd856e..893850a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,20 @@ mod cli; mod client; mod config; +mod render; mod repl; -use std::process::exit; use std::sync::Arc; +use std::{io::stdout, process::exit}; use cli::Cli; use client::ChatGptClient; use config::{Config, Role}; +use is_terminal::IsTerminal; use anyhow::{anyhow, Result}; use clap::Parser; +use render::MarkdownRender; use repl::{Repl, ReplCmdHandler}; fn main() { @@ -52,8 +55,15 @@ fn start_directive( ) -> Result<()> { let mut file = config.open_message_file()?; let output = client.acquire(input, role.map(|v| v.prompt))?; - println!("{}", output.trim()); - Config::save_message(file.as_mut(), input, &output); + let output = output.trim(); + if config.highlight && stdout().is_terminal() { + let markdown_render = MarkdownRender::init()?; + markdown_render.print(output)?; + } else { + println!("{output}"); + } + + Config::save_message(file.as_mut(), input, output); Ok(()) } |
