prefer ratatui Stylized for constructing lines/spans (#3068)
no functional change, just simplifying ratatui styling and adding guidance in AGENTS.md for future.
This commit is contained in:
@@ -1262,9 +1262,9 @@ impl WidgetRef for ChatComposer {
|
||||
let key_hint_style = Style::default().fg(Color::Cyan);
|
||||
let mut hint = if self.ctrl_c_quit_hint {
|
||||
vec![
|
||||
Span::from(" "),
|
||||
" ".into(),
|
||||
"Ctrl+C again".set_style(key_hint_style),
|
||||
Span::from(" to quit"),
|
||||
" to quit".into(),
|
||||
]
|
||||
} else {
|
||||
let newline_hint_key = if self.use_shift_enter_hint {
|
||||
@@ -1273,28 +1273,28 @@ impl WidgetRef for ChatComposer {
|
||||
"Ctrl+J"
|
||||
};
|
||||
vec![
|
||||
Span::from(" "),
|
||||
" ".into(),
|
||||
"⏎".set_style(key_hint_style),
|
||||
Span::from(" send "),
|
||||
" send ".into(),
|
||||
newline_hint_key.set_style(key_hint_style),
|
||||
Span::from(" newline "),
|
||||
" newline ".into(),
|
||||
"Ctrl+T".set_style(key_hint_style),
|
||||
Span::from(" transcript "),
|
||||
" transcript ".into(),
|
||||
"Ctrl+C".set_style(key_hint_style),
|
||||
Span::from(" quit"),
|
||||
" quit".into(),
|
||||
]
|
||||
};
|
||||
|
||||
if !self.ctrl_c_quit_hint && self.esc_backtrack_hint {
|
||||
hint.push(Span::from(" "));
|
||||
hint.push(" ".into());
|
||||
hint.push("Esc".set_style(key_hint_style));
|
||||
hint.push(Span::from(" edit prev"));
|
||||
hint.push(" edit prev".into());
|
||||
}
|
||||
|
||||
// Append token/context usage info to the footer hints when available.
|
||||
if let Some(token_usage_info) = &self.token_usage_info {
|
||||
let token_usage = &token_usage_info.total_token_usage;
|
||||
hint.push(Span::from(" "));
|
||||
hint.push(" ".into());
|
||||
hint.push(
|
||||
Span::from(format!("{} tokens used", token_usage.blended_total()))
|
||||
.style(Style::default().add_modifier(Modifier::DIM)),
|
||||
@@ -1309,7 +1309,7 @@ impl WidgetRef for ChatComposer {
|
||||
} else {
|
||||
100
|
||||
};
|
||||
hint.push(Span::from(" "));
|
||||
hint.push(" ".into());
|
||||
hint.push(
|
||||
Span::from(format!("{percent_remaining}% context left"))
|
||||
.style(Style::default().add_modifier(Modifier::DIM)),
|
||||
|
||||
@@ -3,8 +3,7 @@ use crossterm::event::KeyEvent;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::style::Modifier;
|
||||
use ratatui::style::Style;
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::Line;
|
||||
use ratatui::text::Span;
|
||||
use ratatui::widgets::Paragraph;
|
||||
@@ -42,7 +41,7 @@ pub(crate) struct ListSelectionView {
|
||||
|
||||
impl ListSelectionView {
|
||||
fn dim_prefix_span() -> Span<'static> {
|
||||
Span::styled("▌ ", Style::default().add_modifier(Modifier::DIM))
|
||||
"▌ ".dim()
|
||||
}
|
||||
|
||||
fn render_dim_prefix_line(area: Rect, buf: &mut Buffer) {
|
||||
@@ -162,13 +161,8 @@ impl BottomPaneView for ListSelectionView {
|
||||
height: 1,
|
||||
};
|
||||
|
||||
let title_spans: Vec<Span<'static>> = vec![
|
||||
Self::dim_prefix_span(),
|
||||
Span::styled(
|
||||
self.title.clone(),
|
||||
Style::default().add_modifier(Modifier::BOLD),
|
||||
),
|
||||
];
|
||||
let title_spans: Vec<Span<'static>> =
|
||||
vec![Self::dim_prefix_span(), self.title.clone().bold()];
|
||||
let title_para = Paragraph::new(Line::from(title_spans));
|
||||
title_para.render(title_area, buf);
|
||||
|
||||
@@ -180,10 +174,8 @@ impl BottomPaneView for ListSelectionView {
|
||||
width: area.width,
|
||||
height: 1,
|
||||
};
|
||||
let subtitle_spans: Vec<Span<'static>> = vec![
|
||||
Self::dim_prefix_span(),
|
||||
Span::styled(sub.clone(), Style::default().add_modifier(Modifier::DIM)),
|
||||
];
|
||||
let subtitle_spans: Vec<Span<'static>> =
|
||||
vec![Self::dim_prefix_span(), sub.clone().dim()];
|
||||
let subtitle_para = Paragraph::new(Line::from(subtitle_spans));
|
||||
subtitle_para.render(subtitle_area, buf);
|
||||
// Render the extra spacer line with the dimmed prefix to align with title/subtitle
|
||||
@@ -240,10 +232,7 @@ impl BottomPaneView for ListSelectionView {
|
||||
width: area.width,
|
||||
height: 1,
|
||||
};
|
||||
let footer_para = Paragraph::new(Line::from(Span::styled(
|
||||
hint.clone(),
|
||||
Style::default().add_modifier(Modifier::DIM),
|
||||
)));
|
||||
let footer_para = Paragraph::new(hint.clone().dim());
|
||||
footer_para.render(footer_area, buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use ratatui::prelude::Constraint;
|
||||
use ratatui::style::Color;
|
||||
use ratatui::style::Modifier;
|
||||
use ratatui::style::Style;
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::Line;
|
||||
use ratatui::text::Span;
|
||||
use ratatui::widgets::Block;
|
||||
@@ -38,10 +39,9 @@ pub(crate) fn render_rows(
|
||||
) {
|
||||
let mut rows: Vec<Row> = Vec::new();
|
||||
if rows_all.is_empty() {
|
||||
rows.push(Row::new(vec![Cell::from(Line::from(Span::styled(
|
||||
"no matches",
|
||||
Style::default().add_modifier(Modifier::ITALIC | Modifier::DIM),
|
||||
)))]));
|
||||
rows.push(Row::new(vec![Cell::from(Line::from(
|
||||
"no matches".dim().italic(),
|
||||
))]));
|
||||
} else {
|
||||
let max_rows_from_area = area.height as usize;
|
||||
let visible_rows = max_results
|
||||
@@ -79,23 +79,20 @@ pub(crate) fn render_rows(
|
||||
if let Some(idxs) = match_indices.as_ref() {
|
||||
let mut idx_iter = idxs.iter().peekable();
|
||||
for (char_idx, ch) in name.chars().enumerate() {
|
||||
let mut style = Style::default();
|
||||
if idx_iter.peek().is_some_and(|next| **next == char_idx) {
|
||||
idx_iter.next();
|
||||
style = style.add_modifier(Modifier::BOLD);
|
||||
spans.push(ch.to_string().bold());
|
||||
} else {
|
||||
spans.push(ch.to_string().into());
|
||||
}
|
||||
spans.push(Span::styled(ch.to_string(), style));
|
||||
}
|
||||
} else {
|
||||
spans.push(Span::raw(name.clone()));
|
||||
spans.push(name.clone().into());
|
||||
}
|
||||
|
||||
if let Some(desc) = description.as_ref() {
|
||||
spans.push(Span::raw(" "));
|
||||
spans.push(Span::styled(
|
||||
desc.clone(),
|
||||
Style::default().add_modifier(Modifier::DIM),
|
||||
));
|
||||
spans.push(" ".into());
|
||||
spans.push(desc.clone().dim());
|
||||
}
|
||||
|
||||
let mut cell = Cell::from(Line::from(spans));
|
||||
|
||||
Reference in New Issue
Block a user