diff --git a/lib/crates/fabro-util/src/terminal.rs b/lib/crates/fabro-util/src/terminal.rs index 449690a09..a62762156 100644 --- a/lib/crates/fabro-util/src/terminal.rs +++ b/lib/crates/fabro-util/src/terminal.rs @@ -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] diff --git a/lib/crates/fabro-workflows/src/cli/logs.rs b/lib/crates/fabro-workflows/src/cli/logs.rs index 1f25e28d1..5ffeb8ef2 100644 --- a/lib/crates/fabro-workflows/src/cli/logs.rs +++ b/lib/crates/fabro-workflows/src/cli/logs.rs @@ -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}"))