repo_description: All-in-one LLM CLI tool featuring Shell Assistant, Chat-REPL, RAG, AI Tools & Agents, with access to OpenAI, Claude, Gemini, Ollama, Groq, and more.
repo_topics: ai ai-agents chatbot claude cli function-calling gemini llm ollama openai rag rust shell webui
code: mod markdown;
  mod stream;
  
  pub use self::markdown::{MarkdownRender, RenderOptions};
  use self::stream::{markdown_stream, raw_stream};
  
  use crate::utils::{error_text, pretty_error, AbortSignal, IS_STDOUT_TERMINAL};
  use crate::{client::SseEvent, config::GlobalConfig};
  
  use anyhow::Result;
  use tokio::sync::mpsc::UnboundedReceiver;
  
  pub async fn render_stream(
      rx: UnboundedReceiver<SseEvent>,
      config: &GlobalConfig,
      abort_signal: AbortSignal,
  ) -> Result<()> {
      let ret = if *IS_STDOUT_TERMINAL && config.read().highlight {
          let render_options = config.read().render_options()?;
          let mut render = MarkdownRender::init(render_options)?;
          markdown_stream(rx, &mut render, &abort_signal).await
      } else {
          raw_stream(rx, &abort_signal).await
      };
      ret.map_err(|err| err.context("Failed to reader stream"))
  }
  
  pub fn render_error(err: anyhow::Error) {
      eprintln!("{}", error_text(&pretty_error(&err)));
  }
  