44 lines
1.2 KiB
Rust
44 lines
1.2 KiB
Rust
|
use tui::widgets::{Block, Borders, Paragraph};
|
||
|
|
||
|
use crate::pane::prelude::*;
|
||
|
|
||
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||
|
pub struct Command {
|
||
|
buf: String
|
||
|
}
|
||
|
impl Command {
|
||
|
pub const fn new() -> Self {
|
||
|
Self { buf: String::new() }
|
||
|
}
|
||
|
|
||
|
pub fn buf(&self) -> &str { &self.buf }
|
||
|
}
|
||
|
impl Pane for Command {
|
||
|
fn cursor_position(&self) -> Option<(u16, u16)> {
|
||
|
let x = u16::try_from(self.buf.len())
|
||
|
.expect("too big to display");
|
||
|
let y = 0;
|
||
|
Some((x, y))
|
||
|
}
|
||
|
|
||
|
fn lines_hint(&self) -> usize {
|
||
|
1
|
||
|
}
|
||
|
|
||
|
fn display(&self, output: OutputSink, area: Rect) {
|
||
|
let widget = Paragraph::new(self.buf.as_str())
|
||
|
.block(Block::default().title("Command").borders(Borders::all()));
|
||
|
|
||
|
output.render_widget(widget, area);
|
||
|
}
|
||
|
|
||
|
fn update(&mut self, key: KeyCode) -> Message {
|
||
|
match key {
|
||
|
KeyCode::Char(c) => { self.buf.push(c); Message::Nothing },
|
||
|
KeyCode::Backspace => { self.buf.pop(); Message::Nothing },
|
||
|
KeyCode::Esc => Message::CancelCommand,
|
||
|
KeyCode::Enter => Message::ExecuteCommand,
|
||
|
_ => Message::Nothing,
|
||
|
}
|
||
|
}
|
||
|
}
|