summaryrefslogtreecommitdiffstats
path: root/src/run.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-17 21:37:44 -0500
committerJiayi Zhao <jeff.no.zhao@gmail.com>2020-02-17 21:37:44 -0500
commitaa9b25ab36d6da75d4163f13de7cad5f5ed2ce69 (patch)
tree8c798b86e1ddcc7425d2b89fd417b5267cabf91d /src/run.rs
parente7bcdd1fc7685e1f132adc267e56cdae2925d632 (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.rs37
1 files changed, 5 insertions, 32 deletions
diff --git a/src/run.rs b/src/run.rs
index 7b53040..f09dcbe 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -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());