From e2f81df3dc4c36719264fff5a6516fe3aca0fa99 Mon Sep 17 00:00:00 2001 From: Armin Friedl Date: Mon, 8 Nov 2021 22:23:55 +0100 Subject: [PATCH] Carry over input to actions --- src/main.rs | 27 +++++++++++++++++++++------ src/ui/ui.rs | 3 ++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 15e72cf..4598e1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,5 @@ use log::{debug, trace}; -use std::cell::RefCell; use std::error::Error; -use std::rc::Rc; use winit::window::{Window, WindowBuilder}; use winit::event_loop::{ControlFlow, EventLoop}; @@ -140,7 +138,7 @@ impl RoftlLoop { { let actions = self.roftl.actions(self.selection); debug!{"Actions for current selection: {:?}", actions} - ui::draw_actions(&self.window, actions); + ui::draw_actions(&self.window, actions, &self.input_buffer); } _ => () @@ -255,9 +253,26 @@ impl RoftlLoop { self.roftl.do_action(self.selection, roftl::Action::Quaternary); ControlFlow::Exit }, - _ => { - trace!{"Retrieved unknown action selection. Processing character {}", character} - self.process_character(character) + + 'q' | 'Q' => ControlFlow::Exit, + + // Escape + c if c == char::from(0x1b) => ControlFlow::Exit, + + // tab + c if c == char::from(0x09) => { + debug!{"Received actions"} + match self.mode { + Mode::Selection => { self.mode = Mode::Actions; self.input_changed = true }, + Mode::Actions => { self.mode = Mode::Selection; self.input_changed = true } + } + self.window.request_redraw(); + ControlFlow::Wait + }, + + _ => { + debug!{"Retrieved unknown action selection. Processing character {}", character} + ControlFlow::Wait }, } } diff --git a/src/ui/ui.rs b/src/ui/ui.rs index 20660b7..0427188 100644 --- a/src/ui/ui.rs +++ b/src/ui/ui.rs @@ -114,7 +114,7 @@ pub fn redraw_quick(window: &Window, result: Vec<(&Entry, Vec)>, selectio }); } -pub fn draw_actions(window: &Window, actions: Vec) +pub fn draw_actions(window: &Window, actions: Vec, input: &str) { let context = make_context(&window); @@ -123,6 +123,7 @@ pub fn draw_actions(window: &Window, actions: Vec) let painter = painter::Painter::new(&context); painter.background(); + painter.input_box(0, 0, input); painter.divider(0, 1); actions.iter().enumerate()