Fix fabro logs --pretty wrapping past terminal edge on assistant messages

Markdown was rendered at full terminal width then indented, pushing lines
past the right edge. Now wraps to terminal_width minus indent first.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-03-14 16:30:03 -04:00
parent 263399e0cd
commit b3e763d78d
2 changed files with 22 additions and 1 deletions

View file

@ -48,6 +48,25 @@ impl Styles {
termimad::term_text(text).to_string()
}
/// Render Markdown wrapped to a specific width (in columns).
/// Returns plain text when color is disabled.
#[must_use]
pub fn render_markdown_width(&self, text: &str, width: usize) -> String {
if !self.use_color {
return text.to_string();
}
termimad::MadSkin::default()
.text(text, Some(width))
.to_string()
}
/// Return the terminal width in columns, or 80 if it cannot be detected.
#[must_use]
pub fn terminal_width() -> usize {
let (w, _) = termimad::terminal_size();
w as usize
}
/// Create styles based on whether stderr is a TTY.
/// Respects `NO_COLOR` environment variable.
#[must_use]

View file

@ -294,7 +294,9 @@ pub fn format_event_pretty(line: &str, styles: &fabro_util::terminal::Styles) ->
styles.dim.apply_to(model),
);
let indent = " ";
let rendered = styles.render_markdown(text);
let term_width = fabro_util::terminal::Styles::terminal_width();
let wrap_width = term_width.saturating_sub(indent.len());
let rendered = styles.render_markdown_width(text, wrap_width);
let body: String = rendered
.lines()
.map(|l| format!("{indent}{l}"))