summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/config/keymap/default_keymap.rs97
-rw-r--r--src/config/keymap/keymapping.rs176
-rw-r--r--src/config/keymap/mod.rs1
-rw-r--r--src/error/error_kind.rs16
-rw-r--r--src/error/error_type.rs23
5 files changed, 135 insertions, 178 deletions
diff --git a/src/config/keymap/default_keymap.rs b/src/config/keymap/default_keymap.rs
new file mode 100644
index 0000000..a8ede07
--- /dev/null
+++ b/src/config/keymap/default_keymap.rs
@@ -0,0 +1,97 @@
+pub const DEFAULT_KEYMAP: &str = "
+mapcommand = [
+ { keys = [ \"T\" ], command = \"new_tab\" },
+ { keys = [ \"ctrl+t\" ], command = \"new_tab\" },
+ { keys = [ \"W\" ], command = \"close_tab\" },
+ { keys = [ \"ctrl+w\" ], command = \"close_tab\" },
+ { keys = [ \"q\" ], command = \"close_tab\" },
+ { keys = [ \"Q\" ], command = \"quit_to_cwd\" },
+
+ { keys = [ \"R\" ], command = \"reload_dirlist\" },
+ { keys = [ \"z\", \"h\" ], command = \"toggle_hidden\" },
+ { keys = [ \"\t\" ], command = \"tab_switch 1\" },
+ { keys = [ \"backtab\" ], command = \"tab_switch -1\" },
+
+ { keys = [ \"alt+1\" ], command = \"tab_switch_index 1\" },
+ { keys = [ \"alt+2\" ], command = \"tab_switch_index 2\" },
+ { keys = [ \"alt+3\" ], command = \"tab_switch_index 3\" },
+ { keys = [ \"alt+4\" ], command = \"tab_switch_index 4\" },
+ { keys = [ \"alt+5\" ], command = \"tab_switch_index 5\" },
+
+ # arrow keys
+ { keys = [ \"arrow_up\" ], command = \"cursor_move_up\" },
+ { keys = [ \"arrow_down\" ], command = \"cursor_move_down\" },
+ { 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 = [ \"page_up\" ], command = \"cursor_move_page_up\" },
+ { keys = [ \"page_down\" ], command = \"cursor_move_page_down\" },
+
+ # vim-like keybindings
+ { keys = [ \"j\" ], command = \"cursor_move_down\" },
+ { keys = [ \"k\" ], command = \"cursor_move_up\" },
+ { keys = [ \"h\" ], command = \"cd ..\" },
+ { keys = [ \"l\" ], command = \"open\" },
+ { keys = [ \"g\", \"g\" ], command = \"cursor_move_home\" },
+ { keys = [ \"G\" ], command = \"cursor_move_end\" },
+ { keys = [ \"r\" ], command = \"open_with\" },
+
+ { keys = [ \"[\" ], command = \"parent_cursor_move_up\" },
+ { keys = [ \"]\" ], command = \"parent_cursor_move_down\" },
+
+ { keys = [ \"c\", \"d\" ], command = \":cd \" },
+ { keys = [ \"d\", \"d\" ], command = \"cut_files\" },
+ { keys = [ \"y\", \"y\" ], command = \"copy_files\" },
+ { keys = [ \"p\", \"p\" ], command = \"paste_files\" },
+ { keys = [ \"p\", \"o\" ], command = \"paste_files --overwrite=true\" },
+
+ { keys = [ \"y\", \"n\" ], command = \"copy_filename\" },
+ { keys = [ \"y\", \".\" ], command = \"copy_filename_without_extension\" },
+ { keys = [ \"y\", \"p\" ], command = \"copy_filepath\" },
+ { keys = [ \"y\", \"d\" ], command = \"copy_dirpath\" },
+
+ { keys = [ \"delete\" ], command = \"delete_files\" },
+ { keys = [ \"d\", \"D\" ], command = \"delete_files\" },
+
+ { keys = [ \"a\" ], command = \"rename_append\" },
+ { keys = [ \"A\" ], command = \"rename_prepend\" },
+
+ { keys = [ \"f\", \"t\" ], command = \":touch \" },
+
+ { keys = [ \" \" ], command = \"select --toggle=true\" },
+ { keys = [ \"t\" ], command = \"select --all=true --toggle=true\" },
+
+ { keys = [ \"w\" ], command = \"show_workers --exit-key=w\" },
+ { keys = [ \"b\", \"b\" ], command = \"bulk_rename\" },
+ { keys = [ \"=\" ], command = \"set_mode\" },
+
+ { keys = [ \":\" ], command = \":\" },
+ { keys = [ \";\" ], command = \":\" },
+
+ { keys = [ \"'\" ], command = \":shell \" },
+ { keys = [ \"m\", \"k\" ], command = \":mkdir \" },
+ { keys = [ \"c\", \"w\" ], command = \":rename \" },
+
+ { keys = [ \"/\" ], command = \":search \" },
+ { keys = [ \"\\\" ], command = \":search_glob \" },
+ { keys = [ \"S\" ], command = \"search_fzf\" },
+
+ { keys = [ \"n\" ], command = \"search_next\" },
+ { keys = [ \"N\" ], command = \"search_prev\" },
+
+ { keys = [ \"s\", \"r\" ], command = \"sort reverse\" },
+ { keys = [ \"s\", \"l\" ], command = \"sort lexical\" },
+ { keys = [ \"s\", \"m\" ], command = \"sort mtime\" },
+ { keys = [ \"s\", \"n\" ], command = \"sort natural\" },
+ { keys = [ \"s\", \"s\" ], command = \"sort size\" },
+ { keys = [ \"s\", \"e\" ], command = \"sort ext\" },
+
+ { keys = [ \"g\", \"r\" ], command = \"cd /\" },
+ { keys = [ \"g\", \"c\" ], command = \"cd ~/.config\" },
+ { keys = [ \"g\", \"d\" ], command = \"cd ~/Downloads\" },
+ { keys = [ \"g\", \"e\" ], command = \"cd /etc\" },
+ { keys = [ \"g\", \"h\" ], command = \"cd ~/\" },
+ { keys = [ \"?\" ], command = \"help\" }
+]";
diff --git a/src/config/keymap/keymapping.rs b/src/config/keymap/keymapping.rs
index 9250c28..0f42e94 100644
--- a/src/config/keymap/keymapping.rs
+++ b/src/config/keymap/keymapping.rs
@@ -8,10 +8,13 @@ use termion::event::MouseEvent;
use termion::event::{Event, Key};
use crate::config::{parse_to_config_file, ConfigStructure, Flattenable};
+use crate::error::JoshutoResult;
use crate::io::IoWorkerOptions;
use crate::key_command::{Command, CommandKeybind};
use crate::util::keyparse::str_to_event;
+use super::default_keymap::DEFAULT_KEYMAP;
+
#[derive(Debug, Deserialize)]
struct CommandKeymap {
pub command: String,
@@ -78,179 +81,16 @@ impl AppKeyMapping {
}
}
- pub fn default_res(&mut self) -> Result<(), String> {
- let mut m = self;
-
- let cmd = Command::CursorMoveUp(1);
- let keys = [Event::Key(Key::Up)];
- insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = Command::CursorMoveDown(1);
- let keys = [Event::Key(Key::Down)];
- insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = Command::ParentDirectory;
- let keys = [Event::Key(Key::Left)];
- insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = Command::OpenFile;
- let keys = [Event::Key(Key::Right)];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::OpenFile;
- let keys = [Event::Key(Key::Char('\n'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CursorMoveHome;
- let keys = [Event::Key(Key::Home)];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CursorMoveEnd;
- let keys = [Event::Key(Key::End)];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CursorMovePageUp;
- let keys = [Event::Key(Key::PageUp)];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CursorMovePageDown;
- let keys = [Event::Key(Key::PageDown)];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- // vim keys
- let cmd = Command::CursorMoveUp(1);
- let keys = [Event::Key(Key::Char('k'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CursorMoveDown(1);
- let keys = [Event::Key(Key::Char('j'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::ParentDirectory;
- let keys = [Event::Key(Key::Char('h'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::OpenFile;
- let keys = [Event::Key(Key::Char('l'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::NewTab;
- let keys = [Event::Key(Key::Char('T'))];
- insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = Command::NewTab;
- let keys = [Event::Key(Key::Ctrl('t'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CloseTab;
- let keys = [Event::Key(Key::Char('W'))];
- insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = Command::CloseTab;
- let keys = [Event::Key(Key::Ctrl('w'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CloseTab;
- let keys = [Event::Key(Key::Char('q'))];
- insert_keycommand(&mut m, cmd, &keys)?;
- let cmd = Command::ForceQuit;
- let keys = [Event::Key(Key::Char('Q'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::ReloadDirList;
- let keys = [Event::Key(Key::Char('R'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::ToggleHiddenFiles;
- let keys = [Event::Key(Key::Char('z')), Event::Key(Key::Char('h'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::TabSwitch(1);
- let keys = [Event::Key(Key::Char('\t'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::TabSwitch(-1);
- let keys = [Event::Key(Key::BackTab)];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::OpenFileWith(None);
- let keys = [Event::Key(Key::Char('r'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CutFiles;
- let keys = [Event::Key(Key::Char('d')), Event::Key(Key::Char('d'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CopyFiles;
- let keys = [Event::Key(Key::Char('y')), Event::Key(Key::Char('y'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::PasteFiles(IoWorkerOptions::default());
- let keys = [Event::Key(Key::Char('p')), Event::Key(Key::Char('p'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::DeleteFiles;
- let keys = [Event::Key(Key::Delete)];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::DeleteFiles;
- let keys = [Event::Key(Key::Char('D')), Event::Key(Key::Char('d'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::RenameFileAppend;
- let keys = [Event::Key(Key::Char('a'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::RenameFilePrepend;
- let keys = [Event::Key(Key::Char('A'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CommandLine("search ".to_string(), "".to_string());
- let keys = [Event::Key(Key::Char('/'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::SearchNext;
- let keys = [Event::Key(Key::Char('n'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::SearchPrev;
- let keys = [Event::Key(Key::Char('N'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::BulkRename;
- let keys = [Event::Key(Key::Char('b')), Event::Key(Key::Char('b'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::SetMode;
- let keys = [Event::Key(Key::Char('='))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CommandLine("".to_string(), "".to_string());
- let keys = [Event::Key(Key::Char(';'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CommandLine("".to_string(), "".to_string());
- let keys = [Event::Key(Key::Char(':'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CommandLine("mkdir ".to_string(), "".to_string());
- let keys = [Event::Key(Key::Char('m')), Event::Key(Key::Char('k'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::CommandLine("rename ".to_string(), "".to_string());
- let keys = [Event::Key(Key::Char('c')), Event::Key(Key::Char('w'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- let cmd = Command::Help;
- let keys = [Event::Key(Key::Char('?'))];
- insert_keycommand(&mut m, cmd, &keys)?;
-
- Ok(())
+ pub fn default_res() -> JoshutoResult<Self> {
+ let raw: RawAppKeyMapping = toml::from_str(DEFAULT_KEYMAP)?;
+ let keymapping: Self = raw.flatten();
+ Ok(keymapping)
}
}
impl std::default::Default for AppKeyMapping {
fn default() -> Self {
- let mut m = Self {
- map: HashMap::new(),
- };
- let _ = m.default_res();
- m
+ AppKeyMapping::default_res().unwrap()
}
}
diff --git a/src/config/keymap/mod.rs b/src/config/keymap/mod.rs
index 14ad630..3ffde21 100644
--- a/src/config/keymap/mod.rs
+++ b/src/config/keymap/mod.rs
@@ -1,3 +1,4 @@
mod keymapping;
+mod default_keymap;
pub use self::keymapping::AppKeyMapping;
diff --git a/src/error/error_kind.rs b/src/error/error_kind.rs
index 679ad32..50fbf16 100644
--- a/src/error/error_kind.rs
+++ b/src/error/error_kind.rs
@@ -1,6 +1,7 @@
+use std::convert::From;
use std::io;
-#[derive(Copy, Clone, Debug)]
+#[derive(Clone, Debug)]
pub enum JoshutoErrorKind {
// io related
Io(io::ErrorKind),
@@ -11,6 +12,7 @@ pub enum JoshutoErrorKind {
// parse error
ParseError,
ClipboardError,
+ TomlDeError(toml::de::Error),
Glob,
@@ -20,20 +22,26 @@ pub enum JoshutoErrorKind {
UnrecognizedCommand,
}
-impl std::convert::From<io::ErrorKind> for JoshutoErrorKind {
+impl From<io::ErrorKind> for JoshutoErrorKind {
fn from(err: io::ErrorKind) -> Self {
Self::Io(err)
}
}
-impl std::convert::From<&globset::ErrorKind> for JoshutoErrorKind {
+impl From<&globset::ErrorKind> for JoshutoErrorKind {
fn from(_: &globset::ErrorKind) -> Self {
Self::Glob
}
}
-impl std::convert::From<std::env::VarError> for JoshutoErrorKind {
+impl From<std::env::VarError> for JoshutoErrorKind {
fn from(_: std::env::VarError) -> Self {
Self::EnvVarNotPresent
}
}
+
+impl From<toml::de::Error> for JoshutoErrorKind {
+ fn from(err: toml::de::Error) -> Self {
+ Self::TomlDeError(err)
+ }
+}
diff --git a/src/error/error_type.rs b/src/error/error_type.rs
index 9ca849a..d35b808 100644
--- a/src/error/error_type.rs
+++ b/src/error/error_type.rs
@@ -1,7 +1,9 @@
+use std::convert::From;
use std::io;
use super::JoshutoErrorKind;
+#[derive(Clone, Debug)]
pub struct JoshutoError {
_kind: JoshutoErrorKind,
_cause: String,
@@ -13,8 +15,8 @@ impl JoshutoError {
Self { _kind, _cause }
}
- pub fn kind(&self) -> JoshutoErrorKind {
- self._kind
+ pub fn kind(&self) -> &JoshutoErrorKind {
+ &self._kind
}
}
@@ -24,7 +26,7 @@ impl std::fmt::Display for JoshutoError {
}
}
-impl std::convert::From<io::Error> for JoshutoError {
+impl From<io::Error> for JoshutoError {
fn from(err: io::Error) -> Self {
Self {
_kind: JoshutoErrorKind::from(err.kind()),
@@ -33,7 +35,7 @@ impl std::convert::From<io::Error> for JoshutoError {
}
}
-impl std::convert::From<globset::Error> for JoshutoError {
+impl From<globset::Error> for JoshutoError {
fn from(err: globset::Error) -> Self {
Self {
_kind: JoshutoErrorKind::from(err.kind()),
@@ -42,7 +44,7 @@ impl std::convert::From<globset::Error> for JoshutoError {
}
}
-impl std::convert::From<std::env::VarError> for JoshutoError {
+impl From<std::env::VarError> for JoshutoError {
fn from(err: std::env::VarError) -> Self {
Self {
_kind: JoshutoErrorKind::from(err),
@@ -51,7 +53,7 @@ impl std::convert::From<std::env::VarError> for JoshutoError {
}
}
-impl std::convert::From<trash::Error> for JoshutoError {
+impl From<trash::Error> for JoshutoError {
fn from(err: trash::Error) -> Self {
let err = match err {
trash::Error::Unknown => {
@@ -75,3 +77,12 @@ impl std::convert::From<trash::Error> for JoshutoError {
}
}
}
+
+impl From<toml::de::Error> for JoshutoError {
+ fn from(err: toml::de::Error) -> Self {
+ Self {
+ _kind: JoshutoErrorKind::from(err),
+ _cause: "Failed to parse TOML".to_string(),
+ }
+ }
+}