Files
p2p-chat/src/tui/input.rs
2026-02-11 20:37:44 +03:00

65 lines
1.9 KiB
Rust

//! Input bar widget with cursor.
use ratatui::layout::Rect;
use ratatui::style::Style;
use ratatui::widgets::{Block, Borders, Paragraph};
use ratatui::Frame;
use super::{App, InputMode};
pub fn render(frame: &mut Frame, area: Rect, app: &App) {
let (title, border_color, content) = match app.input_mode {
InputMode::FilePrompt => (
" 📁 File path (Enter to send, Esc to cancel) ",
app.theme.system_msg,
app.file_path_input.as_str(),
),
InputMode::Editing => (" ✏ Message (Esc for commands) ", app.theme.self_name, app.input.as_str()),
InputMode::Normal => (
" Press i/Enter to type, Q=quit, or use /help ",
app.theme.time,
app.input.as_str(),
),
InputMode::MicSelect => (
" 🎤 Selecting microphone... ",
app.theme.border,
"",
),
InputMode::SpeakerSelect => (
" 🔊 Selecting speaker... ",
app.theme.border,
"",
),
};
let block = Block::default()
.title(title)
.borders(Borders::ALL)
.border_style(Style::default().fg(border_color));
let paragraph = Paragraph::new(content.to_string())
.style(Style::default().fg(app.theme.text))
.block(block);
frame.render_widget(paragraph, area);
// Set cursor position when in editing/file mode
match app.input_mode {
InputMode::Editing => {
frame.set_cursor_position((
area.x + 1 + app.cursor_position as u16,
area.y + 1,
));
}
InputMode::FilePrompt => {
frame.set_cursor_position((
area.x + 1 + app.file_path_input.len() as u16,
area.y + 1,
));
}
InputMode::Normal => {}
InputMode::MicSelect => {}
InputMode::SpeakerSelect => {}
}
}