Carry over input to actions

This commit is contained in:
Armin Friedl 2021-11-08 22:23:55 +01:00
parent a207a38101
commit e2f81df3dc
2 changed files with 23 additions and 7 deletions

View file

@ -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
},
'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
},
_ => {
trace!{"Retrieved unknown action selection. Processing character {}", character}
self.process_character(character)
debug!{"Retrieved unknown action selection. Processing character {}", character}
ControlFlow::Wait
},
}
}

View file

@ -114,7 +114,7 @@ pub fn redraw_quick(window: &Window, result: Vec<(&Entry, Vec<usize>)>, selectio
});
}
pub fn draw_actions(window: &Window, actions: Vec<String>)
pub fn draw_actions(window: &Window, actions: Vec<String>, input: &str)
{
let context = make_context(&window);
@ -123,6 +123,7 @@ pub fn draw_actions(window: &Window, actions: Vec<String>)
let painter = painter::Painter::new(&context);
painter.background();
painter.input_box(0, 0, input);
painter.divider(0, 1);
actions.iter().enumerate()