helix-mods/helix-view/src/prompt.rs

37 lines
834 B
Rust
Raw Normal View History

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,
pub cursor_loc: usize,
2020-10-09 22:55:45 +02:00
}
impl Prompt {
pub fn new() -> Prompt {
let prompt = Prompt {
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);
}
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
}