Files
loki/src/render/mod.rs
Alex Clarke f41c85b703
CI / All (macos-latest) (push) Has been cancelled
CI / All (ubuntu-latest) (push) Has been cancelled
CI / All (windows-latest) (push) Has been cancelled
style: Applied formatting across new inquire files
2026-03-16 12:39:20 -06:00

34 lines
997 B
Rust

mod inquire;
mod markdown;
mod stream;
pub use inquire::prompt_theme;
pub use self::markdown::{MarkdownRender, RenderOptions};
use self::stream::{markdown_stream, raw_stream};
use crate::utils::{AbortSignal, IS_STDOUT_TERMINAL, error_text, pretty_error};
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)));
}