cli_tutor/ui/
input_bar.rs1use crate::app::App;
2use ratatui::{
3 layout::Rect,
4 style::{Color, Modifier, Style},
5 text::{Line, Span},
6 widgets::{Block, Borders, Paragraph},
7 Frame,
8};
9
10pub fn render(app: &App, frame: &mut Frame, area: Rect) {
11 let before_cursor = &app.input[..app.cursor_pos];
12 let at_cursor = app.input[app.cursor_pos..].chars().next();
13 let after_cursor = if let Some(c) = at_cursor {
14 &app.input[app.cursor_pos + c.len_utf8()..]
15 } else {
16 ""
17 };
18
19 let cursor_char = at_cursor.map(|c| c.to_string()).unwrap_or(" ".to_string());
20
21 let line = Line::from(vec![
22 Span::styled(
23 "$ ",
24 Style::default()
25 .fg(Color::Green)
26 .add_modifier(Modifier::BOLD),
27 ),
28 Span::raw(before_cursor.to_string()),
29 Span::styled(
31 cursor_char,
32 Style::default().bg(Color::White).fg(Color::Black),
33 ),
34 Span::raw(after_cursor.to_string()),
35 ]);
36
37 let block = Block::default().borders(Borders::ALL).title("Command");
38
39 frame.render_widget(Paragraph::new(line).block(block), area);
40}