From ed03ec92a825b8e42005f2f8506b0f3db4923fa5 Mon Sep 17 00:00:00 2001 From: Jan Hrastnik Date: Tue, 13 Oct 2020 00:23:48 +0200 Subject: moved prompt command matching to prompt.rs --- helix-view/src/prompt.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'helix-view/src/prompt.rs') diff --git a/helix-view/src/prompt.rs b/helix-view/src/prompt.rs index 4aaf770b..f1920daa 100644 --- a/helix-view/src/prompt.rs +++ b/helix-view/src/prompt.rs @@ -1,13 +1,18 @@ +use crate::commands; +use crate::View; +use crossterm::event::{KeyCode, KeyEvent}; use std::string::String; pub struct Prompt { pub buffer: String, + pub cursor_loc: usize, } impl Prompt { pub fn new() -> Prompt { let prompt = Prompt { - buffer: String::from(""), + buffer: String::from(":"), // starting prompt symbol + cursor_loc: 0, }; prompt } @@ -15,4 +20,17 @@ impl Prompt { pub fn insert_char(&mut self, c: char) { self.buffer.push(c); } + + 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), + _ => (), + } + } } -- cgit v1.2.3-70-g09d2