summaryrefslogtreecommitdiffstats
path: root/src/render
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-10-08 12:38:31 +0800
committerGitHub <noreply@github.com>2024-10-08 12:38:31 +0800
commit4bc74f7e9006fc7f182c9dc6ea309ea83c5bb4f9 (patch)
tree1ed8ef0b37879ea543fe1ba2060757e4079c90ce /src/render
parentc211d1e43a02266226fb8d04856e703a4e6a625d (diff)
downloadaichat-4bc74f7e9006fc7f182c9dc6ea309ea83c5bb4f9.tar.gz
refactor: NO_COLOR, highlight and render_error (#915)
- If NO_COLOR is enabled, AIChat will not output any ANSI color codes. - `config.highlight` will only affect rendering markdown - improve rendering error
Diffstat (limited to 'src/render')
-rw-r--r--src/render/mod.rs11
1 files changed, 3 insertions, 8 deletions
diff --git a/src/render/mod.rs b/src/render/mod.rs
index 4e55e9f..97161f8 100644
--- a/src/render/mod.rs
+++ b/src/render/mod.rs
@@ -4,7 +4,7 @@ mod stream;
pub use self::markdown::{MarkdownRender, RenderOptions};
use self::stream::{markdown_stream, raw_stream};
-use crate::utils::{error_text, AbortSignal, IS_STDOUT_TERMINAL};
+use crate::utils::{error_text, pretty_error, AbortSignal, IS_STDOUT_TERMINAL};
use crate::{client::SseEvent, config::GlobalConfig};
use anyhow::Result;
@@ -25,11 +25,6 @@ pub async fn render_stream(
ret.map_err(|err| err.context("Failed to reader stream"))
}
-pub fn render_error(err: anyhow::Error, highlight: bool) {
- let err = format!("Error: {err:?}");
- if highlight {
- eprintln!("{}", error_text(&err));
- } else {
- eprintln!("{err}");
- }
+pub fn render_error(err: anyhow::Error) {
+ eprintln!("{}", error_text(&pretty_error(&err)));
}