feat(tui): rombak rendering chat jadi format log rapat

markdown.rs juga disesuaikan: indentasi paragraf/heading bawaannya
dilepas supaya tidak bentrok dengan indent PREFIX_WIDTH di chat.rs
(baris pertama vs baris wrap lanjutan jadi sejajar).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
asepharyana
2026-07-14 23:41:53 +07:00
co-authored by Claude Sonnet 5
parent 6b58977875
commit e34708a319
2 changed files with 138 additions and 118 deletions
+9 -13
View File
@@ -7,6 +7,13 @@
//! Design: code blocks get a dark background with a labeled top bar,
//! headings are bold with distinct colors, blockquotes get a vertical
//! accent bar prefix, and inline code is highlighted with a background.
//! Deliberately adds no leading indentation of its own for paragraphs,
//! headings, or list bullets — the caller (`chat.rs`) owns column
//! alignment via its `PREFIX_WIDTH` scheme, so any indent added here
//! would only apply to a construct's first rendered line and throw
//! wrapped continuation lines out of alignment with it. Code-block lines
//! are the exception: every line gets its `" "` prefix independently
//! and consistently, so there's no first-line-only misalignment there.
use ratatui::style::{Modifier, Style};
use ratatui::text::Span;
@@ -27,7 +34,6 @@ pub fn render_markdown(text: &str, width: u16) -> Vec<Span<'static>> {
let mut in_code_block = false;
let mut in_heading = false;
let mut heading_level = 0;
let mut first_in_paragraph = true;
for event in parser {
match event {
@@ -59,13 +65,10 @@ pub fn render_markdown(text: &str, width: u16) -> Vec<Span<'static>> {
};
// No prefix, we'll handle in the text events
}
pulldown_cmark::Tag::Paragraph => {
first_in_paragraph = true;
}
pulldown_cmark::Tag::Item => {
// List item bullet
spans.push(Span::styled(
" ",
"",
Style::default().fg(Theme::PRIMARY),
));
}
@@ -106,7 +109,6 @@ pub fn render_markdown(text: &str, width: u16) -> Vec<Span<'static>> {
spans.push(Span::raw("\n"));
}
pulldown_cmark::TagEnd::Paragraph => {
first_in_paragraph = true;
spans.push(Span::raw("\n\n"));
}
pulldown_cmark::TagEnd::Item | pulldown_cmark::TagEnd::BlockQuote(_) => {
@@ -129,17 +131,11 @@ pub fn render_markdown(text: &str, width: u16) -> Vec<Span<'static>> {
3 => Theme::ACCENT_PURPLE,
_ => Theme::TEXT,
};
let prefix = " ";
spans.push(Span::styled(
format!("{prefix}{s}"),
s,
Style::default().fg(color).add_modifier(Modifier::BOLD),
));
} else {
// Handle first word detection for paragraph indentation
if first_in_paragraph {
spans.push(Span::raw(" "));
first_in_paragraph = false;
}
spans.push(Span::raw(s));
}
}