diff options
author | Blaž Hrastnik | 2020-10-16 07:58:26 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2020-10-16 07:58:26 +0000 |
commit | bc2c652fe885c7e7953224268688a6d7b6dea80e (patch) | |
tree | 4fc870f35222ab9e76d68c045cc16832924a6607 /helix-term/src | |
parent | 49b4cdb5669b1c572b2b26af4353cb16cb1260f7 (diff) |
Bugfix
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/application.rs | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 51df234a..87d03c72 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -225,7 +225,6 @@ impl Renderer { Mode::Insert => "INS", Mode::Normal => "NOR", Mode::Goto => "GOTO", - Mode::Command => "COM", // command? }; // statusline self.surface.set_style( @@ -237,13 +236,15 @@ impl Renderer { } pub fn render_prompt(&mut self, prompt: &Prompt) { - use tui::backend::Backend; // render buffer text self.surface - .set_string(1, self.size.1 - 1, String::from(":"), self.text_color); + .set_string(1, self.size.1 - 1, &prompt.prompt, self.text_color); self.surface - .set_string(2, self.size.1 - 1, &prompt.buffer, self.text_color); + .set_string(2, self.size.1 - 1, &prompt.line, self.text_color); + } + pub fn draw(&mut self) { + use tui::backend::Backend; // TODO: theres probably a better place for this self.terminal .backend_mut() @@ -259,7 +260,7 @@ impl Renderer { mode => write!(stdout, "\x1B[2 q"), }; let pos = if let Some(prompt) = prompt { - Position::new(self.size.0 as usize, 2 + prompt.cursor_loc) + Position::new(self.size.0 as usize, 2 + prompt.cursor) } else { if let Some(path) = view.state.path() { self.surface.set_string( @@ -303,15 +304,6 @@ impl Application { Ok(app) } - pub fn set_prompt(&mut self) { - let commands = |editor: &mut Editor, input: &str| match input { - "q" => editor.should_close = true, - _ => (), - }; - let prompt = Prompt::new(|input| None, commands); - self.prompt = Some(prompt); - } - fn render(&mut self) { let viewport = Rect::new(OFFSET, 0, self.terminal.size.0, self.terminal.size.1 - 2); // - 2 for statusline and prompt @@ -323,6 +315,8 @@ impl Application { self.terminal.render_prompt(prompt); } + self.terminal.draw(); + // TODO: drop unwrap self.terminal.render_cursor( self.editor.view.as_ref().unwrap(), @@ -335,7 +329,6 @@ impl Application { let mut reader = EventStream::new(); let keymap = keymap::default(); - self.set_prompt(); self.render(); loop { @@ -363,6 +356,8 @@ impl Application { .as_mut() .unwrap() .handle_input(event, &mut self.editor); + + self.render(); } else if let Some(view) = &mut self.editor.view { let keys = vec![event]; // TODO: sequences (`gg`) @@ -380,7 +375,31 @@ impl Application { } view.ensure_cursor_in_view(); } - Mode::Command => unreachable!(), + Mode::Normal => { + if let &[KeyEvent { + code: KeyCode::Char(':'), + .. + }] = keys.as_slice() + { + let prompt = Prompt::new( + ":".to_owned(), + |_input: &str| None, // completion + |editor: &mut Editor, input: &str| match input { + "q" => editor.should_close = true, + _ => (), + }, + ); + + self.prompt = Some(prompt); + + // HAXX: special casing for command mode + } else if let Some(command) = keymap[&Mode::Normal].get(&keys) { + command(view, 1); + + // TODO: simplistic ensure cursor in view for now + view.ensure_cursor_in_view(); + } + } mode => { if let Some(command) = keymap[&mode].get(&keys) { command(view, 1); |