summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml2
-rw-r--r--config/keymap.toml46
-rw-r--r--docs/configuration/keymap.toml.md16
-rw-r--r--src/commands/mod.rs4
-rw-r--r--src/commands/numbered_command.rs2
-rw-r--r--src/commands/show_help.rs (renamed from src/commands/help.rs)6
-rw-r--r--src/commands/show_tasks.rs55
-rw-r--r--src/commands/show_workers.rs34
-rw-r--r--src/config/keymap/keymapping.rs98
-rw-r--r--src/config/keymap/mod.rs2
-rw-r--r--src/config/mod.rs2
-rw-r--r--src/event/process_event.rs8
-rw-r--r--src/key_command/command.rs2
-rw-r--r--src/key_command/command_keybind.rs7
-rw-r--r--src/key_command/constants.rs2
-rw-r--r--src/key_command/impl_appcommand.rs2
-rw-r--r--src/key_command/impl_appexecute.rs4
-rw-r--r--src/key_command/impl_comment.rs2
-rw-r--r--src/key_command/impl_from_str.rs2
-rw-r--r--src/run.rs2
-rw-r--r--src/ui/views/tui_command_menu.rs7
-rw-r--r--src/ui/widgets/tui_help.rs10
22 files changed, 199 insertions, 116 deletions
diff --git a/Cargo.toml b/Cargo.toml
index e9b2b0b..98f4ffb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,7 +5,7 @@ authors = ["Jiayi Zhao <jeff.no.zhao@gmail.com>"]
description = "Terminal file manager inspired by ranger"
homepage = "https://github.com/kamiyaa/joshuto"
license = "LGPL-3.0"
-edition = "2018"
+edition = "2021"
[dependencies]
ansi-to-tui = { version = "^0", optional = true }
diff --git a/config/keymap.toml b/config/keymap.toml
index 21d3a4b..b5980ea 100644
--- a/config/keymap.toml
+++ b/config/keymap.toml
@@ -1,4 +1,6 @@
-mapcommand = [
+[default_view]
+
+keymap = [
{ keys = [ "T" ], command = "new_tab" },
{ keys = [ "ctrl+t" ], command = "new_tab" },
{ keys = [ "W" ], command = "close_tab" },
@@ -23,8 +25,8 @@ mapcommand = [
{ keys = [ "arrow_left" ], command = "cd .." },
{ keys = [ "arrow_right" ], command = "open" },
{ keys = [ "\n" ], command = "open" },
- { keys = [ "end" ], command = "cursor_move_end" },
{ keys = [ "home" ], command = "cursor_move_home" },
+ { keys = [ "end" ], command = "cursor_move_end" },
{ keys = [ "page_up" ], command = "cursor_move_page_up" },
{ keys = [ "page_down" ], command = "cursor_move_page_down" },
{ keys = [ "ctrl+u" ], command = "cursor_move_page_up 0.5" },
@@ -68,7 +70,7 @@ mapcommand = [
{ keys = [ " " ], command = "select --toggle=true" },
{ keys = [ "t" ], command = "select --all=true --toggle=true" },
- { keys = [ "w" ], command = "show_workers --exit-key=w" },
+ { keys = [ "w" ], command = "show_tasks --exit-key=w" },
{ keys = [ "b", "b" ], command = "bulk_rename" },
{ keys = [ "=" ], command = "set_mode" },
@@ -102,3 +104,41 @@ mapcommand = [
{ keys = [ "g", "h" ], command = "cd ~/" },
{ keys = [ "?" ], command = "help" }
]
+
+[task_view]
+
+keymap = [
+ # arrow keys
+ { keys = [ "arrow_up" ], command = "cursor_move_up" },
+ { keys = [ "arrow_down" ], command = "cursor_move_down" },
+ { keys = [ "home" ], command = "cursor_move_home" },
+ { keys = [ "end" ], command = "cursor_move_end" },
+
+ # vim-like keybindings
+ { keys = [ "j" ], command = "cursor_move_down" },
+ { keys = [ "k" ], command = "cursor_move_up" },
+ { keys = [ "g", "g" ], command = "cursor_move_home" },
+ { keys = [ "G" ], command = "cursor_move_end" },
+
+ { keys = [ "w" ], command = "show_tasks" },
+ { keys = [ "escape" ], command = "show_tasks" },
+]
+
+[help_view]
+
+keymap = [
+ # arrow keys
+ { keys = [ "arrow_up" ], command = "cursor_move_up" },
+ { keys = [ "arrow_down" ], command = "cursor_move_down" },
+ { keys = [ "home" ], command = "cursor_move_home" },
+ { keys = [ "end" ], command = "cursor_move_end" },
+
+ # vim-like keybindings
+ { keys = [ "j" ], command = "cursor_move_down" },
+ { keys = [ "k" ], command = "cursor_move_up" },
+ { keys = [ "g", "g" ], command = "cursor_move_home" },
+ { keys = [ "G" ], command = "cursor_move_end" },
+
+ { keys = [ "w" ], command = "show_tasks" },
+ { keys = [ "escape" ], command = "show_tasks" },
+]
diff --git a/docs/configuration/keymap.toml.md b/docs/configuration/keymap.toml.md
index 9aeef6a..8cc9def 100644
--- a/docs/configuration/keymap.toml.md
+++ b/docs/configuration/keymap.toml.md
@@ -2,10 +2,24 @@
This file is for mapping keyboard keys to commands.
```toml
-mapcommand = [
+# keymapping for default view
+[default_view]
+keymap = [
{ keys = [ "T" ], command = "new_tab" },
# ...
]
+
+# keymapping for task view
+[task_view]
+keymap = [
+ # ...
+]
+
+# keymapping for help view
+[help_view]
+keymap = [
+ # ...
+]
```
For more examples, take a look at [config/keymap.toml](https://github.com/kamiyaa/joshuto/blob/main/config/keymap.toml)
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index f585bbc..1f447c2 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -4,7 +4,6 @@ pub mod command_line;
pub mod cursor_move;
pub mod delete_files;
pub mod file_ops;
-pub mod help;
pub mod line_nums;
pub mod new_directory;
pub mod numbered_command;
@@ -20,8 +19,9 @@ pub mod search_glob;
pub mod search_string;
pub mod selection;
pub mod set_mode;
+pub mod show_help;
pub mod show_hidden;
-pub mod show_workers;
+pub mod show_tasks;
pub mod sort;
pub mod sub_process;
pub mod subdir_fzf;
diff --git a/src/commands/numbered_command.rs b/src/commands/numbered_command.rs
index 06e97ac..c35205b 100644
--- a/src/commands/numbered_command.rs
+++ b/src/commands/numbered_command.rs
@@ -51,7 +51,7 @@ pub fn numbered_command(
Event::Key(Key::Char(c)) if c.is_numeric() => {
prefix.push(c);
}
- key => match keymap.as_ref().get(&key) {
+ key => match keymap.default_view.get(&key) {
Some(CommandKeybind::SimpleKeybind(command)) => {
return command.numbered_execute(num_prefix, context, backend, keymap);
}
diff --git a/src/commands/help.rs b/src/commands/show_help.rs
index bd8507d..739c63b 100644
--- a/src/commands/help.rs
+++ b/src/commands/show_help.rs
@@ -25,9 +25,9 @@ pub fn help_loop(
loop {
let keymap = if search_query.is_empty() {
- widgets::get_keymap_table(keymap_t, &search_query, sort_by)
+ widgets::get_keymap_table(&keymap_t.default_view, &search_query, sort_by)
} else {
- widgets::get_keymap_table(keymap_t, &search_query[1..], sort_by)
+ widgets::get_keymap_table(&keymap_t.default_view, &search_query[1..], sort_by)
};
context.remove_external_preview();
@@ -49,7 +49,7 @@ pub fn help_loop(
Event::Key(Key::Char('/')) => search_query.push('/'),
event => {
if let Some(CommandKeybind::SimpleKeybind(command)) =
- keymap_t.as_ref().get(&event)
+ keymap_t.help_view.get(&event)
{
match command {
Command::CursorMoveUp(_) => move_offset(&mut offset, -1),
diff --git a/src/commands/show_tasks.rs b/src/commands/show_tasks.rs
new file mode 100644
index 0000000..a1acd23
--- /dev/null
+++ b/src/commands/show_tasks.rs
@@ -0,0 +1,55 @@
+use crate::config::AppKeyMapping;
+use crate::context::AppContext;
+use crate::error::JoshutoResult;
+use crate::event::process_event;
+use crate::event::AppEvent;
+use crate::key_command::{Command, CommandKeybind};
+use crate::ui::views::TuiWorkerView;
+use crate::ui::TuiBackend;
+use crate::util::to_string::ToString;
+
+pub fn show_tasks(
+ context: &mut AppContext,
+ backend: &mut TuiBackend,
+ keymap_t: &AppKeyMapping,
+) -> JoshutoResult {
+ context.flush_event();
+
+ loop {
+ backend.render(TuiWorkerView::new(context));
+
+ if let Ok(event) = context.poll_event() {
+ match event {
+ AppEvent::Termion(key) => {
+ match key {
+ key => match keymap_t.task_view.get(&key) {
+ None => {
+ context
+ .message_queue_mut()
+ .push_info(format!("Unmapped input: {}", key.to_string()));
+ }
+ Some(CommandKeybind::SimpleKeybind(command)) => match command {
+ Command::ShowTasks => break,
+ _ => {}
+ },
+ Some(CommandKeybind::CompositeKeybind(m)) => {
+ let cmd =
+ process_event::get_input_while_composite(backend, context, &m);
+
+ if let Some(command) = cmd {
+ match command {
+ Command::ShowTasks => break,
+ _ => {}
+ }
+ }
+ }
+ },
+ }
+ context.flush_event();
+ }
+ event => process_event::process_noninteractive(event, context),
+ };
+ }
+ }
+ Ok(())
+}
diff --git a/src/commands/show_workers.rs b/src/commands/show_workers.rs
deleted file mode 100644
index e20530a..0000000
--- a/src/commands/show_workers.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-use termion::event::{Event, Key};
-
-use crate::config::AppKeyMapping;
-use crate::context::AppContext;
-use crate::error::JoshutoResult;
-use crate::event::process_event;
-use crate::event::AppEvent;
-use crate::ui::views::TuiWorkerView;
-use crate::ui::TuiBackend;
-
-pub fn show_workers(
- context: &mut AppContext,
- backend: &mut TuiBackend,
- _keymap_t: &AppKeyMapping,
-) -> JoshutoResult {
- context.flush_event();
-
- loop {
- backend.render(TuiWorkerView::new(context));
-
- if let Ok(event) = context.poll_event() {
- match event {
- AppEvent::Termion(Event::Key(Key::Esc)) => {
- break;
- }
- AppEvent::Termion(_) => {
- context.flush_event();
- }
- event => process_event::process_noninteractive(event, context),
- };
- }
- }
- Ok(())
-}
diff --git a/src/config/keymap/keymapping.rs b/src/config/keymap/keymapping.rs
index 8d8b108..a14cb12 100644
--- a/src/config/keymap/keymapping.rs
+++ b/src/config/keymap/keymapping.rs
@@ -1,7 +1,7 @@
use serde_derive::Deserialize;
use std::collections::{hash_map::Entry, HashMap};
-use std::convert::{AsMut, AsRef, From};
+use std::convert::From;
use std::str::FromStr;
use termion::event::Event;
@@ -20,75 +20,85 @@ struct CommandKeymap {
}
#[derive(Debug, Deserialize)]
-struct AppKeyMappingCrude {
+struct AppModeKeyMapping {
#[serde(default)]
- pub mapcommand: Vec<CommandKeymap>,
+ pub keymap: Vec<CommandKeymap>,
}
+#[derive(Debug, Deserialize)]
+struct AppKeyMappingRaw {
+ pub default_view: AppModeKeyMapping,
+ pub task_view: AppModeKeyMapping,
+ pub help_view: AppModeKeyMapping,
+}
+
+pub type KeyMapping = HashMap<Event, CommandKeybind>;
+
#[derive(Debug)]
pub struct AppKeyMapping {
- map: HashMap<Event, CommandKeybind>,
+ pub default_view: KeyMapping,
+ pub task_view: KeyMapping,
+ pub help_view: KeyMapping,
}
impl AppKeyMapping {
pub fn new() -> Self {
Self {
- map: HashMap::new(),
+ default_view: KeyMapping::new(),
+ task_view: KeyMapping::new(),
+ help_view: KeyMapping::new(),
}
}
pub fn default_res() -> JoshutoResult<Self> {
- let crude: AppKeyMappingCrude = toml::from_str(DEFAULT_CONFIG_FILE_PATH)?;
+ let crude: AppKeyMappingRaw = toml::from_str(DEFAULT_CONFIG_FILE_PATH)?;
let keymapping: Self = Self::from(crude);
Ok(keymapping)
}
}
-impl AsRef<HashMap<Event, CommandKeybind>> for AppKeyMapping {
- fn as_ref(&self) -> &HashMap<Event, CommandKeybind> {
- &self.map
- }
-}
+fn vec_to_map(vec: &[CommandKeymap]) -> HashMap<Event, CommandKeybind> {
+ let mut hashmap = HashMap::new();
+
+ for m in vec {
+ match Command::from_str(m.command.as_str()) {
+ Ok(command) => {
+ let events: Vec<Event> = m
+ .keys
+ .iter()
+ .filter_map(|s| str_to_event(s.as_str()))
+ .collect();
+
+ if events.len() != m.keys.len() {
+ eprintln!("Failed to parse events: {:?}", m.keys);
+ continue;
+ }
-impl AsMut<HashMap<Event, CommandKeybind>> for AppKeyMapping {
- fn as_mut(&mut self) -> &mut HashMap<Event, CommandKeybind> {
- &mut self.map
+ let result = insert_keycommand(&mut hashmap, command, &events);
+ match result {
+ Ok(_) => {}
+ Err(e) => eprintln!("{}", e),
+ }
+ }
+ Err(e) => eprintln!("{}", e),
+ }
}
+ hashmap
}
-impl From<AppKeyMappingCrude> for AppKeyMapping {
- fn from(crude: AppKeyMappingCrude) -> Self {
+impl From<AppKeyMappingRaw> for AppKeyMapping {
+ fn from(raw: AppKeyMappingRaw) -> Self {
let mut keymaps = Self::new();
- for m in crude.mapcommand {
- match Command::from_str(m.command.as_str()) {
- Ok(command) => {
- let events: Vec<Event> = m
- .keys
- .iter()
- .filter_map(|s| str_to_event(s.as_str()))
- .collect();
-
- if events.len() != m.keys.len() {
- eprintln!("Failed to parse events: {:?}", m.keys);
- continue;
- }
-
- let result = insert_keycommand(&mut keymaps, command, &events);
- match result {
- Ok(_) => {}
- Err(e) => eprintln!("{}", e),
- }
- }
- Err(e) => eprintln!("{}", e),
- }
- }
+ keymaps.default_view = vec_to_map(&raw.default_view.keymap);
+ keymaps.task_view = vec_to_map(&raw.task_view.keymap);
+ keymaps.help_view = vec_to_map(&raw.help_view.keymap);
keymaps
}
}
impl TomlConfigFile for AppKeyMapping {
fn get_config(file_name: &str) -> Self {
- parse_to_config_file::<AppKeyMappingCrude, AppKeyMapping>(file_name).unwrap_or_else(|| {
+ parse_to_config_file::<AppKeyMappingRaw, AppKeyMapping>(file_name).unwrap_or_else(|| {
eprintln!("Using default keymapping");
Self::default()
})
@@ -104,7 +114,7 @@ impl std::default::Default for AppKeyMapping {
}
fn insert_keycommand(
- keymap: &mut AppKeyMapping,
+ keymap: &mut KeyMapping,
keycommand: Command,
events: &[Event],
) -> Result<(), String> {
@@ -115,7 +125,7 @@ fn insert_keycommand(
let event = events[0].clone();
if num_events == 1 {
- match keymap.as_mut().entry(event) {
+ match keymap.entry(event) {
Entry::Occupied(_) => {
return Err(format!("Error: Keybindings ambiguous for {}", keycommand))
}
@@ -124,7 +134,7 @@ fn insert_keycommand(
return Ok(());
}
- match keymap.as_mut().entry(event) {
+ match keymap.entry(event) {
Entry::Occupied(mut entry) => match entry.get_mut() {
CommandKeybind::CompositeKeybind(ref mut m) => {
insert_keycommand(m, keycommand, &events[1..])
@@ -132,7 +142,7 @@ fn insert_keycommand(
_ => Err(format!("Error: Keybindings ambiguous for {}", keycommand)),
},
Entry::Vacant(entry) => {
- let mut new_map = AppKeyMapping::new();
+ let mut new_map = KeyMapping::new();
let result = insert_keycommand(&mut new_map, keycommand, &events[1..]);
if result.is_ok() {
let composite_command = CommandKeybind::CompositeKeybind(new_map);
diff --git a/src/config/keymap/mod.rs b/src/config/keymap/mod.rs
index 609f1e6..24407a2 100644
--- a/src/config/keymap/mod.rs
+++ b/src/config/keymap/mod.rs
@@ -1,6 +1,6 @@
mod keymapping;
-pub use self::keymapping::AppKeyMapping;
+pub use self::keymapping::*;
#[cfg(not(target_os = "windows"))]
const DEFAULT_CONFIG_FILE_PATH: &str = include_str!("../../../config/keymap.toml");
diff --git a/src/config/mod.rs b/src/config/mod.rs
index cd79299..c1c71b7 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -6,7 +6,7 @@ pub mod preview;
pub mod theme;
pub use self::general::AppConfig;
-pub use self::keymap::AppKeyMapping;
+pub use self::keymap::*;
pub use self::mimetype::*;
pub use self::preview::*;
pub use self::theme::*;
diff --git a/src/event/process_event.rs b/src/event/process_event.rs
index 7e89225..0b7ed8d 100644
--- a/src/event/process_event.rs
+++ b/src/event/process_event.rs
@@ -6,7 +6,7 @@ use termion::event::{Event, Key, MouseButton, MouseEvent};
use tui::layout::{Constraint, Direction, Layout};
use crate::commands::{cursor_move, parent_cursor_move, reload};
-use crate::config::AppKeyMapping;
+use crate::config::{AppKeyMapping, KeyMapping};
use crate::context::AppContext;
use crate::event::AppEvent;
use crate::fs::JoshutoDirList;
@@ -21,7 +21,7 @@ use crate::util::format;
pub fn get_input_while_composite<'a>(
backend: &mut ui::TuiBackend,
context: &mut AppContext,
- keymap: &'a AppKeyMapping,
+ keymap: &'a KeyMapping,
) -> Option<&'a Command> {
let mut keymap = keymap;
@@ -35,9 +35,9 @@ pub fn get_input_while_composite<'a>(
AppEvent::Termion(event) => {
match event {
Event::Key(Key::Esc) => return None,
- event => match keymap.as_ref().get(&event) {
+ event => match keymap.get(&event) {
Some(CommandKeybind::SimpleKeybind(s)) => {
- return Some(s);
+ return Some(&s);
}
Some(CommandKeybind::CompositeKeybind(m)) => {
keymap = m;
diff --git a/src/key_command/command.rs b/src/key_command/command.rs
index 6dae33b..3cc0cb3 100644
--- a/src/key_command/command.rs
+++ b/src/key_command/command.rs
@@ -63,7 +63,7 @@ pub enum Command {
SelectFiles(String, SelectOption),
SetMode,
SubProcess(Vec<String>, bool),
- ShowWorkers,
+ ShowTasks,
ToggleHiddenFiles,
diff --git a/src/key_command/command_keybind.rs b/src/key_command/command_keybind.rs
index e989644..bd58b18 100644
--- a/src/key_command/command_keybind.rs
+++ b/src/key_command/command_keybind.rs
@@ -1,11 +1,10 @@
-use crate::config::AppKeyMapping;
-
-use super::Command;
+use crate::config::KeyMapping;
+use crate::key_command::Command;
#[derive(Debug)]
pub enum CommandKeybind {
SimpleKeybind(Command),
- CompositeKeybind(AppKeyMapping),
+ CompositeKeybind(KeyMapping),
}
impl std::fmt::Display for CommandKeybind {
diff --git a/src/key_command/constants.rs b/src/key_command/constants.rs
index d9a4202..6e4ea09 100644
--- a/src/key_command/constants.rs
+++ b/src/key_command/constants.rs
@@ -64,7 +64,7 @@ cmd_constants![
(CMD_SORT_REVERSE, "sort reverse"),
(CMD_SUBPROCESS_FOREGROUND, "shell"),
(CMD_SUBPROCESS_BACKGROUND, "spawn"),
- (CMD_SHOW_WORKERS, "show_workers"),
+ (CMD_SHOW_TASKS, "show_tasks"),
(CMD_TAB_SWITCH, "tab_switch"),
(CMD_TAB_SWITCH_INDEX, "tab_switch_index"),
(CMD_TOGGLE_HIDDEN, "toggle_hidden"),
diff --git a/src/key_command/impl_appcommand.rs b/src/key_command/impl_appcommand.rs
index c8bf2eb..68f4824 100644
--- a/src/key_command/impl_appcommand.rs
+++ b/src/key_command/impl_appcommand.rs
@@ -61,7 +61,7 @@ impl AppCommand for Command {
Self::SelectFiles(_, _) => CMD_SELECT_FILES,
Self::SetMode => CMD_SET_MODE,
- Self::ShowWorkers => CMD_SHOW_WORKERS,
+ Self::ShowTasks => CMD_SHOW_TASKS,
Self::Sort(_) => CMD_SORT,
Self::SortReverse => CMD_SORT_REVERSE,
diff --git a/src/key_command/impl_appexecute.rs b/src/key_command/impl_appexecute.rs
index 0a9725c..993d3f8 100644
--- a/src/key_command/impl_appexecute.rs
+++ b/src/key_command/impl_appexecute.rs
@@ -87,7 +87,7 @@ impl AppExecute for Command {
selection::select_files(context, pattern.as_str(), options)
}
Self::SetMode => set_mode::set_mode(context, backend),
- Self::ShowWorkers => show_workers::show_workers(context, backend, keymap_t),
+ Self::ShowTasks => show_tasks::show_tasks(context, backend, keymap_t),
Self::Sort(t) => sort::set_sort(context, *t),
Self::SortReverse => sort::toggle_reverse(context),
Self::SubProcess(v, spawn) => {
@@ -102,7 +102,7 @@ impl AppExecute for Command {
Ok(())
}
Self::TabSwitchIndex(i) => tab_ops::tab_switch_index(*i as usize, context),
- Self::Help => help::help_loop(context, backend, keymap_t),
+ Self::Help => show_help::help_loop(context, backend, keymap_t),
Self::SearchFzf => search_fzf::search_fzf(context, backend),
Self::SubdirFzf => subdir_fzf::subdir_fzf(context, backend),
diff --git a/src/key_command/impl_comment.rs b/src/key_command/impl_comment.rs
index dbc639a..59f0d00 100644
--- a/src/key_command/impl_comment.rs
+++ b/src/key_command/impl_comment.rs
@@ -79,7 +79,7 @@ impl CommandComment for Command {
Self::SetMode => "Set file permissions",
Self::SubProcess(_, false) => "Run a shell command",
Self::SubProcess(_, true) => "Run commmand in background",
- Self::ShowWorkers => "Show IO workers",
+ Self::ShowTasks => "Show running background tasks",
Self::ToggleHiddenFiles => "Toggle hidden files displaying",
diff --git a/src/key_command/impl_from_str.rs b/src/key_command/impl_from_str.rs
index 09944a3..7a19cce 100644
--- a/src/key_command/impl_from_str.rs
+++ b/src/key_command/impl_from_str.rs
@@ -74,7 +74,7 @@ impl std::str::FromStr for Command {
simple_command_conversion_case!(command, CMD_RENAME_FILE_PREPEND, Self::RenameFilePrepend);
simple_command_conversion_case!(command, CMD_SEARCH_NEXT, Self::SearchNext);
simple_command_conversion_case!(command, CMD_SEARCH_PREV, Self::SearchPrev);
- simple_command_conversion_case!(command, CMD_SHOW_WORKERS, Self::ShowWorkers);
+ simple_command_conversion_case!(command, CMD_SHOW_TASKS, Self::ShowTasks);
simple_command_conversion_case!(command, CMD_SET_MODE, Self::SetMode);
simple_command_conversion_case!(command, CMD_TOGGLE_HIDDEN, Self::ToggleHiddenFiles);
simple_command_conversion_case!(command, CMD_BULK_RENAME, Self::BulkRename);
diff --git a/src/run.rs b/src/run.rs
index 0c545d8..145e6bc 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -76,7 +76,7 @@ pub fn run(
context.message_queue_mut().push_error(e.to_string());
}
}
- key => match keymap_t.as_ref().get(&key) {
+ key => match keymap_t.default_view.get(&key) {
None => {
context
.message_queue_mut()
diff --git a/src/ui/views/tui_command_menu.rs b/src/ui/views/tui_command_menu.rs
index bc94752..2faf0e2 100644
--- a/src/ui/views/tui_command_menu.rs
+++ b/src/ui/views/tui_command_menu.rs
@@ -4,7 +4,7 @@ use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::widgets::{Clear, Widget};
-use crate::config::AppKeyMapping;
+use crate::config::KeyMapping;
use crate::context::AppContext;
use crate::ui::views::TuiView;
use crate::ui::widgets::TuiMenu;
@@ -15,11 +15,11 @@ const BOTTOM_MARGIN: usize = 1;
pub struct TuiCommandMenu<'a> {
context: &'a AppContext,
- keymap: &'a AppKeyMapping,
+ keymap: &'a KeyMapping,
}
impl<'a> TuiCommandMenu<'a> {
- pub fn new(context: &'a AppContext, keymap: &'a AppKeyMapping) -> Self {
+ pub fn new(context: &'a AppContext, keymap: &'a KeyMapping) -> Self {
Self { context, keymap }
}
}
@@ -31,7 +31,6 @@ impl<'a> Widget for TuiCommandMenu<'a> {
// draw menu
let mut display_vec: Vec<String> = self
.keymap
- .as_ref()
.iter()
.map(|(k, v)| format!(" {} {}", k.to_string(), v))
.collect();
diff --git a/src/ui/widgets/tui_help.rs b/src/ui/widgets/tui_help.rs
index cdec4db..b31c5b3 100644
--- a/src/ui/widgets/tui_help.rs
+++ b/src/ui/widgets/tui_help.rs
@@ -7,7 +7,7 @@ use tui::layout::{Constraint, Rect};
use tui::style::{Color, Modifier, Style};
use tui::widgets::{Cell, Row, Table, Widget};
-use crate::config::AppKeyMapping;
+use crate::config::KeyMapping;
use crate::key_command::traits::CommandComment;
use crate::key_command::CommandKeybind;
@@ -96,7 +96,7 @@ impl<'a> Widget for TuiHelp<'a> {
// Translates output from 'get_raw_keymap_table' into format,
// readable by TUI table widget
pub fn get_keymap_table<'a>(
- keymap: &'a AppKeyMapping,
+ keymap: &'a KeyMapping,
search_query: &'a str,
sort_by: usize,
) -> Vec<Row<'a>> {
@@ -115,17 +115,17 @@ pub fn get_keymap_table<'a>(
// This function is needed because we cannot access Row items, which
// means that we won't be able to sort binds if we create Rows directly
pub fn get_raw_keymap_table<'a>(
- keymap: &'a AppKeyMapping,
+ keymap: &'a KeyMapping,
search_query: &'a str,
sort_by: usize,
) -> Vec<[String; 3]> {
let mut rows = Vec::new();
- for (event, bind) in keymap.as_ref() {
+ for (event, bind) in keymap.iter() {
let key = key_event_to_string(event);
let (command, comment) = match bind {
CommandKeybind::SimpleKeybind(command) => (format!("{}", command), command.comment()),
CommandKeybind::CompositeKeybind(sub_keymap) => {
- let mut sub_rows = get_raw_keymap_table(sub_keymap, "", sort_by);
+ let mut sub_rows = get_raw_keymap_table(&sub_keymap, "", sort_by);
for _ in 0..sub_rows.len() {
let mut sub_row = sub_rows.pop().unwrap();
sub_row[0] = key.clone() + &sub_row[0];