From ada3f92c5b96e4c66f5647c4ac2487f3903692b3 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Fri, 11 Dec 2020 18:25:09 +0900 Subject: wip: Getting the new prompt to render in a new layer. --- helix-term/src/prompt.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'helix-term/src/prompt.rs') diff --git a/helix-term/src/prompt.rs b/helix-term/src/prompt.rs index 4a39f2ec..689eac66 100644 --- a/helix-term/src/prompt.rs +++ b/helix-term/src/prompt.rs @@ -1,5 +1,9 @@ -use crate::Editor; -use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; +use crate::{ + application::Renderer, + compositor::{Component, Context, EventResult}, +}; +use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers}; +use helix_view::Editor; use std::string::String; pub struct Prompt { @@ -79,9 +83,16 @@ impl Prompt { pub fn exit_selection(&mut self) { self.completion_selection_index = None; } +} + +impl Component for Prompt { + fn handle_event(&mut self, event: Event, cx: &mut Context) -> EventResult { + let event = match event { + Event::Key(event) => event, + _ => return EventResult::Ignored, + }; - pub fn handle_event(&mut self, key_event: KeyEvent, editor: &mut Editor) { - match key_event { + match event { KeyEvent { code: KeyCode::Char(c), modifiers: KeyModifiers::NONE, @@ -112,7 +123,7 @@ impl Prompt { KeyEvent { code: KeyCode::Enter, .. - } => (self.callback_fn)(editor, &self.line), + } => (self.callback_fn)(cx.editor, &self.line), KeyEvent { code: KeyCode::Tab, .. } => self.change_completion_selection(), @@ -121,6 +132,12 @@ impl Prompt { modifiers: KeyModifiers::CONTROL, } => self.exit_selection(), _ => (), - } + }; + + EventResult::Consumed(None) + } + + fn render(&mut self, renderer: &mut Renderer, cx: &mut Context) { + renderer.render_prompt(self, &cx.editor.theme) } } -- cgit v1.2.3-70-g09d2