Skip to main content

cui/ui/
cmd.rs

1//! The bottom line: the ':' editor in Command mode, else the last
2//! message or a hint.
3
4use ratatui::Frame;
5use ratatui::layout::{Position, Rect};
6use ratatui::style::{Color, Modifier, Style};
7use ratatui::widgets::Paragraph;
8
9use crate::state::{AppState, Level, Mode};
10
11pub fn draw(f: &mut Frame, area: Rect, state: &AppState) {
12    if state.mode == Mode::Command {
13        let text = format!(":{}", state.cmdline.buffer);
14        f.render_widget(Paragraph::new(text), area);
15        let x = area
16            .x
17            .saturating_add(1 + state.cmdline.cursor as u16)
18            .min(area.right().saturating_sub(1));
19        f.set_cursor_position(Position::new(x, area.y));
20        return;
21    }
22    match &state.message {
23        Some((level, text)) => {
24            let style = match level {
25                Level::Info => Style::new(),
26                Level::Warn => Style::new().fg(Color::Yellow),
27                Level::Error => Style::new().fg(Color::Red),
28            };
29            f.render_widget(Paragraph::new(text.as_str()).style(style), area);
30        }
31        None => f.render_widget(
32            Paragraph::new(" type : for commands, ? for help")
33                .style(Style::new().add_modifier(Modifier::DIM)),
34            area,
35        ),
36    }
37}