From 38ba303c3ccfd94eeeee58c574cecf36839861fb Mon Sep 17 00:00:00 2001 From: Alex Clarke Date: Wed, 29 Jul 2026 10:15:35 -0600 Subject: [PATCH] feat: Improved readability of session message exchange replays --- src/repl/replay.rs | 5 +++-- src/utils/mod.rs | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/repl/replay.rs b/src/repl/replay.rs index 57bae6a..79a02c8 100644 --- a/src/repl/replay.rs +++ b/src/repl/replay.rs @@ -2,7 +2,7 @@ use anyhow::Result; use crate::client::{Message, MessageRole}; use crate::config::{AppConfig, Session}; -use crate::utils::dimmed_text; +use crate::utils::{dimmed_text, replay_label_text}; pub fn snapshot(session: &Session) -> (Vec, Vec) { ( @@ -40,13 +40,14 @@ fn render_messages(app: &AppConfig, messages: &[Message]) -> Result<()> { match message.role { MessageRole::User => { if let Some(text) = message.content.as_text() { - println!("{}", dimmed_text("You:")); + println!("{}", replay_label_text("You:")); println!("{text}"); println!(); } } MessageRole::Assistant => { if let Some(text) = message.content.as_text() { + println!("{}", replay_label_text("Assistant:")); app.print_markdown(text)?; println!(); } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 3808b32..428e882 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -75,6 +75,7 @@ static TOOL_DIM_COLOR: OnceLock = OnceLock::new(); static TOOL_FN_COLOR: OnceLock = OnceLock::new(); static TOOL_KEY_COLOR: OnceLock = OnceLock::new(); static TOOL_WARN_COLOR: OnceLock = OnceLock::new(); +static REPLAY_LABEL_COLOR: OnceLock = OnceLock::new(); pub fn init_tool_colors(theme: &Theme) { fn resolve(theme: &Theme, scope_str: &str) -> Option { @@ -96,6 +97,16 @@ pub fn init_tool_colors(theme: &Theme) { if let Some(c) = resolve(theme, "string") { let _ = TOOL_WARN_COLOR.set(c); } + let replay_color = Scope::new("entity.name") + .ok() + .and_then(|scope| { + let style = Highlighter::new(theme).style_mod_for_stack(&[scope]); + style.foreground.or(theme.settings.foreground) + }) + .map(|fg| Color::Rgb(fg.r, fg.g, fg.b)); + if let Some(c) = replay_color { + let _ = REPLAY_LABEL_COLOR.set(c); + } } pub fn now() -> String { @@ -236,6 +247,18 @@ pub fn cyan_bold_text(input: &str) -> String { .to_string() } +pub fn replay_label_text(input: &str) -> String { + if *NO_COLOR { + return input.to_string(); + } + let color = REPLAY_LABEL_COLOR.get().copied().unwrap_or(Color::Green); + nu_ansi_term::Style::new() + .fg(color) + .bold() + .paint(input) + .to_string() +} + pub fn magenta_text(input: &str) -> String { if *NO_COLOR { return input.to_string();