From 048ce76605f25578e23d1f66ea032e9a7593a7d0 Mon Sep 17 00:00:00 2001 From: alexpasmantier Date: Mon, 30 Sep 2024 14:32:26 +0200 Subject: [PATCH] toml configuration and fix keys --- .config/config.json5 | 12 ++++++------ .config/config.toml | 29 +++++++++++++++++------------ TODO.md | 2 +- src/app.rs | 7 ++++--- src/config.rs | 6 ++++-- src/event.rs | 39 ++++++++++++++++++++++++++++++--------- src/render.rs | 1 + 7 files changed, 63 insertions(+), 33 deletions(-) diff --git a/.config/config.json5 b/.config/config.json5 index 68ac13b..3e85dc4 100644 --- a/.config/config.json5 +++ b/.config/config.json5 @@ -3,22 +3,22 @@ "Input": { "": "Quit", // Quit the application "": "Quit", // Quit the application - "": "Quit", // Another way to quit "": "Quit", // Yet another way to quit "": "Suspend", // Suspend the application "": "GoToNextPane", // Move to the next pane "": "GoToPrevPane", // Move to the previous pane - "": "GoToPaneUp", // Move to the pane above - "": "GoToPaneDown", // Move to the pane below + // "": "GoToPaneUp", // Move to the pane above + // "": "GoToPaneDown", // Move to the pane below "": "GoToPaneLeft", // Move to the pane to the left "": "GoToPaneRight", // Move to the pane to the right + "": "SelectNextEntry", // Move to the next entry + "": "SelectPrevEntry", // Move to the previous entry "": "SelectNextEntry", // Move to the next entry "": "SelectPrevEntry", // Move to the previous entry - "ctrl-down": "ScrollPreviewDown", // Scroll the preview down - "ctrl-up": "ScrollPreviewUp", // Scroll the preview up + "": "ScrollPreviewDown", // Scroll the preview down + "": "ScrollPreviewUp", // Scroll the preview up "": "ScrollPreviewHalfPageDown", // Scroll the preview half a page down "": "ScrollPreviewHalfPageUp", // Scroll the preview half a page up - }, } } diff --git a/.config/config.toml b/.config/config.toml index 743fe79..454dcbf 100644 --- a/.config/config.toml +++ b/.config/config.toml @@ -1,12 +1,17 @@ -FIXME: this doesn't work -[keybindings] -Input = { - "": "Quit", // Quit the application - "": "Quit", // Another way to quit - "": "Quit", // Yet another way to quit - "": "Suspend", // Suspend the application - }, - -Help = { - "" = "Quit" # Quit the help panel - } +[keybindings.Input] +q = "Quit" +esc = "Quit" +ctrl-c = "Quit" +ctrl-z = "Suspend" +tab = "GoToNextPane" +backtab = "GoToPrevPane" +ctrl-left = "GoToPaneLeft" +ctrl-right = "GoToPaneRight" +down = "SelectNextEntry" +up = "SelectPrevEntry" +ctrl-n = "SelectNextEntry" +ctrl-p = "SelectPrevEntry" +ctrl-down = "ScrollPreviewDown" +ctrl-up = "ScrollPreviewUp" +ctrl-d = "ScrollPreviewHalfPageDown" +ctrl-u = "ScrollPreviewHalfPageUp" diff --git a/TODO.md b/TODO.md index e80985c..6db72db 100644 --- a/TODO.md +++ b/TODO.md @@ -9,7 +9,7 @@ ## improvements - [x] async finder initialization - [x] async finder search -- [ ] use nucleo for env +- [x] use nucleo for env - [ ] better keymaps ## feature ideas diff --git a/src/app.rs b/src/app.rs index 2e5ee11..4f39775 100644 --- a/src/app.rs +++ b/src/app.rs @@ -72,7 +72,6 @@ pub struct App { frame_rate: f64, //components: Arc>>>, television: Arc>, - active_component: usize, should_quit: bool, should_suspend: bool, mode: Mode, @@ -103,7 +102,6 @@ impl App { tick_rate, frame_rate, television, - active_component: 0, should_quit: false, should_suspend: false, config: Config::new()?, @@ -151,6 +149,7 @@ impl App { self.handle_actions().await?; if self.should_quit { + // send a termination signal to the event loop self.event_abort_tx.send(())?; break; } @@ -163,7 +162,8 @@ impl App { Event::Input(keycode) => { info!("{:?}", keycode); // if the current component is the television - // and the mode is input, we want to handle + // and the mode is input, automatically handle + // (these mappings aren't exposed to the user) if self.television.lock().await.is_input_focused() { match keycode { Key::Backspace => return Action::DeletePrevChar, @@ -187,6 +187,7 @@ impl App { Action::NoOp }); } + // terminal events Event::Tick => Action::Tick, Event::Resize(x, y) => Action::Resize(x, y), Event::FocusGained => Action::Resume, diff --git a/src/config.rs b/src/config.rs index c245431..d96286e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,7 +15,8 @@ use crate::{ event::{convert_raw_event_to_key, Key}, }; -const CONFIG: &str = include_str!("../.config/config.json5"); +//const CONFIG: &str = include_str!("../.config/config.json5"); +const CONFIG: &str = include_str!("../.config/config.toml"); #[derive(Clone, Debug, Deserialize, Default)] pub struct AppConfig { @@ -49,7 +50,8 @@ lazy_static! { impl Config { pub fn new() -> Result { - let default_config: Config = json5::from_str(CONFIG).unwrap(); + //let default_config: Config = json5::from_str(CONFIG).unwrap(); + let default_config: Config = toml::from_str(CONFIG).unwrap(); let data_dir = get_data_dir(); let config_dir = get_config_dir(); let mut builder = config::Config::builder() diff --git a/src/event.rs b/src/event.rs index e550759..0cd62aa 100644 --- a/src/event.rs +++ b/src/event.rs @@ -22,15 +22,21 @@ pub enum Event { #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, PartialOrd, Eq, Hash)] pub enum Key { - CtrlBackspace, - CtrlDelete, - AltBackspace, - AltDelete, Backspace, + Enter, Left, Right, Up, Down, + CtrlBackspace, + CtrlEnter, + CtrlLeft, + CtrlRight, + CtrlUp, + CtrlDown, + CtrlDelete, + AltBackspace, + AltDelete, Home, End, PageUp, @@ -127,11 +133,26 @@ pub fn convert_raw_event_to_key(event: KeyEvent) -> Key { KeyModifiers::ALT => Key::AltDelete, _ => Key::Delete, }, - Enter => Key::Char('\n'), - Left => Key::Left, - Right => Key::Right, - Up => Key::Up, - Down => Key::Down, + Enter => match event.modifiers { + KeyModifiers::CONTROL => Key::CtrlEnter, + _ => Key::Enter, + }, + Up => match event.modifiers { + KeyModifiers::CONTROL => Key::CtrlUp, + _ => Key::Up, + }, + Down => match event.modifiers { + KeyModifiers::CONTROL => Key::CtrlDown, + _ => Key::Down, + }, + Left => match event.modifiers { + KeyModifiers::CONTROL => Key::CtrlLeft, + _ => Key::Left, + }, + Right => match event.modifiers { + KeyModifiers::CONTROL => Key::CtrlRight, + _ => Key::Right, + }, Home => Key::Home, End => Key::End, PageUp => Key::PageUp, diff --git a/src/render.rs b/src/render.rs index fa5fada..d1ee350 100644 --- a/src/render.rs +++ b/src/render.rs @@ -78,6 +78,7 @@ pub async fn render( tui.enter()?; } RenderingTask::Quit => { + tui.exit()?; break Ok(()); } }