diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-02-17 21:37:44 -0500 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2020-02-17 21:37:44 -0500 |
commit | aa9b25ab36d6da75d4163f13de7cad5f5ed2ce69 (patch) | |
tree | 8c798b86e1ddcc7425d2b89fd417b5267cabf91d /src/run.rs | |
parent | e7bcdd1fc7685e1f132adc267e56cdae2925d632 (diff) |
rework menu widget
- menu loop is now contained in widget rather than in run.rs
- add tui_footer for showing file info
- move TuiDirListDetailed into its own file
- add format util file for formatting file info
- add support for showing file size, symlink paths and modified times
Diffstat (limited to 'src/run.rs')
-rw-r--r-- | src/run.rs | 37 |
1 files changed, 5 insertions, 32 deletions
@@ -8,7 +8,7 @@ use crate::context::JoshutoContext; use crate::tab::JoshutoTab; use crate::ui; use crate::util::event::{Event, Events}; -use crate::util::menu::OptionMenu; +use crate::ui::widgets::TuiCommandMenu; pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) { let mut backend: ui::TuiBackend = ui::TuiBackend::new().unwrap(); @@ -83,40 +83,13 @@ pub fn run(config_t: JoshutoConfig, keymap_t: JoshutoCommandMapping) { } } Some(CommandKeybind::CompositeKeybind(m)) => { - let mut cmd = None; let mut map: &JoshutoCommandMapping = &m; - loop { - let event2 = { - let mut menu = OptionMenu::new(&mut backend, &context.events); + let cmd = { + let mut menu = TuiCommandMenu::new(); + menu.get_input(&mut backend, &context, map) + }; - // TODO: format keys better, rather than debug - let mut display_vec: Vec<String> = map - .iter() - .map(|(k, v)| format!(" {:?}\t{}", k, v)) - .collect(); - display_vec.sort(); - let display_str: Vec<&str> = - display_vec.iter().map(|v| v.as_str()).collect(); - let result = menu.get_option(&display_str); - result - }; - - match event2 { - None => break, - Some(key) => match key { - Key::Char(_) => match map.get(&key) { - Some(CommandKeybind::CompositeKeybind(m)) => map = &m, - Some(CommandKeybind::SimpleKeybind(s)) => { - cmd = Some(s.as_ref()); - break; - } - None => break, - }, - _ => {} - }, - } - } if let Some(command) = cmd { if let Err(e) = command.execute(&mut context, &mut backend) { eprintln!("{}", e.cause()); |