Skip to main content

codetether_agent/tui/ui/chat_view/
input_area.rs

1//! User input textbox renderer.
2//!
3//! Renders a bordered [`Paragraph`] with a context-sensitive title.
4//! Delegates cursor placement to [`place_cursor`].
5
6use ratatui::{
7    Frame,
8    layout::Rect,
9    style::{Color, Style},
10    widgets::{Block, Borders, Paragraph, Wrap},
11};
12
13use super::cursor::place_cursor;
14use crate::tui::app::state::App;
15use crate::tui::color_palette::ColorPalette;
16use crate::tui::models::InputMode;
17
18/// Draw the input textbox and place the terminal cursor.
19///
20/// # Examples
21///
22/// ```rust,no_run
23/// # use codetether_agent::tui::ui::chat_view::input_area::render_input;
24/// # fn d(f:&mut ratatui::Frame,a:&codetether_agent::tui::app::state::App){ let p=codetether_agent::tui::color_palette::ColorPalette::marketing(); render_input(f,a,ratatui::layout::Rect::new(0,0,40,3),&p,""); }
25/// ```
26pub fn render_input(f: &mut Frame, app: &App, area: Rect, palette: &ColorPalette, suffix: &str) {
27    let title = if app.state.processing {
28        format!(" Message (Processing — Enter to queue steering){suffix}")
29    } else if matches!(app.state.input_mode, InputMode::Command) {
30        format!(" Command (/ for commands, Tab to autocomplete){suffix}")
31    } else {
32        format!(" Message (Enter to send, Ctrl+V image){suffix}")
33    };
34    let border_color = if app.state.processing {
35        Color::Yellow
36    } else if matches!(app.state.input_mode, InputMode::Command) {
37        Color::Magenta
38    } else {
39        palette.border
40    };
41    let input = Paragraph::new(app.state.input.as_str())
42        .block(
43            Block::default()
44                .borders(Borders::ALL)
45                .border_style(Style::default().fg(border_color))
46                .title(title),
47        )
48        .wrap(Wrap { trim: false });
49    f.render_widget(input, area);
50    place_cursor(f, app, area);
51}