2020-10-13 00:23:48 +02:00
|
|
|
use crate::commands;
|
|
|
|
use crate::View;
|
|
|
|
use crossterm::event::{KeyCode, KeyEvent};
|
2020-10-09 22:55:45 +02:00
|
|
|
use std::string::String;
|
|
|
|
|
|
|
|
pub struct Prompt {
|
|
|
|
pub buffer: String,
|
2020-10-13 00:23:48 +02:00
|
|
|
pub cursor_loc: usize,
|
2020-10-09 22:55:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Prompt {
|
|
|
|
pub fn new() -> Prompt {
|
|
|
|
let prompt = Prompt {
|
2020-10-13 00:23:48 +02:00
|
|
|
buffer: String::from(":"), // starting prompt symbol
|
|
|
|
cursor_loc: 0,
|
2020-10-09 22:55:45 +02:00
|
|
|
};
|
|
|
|
prompt
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn insert_char(&mut self, c: char) {
|
|
|
|
self.buffer.push(c);
|
|
|
|
}
|
2020-10-13 00:23:48 +02:00
|
|
|
|
|
|
|
pub fn handle_keyevent(&mut self, key_event: KeyEvent, view: &mut View) {
|
|
|
|
match key_event {
|
|
|
|
KeyEvent {
|
|
|
|
code: KeyCode::Char(c),
|
|
|
|
..
|
|
|
|
} => self.insert_char(c),
|
|
|
|
KeyEvent {
|
|
|
|
code: KeyCode::Esc, ..
|
|
|
|
} => commands::normal_mode(view, 1),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 22:55:45 +02:00
|
|
|
}
|