Skip to main content

codetether_agent/tui/ui/chat_view/
suggestions.rs

1//! Slash-command autocomplete suggestions list.
2
3use ratatui::{
4    Frame,
5    layout::Rect,
6    style::{Color, Style},
7    text::{Line, Span},
8    widgets::{Block, Borders, List, ListItem, ListState},
9};
10
11use crate::tui::app::state::App;
12
13/// Render the autocomplete suggestions panel in `area`.
14///
15/// # Examples
16///
17/// ```rust,no_run
18/// # use codetether_agent::tui::ui::chat_view::suggestions::render_suggestions;
19/// # fn d(f:&mut ratatui::Frame,a:&codetether_agent::tui::app::state::App){ render_suggestions(f,a,ratatui::layout::Rect::new(0,20,80,5)); }
20/// ```
21pub fn render_suggestions(f: &mut Frame, app: &App, area: Rect) {
22    let items: Vec<ListItem<'static>> = app
23        .state
24        .slash_suggestions
25        .iter()
26        .enumerate()
27        .map(|(idx, cmd)| {
28            let prefix = if idx == app.state.selected_slash_suggestion {
29                "▶ "
30            } else {
31                "  "
32            };
33            ListItem::new(Line::from(vec![
34                Span::raw(prefix),
35                Span::styled(cmd.clone(), Style::default().fg(Color::Cyan).bold()),
36            ]))
37        })
38        .collect();
39    let mut list_state = ListState::default();
40    if !app.state.slash_suggestions.is_empty() {
41        list_state.select(Some(app.state.selected_slash_suggestion));
42    }
43    let list = List::new(items)
44        .block(Block::default().borders(Borders::ALL).title(" Commands "))
45        .highlight_style(Style::default().bg(Color::DarkGray).fg(Color::Cyan).bold());
46    f.render_stateful_widget(list, area, &mut list_state);
47}