feat: update maximum steps and token limits to usize::MAX; add split_spans_into_lines function for improved chat display

This commit is contained in:
asepharyana
2026-07-12 04:01:10 +07:00
parent a974118b5a
commit 0cc60c12ce
6 changed files with 38 additions and 12 deletions
+29 -2
View File
@@ -5,6 +5,31 @@ use ratatui::widgets::{Block, Borders, Paragraph, Wrap};
use ratatui::Frame;
use super::theme::Theme;
fn split_spans_into_lines<'a>(spans: Vec<Span<'a>>) -> Vec<Line<'a>> {
let mut lines = Vec::new();
let mut current_spans = Vec::new();
for span in spans {
let text = span.content.as_ref();
let mut parts = text.split('\n').peekable();
while let Some(part) = parts.next() {
if !part.is_empty() {
current_spans.push(Span::styled(part.to_string(), span.style));
}
if parts.peek().is_some() {
lines.push(Line::from(std::mem::take(&mut current_spans)));
}
}
}
if !current_spans.is_empty() {
lines.push(Line::from(current_spans));
}
if lines.is_empty() {
lines.push(Line::from(vec![]));
}
lines
}
fn _role_name(role: &crate::dto::chat::message::Role) -> &'static str {
match role {
crate::dto::chat::message::Role::User => "User",
@@ -81,10 +106,12 @@ pub fn draw_chat(frame: &mut Frame, area: Rect, state: &crate::app::state::rest:
};
let mut content_spans = vec![Span::styled(format!("{} ", prefix), Style::default().fg(role_color))];
content_spans.extend(super::markdown::render_markdown(&content_str, area.width));
let content_line = Line::from(content_spans);
let message_lines = split_spans_into_lines(content_spans);
display_lines.push(header);
display_lines.push(content_line);
for line in message_lines {
display_lines.push(line);
}
display_lines.push(Line::from(Span::raw("")));
}