diff --git a/config/keymap.toml b/config/keymap.toml index b59ccb96a..edf6df3a9 100644 --- a/config/keymap.toml +++ b/config/keymap.toml @@ -9,6 +9,7 @@ keymap = [ { keys = ["ctrl+w"], commands = ["close_tab"] }, { keys = ["q"], commands = ["close_tab"] }, { keys = ["ctrl+c"], commands = ["quit"] }, + { keys = ["ctrl+z"], commands = ["suspend"] }, { keys = ["Q"], commands = ["quit --output-current-directory"] }, { keys = ["R"], commands = ["reload_dirlist"] }, diff --git a/docs/configuration/keymap.toml.md b/docs/configuration/keymap.toml.md index 807dd3577..8fbe5e155 100644 --- a/docs/configuration/keymap.toml.md +++ b/docs/configuration/keymap.toml.md @@ -147,6 +147,9 @@ function joshuto() { ] ``` +### `suspend`: suspends the current session +can be mapped to Ctrl+z to behave similarly to other programs + ### `sort`: change the sort method - `sort lexical`: sort lexically (`10.txt` comes before `2.txt`) @@ -378,7 +381,7 @@ This command has the same options for `select`. Notice that it's necessary to qu ### `select_fzf`: select files in the current directory via fzf -This command has the same options for `select`. Use tab to select or deselect files in fzf. +This command has the same options for `select`. Use tab to select or deselect files in fzf. ### `filter`: filter the current directory list. @@ -407,7 +410,7 @@ When disabling, the current “visual mode selection” is turned into normal se - `--type=string`: change configurations of operations using substring matching - `--type=glob`: change configurations of operations using glob matching - `--type=regex`: change configurations of operations using regex - - `--type=fzf`: change configurations of operations using fzf + - `--type=fzf`: change configurations of operations using fzf - when no option is added, type is set to `string` by default - Value - `insensitive` @@ -426,7 +429,7 @@ Define search command using [`custom_command`]() ### `custom_search_interactive` -Similar to `select` and `custom_search`. Allows user to execute `custom_command` and +Similar to `select` and `custom_search`. Allows user to execute `custom_command` and then interactively operate on the results. ## Bookmarks diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 02900a7a9..c3d444ab9 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -38,6 +38,7 @@ pub mod set_mode; pub mod show_help; pub mod show_hidden; pub mod show_tasks; +pub mod signal; pub mod sort; pub mod stdout; pub mod sub_process; diff --git a/src/commands/signal.rs b/src/commands/signal.rs new file mode 100644 index 000000000..65160cdd3 --- /dev/null +++ b/src/commands/signal.rs @@ -0,0 +1,15 @@ +use nix::libc::raise; +use nix::sys::signal::Signal; + +use crate::error::AppResult; +use crate::ui::AppBackend; + +pub fn signal_suspend(backend: &mut AppBackend) -> AppResult { + backend.terminal_drop(); + unsafe { + let signal: i32 = Signal::SIGTSTP as i32; + raise(signal); + } + backend.terminal_restore()?; + Ok(()) +} diff --git a/src/constants/command_name.rs b/src/constants/command_name.rs index 0888e9d86..4c3eda47e 100644 --- a/src/constants/command_name.rs +++ b/src/constants/command_name.rs @@ -97,4 +97,5 @@ cmd_constants![ (CMD_BOOKMARK_CHANGE_DIRECTORY, "cd_bookmark"), (CMD_CUSTOM_SEARCH, "custom_search"), (CMD_CUSTOM_SEARCH_INTERACTIVE, "custom_search_interactive"), + (CMD_SIGNAL_SUSPEND, "suspend"), ]; diff --git a/src/types/command/impl_appcommand.rs b/src/types/command/impl_appcommand.rs index b6f990733..94f3c73d6 100644 --- a/src/types/command/impl_appcommand.rs +++ b/src/types/command/impl_appcommand.rs @@ -104,6 +104,8 @@ impl AppCommand for Command { Self::SwitchLineNums(_) => CMD_SWITCH_LINE_NUMBERS, Self::SetLineMode(_) => CMD_SET_LINEMODE, + Self::SignalSuspend => CMD_SIGNAL_SUSPEND, + Self::TabSwitch { .. } => CMD_TAB_SWITCH, Self::TabSwitchIndex { .. } => CMD_TAB_SWITCH_INDEX, Self::ToggleHiddenFiles => CMD_TOGGLE_HIDDEN, diff --git a/src/types/command/impl_appexecute.rs b/src/types/command/impl_appexecute.rs index b7c5064c3..2fbc3b08b 100644 --- a/src/types/command/impl_appexecute.rs +++ b/src/types/command/impl_appexecute.rs @@ -152,6 +152,7 @@ impl AppExecute for Command { } => sort::set_sort(app_state, *sort_method, *reverse), Self::SetLineMode(mode) => linemode::set_linemode(app_state, *mode), Self::SortReverse => sort::toggle_reverse(app_state), + Self::SignalSuspend => signal::signal_suspend(backend), Self::SubProcess { words, mode } => { sub_process::sub_process(app_state, backend, words.as_slice(), mode.clone()) } diff --git a/src/types/command/impl_comment.rs b/src/types/command/impl_comment.rs index d8890a4fe..2f6c83472 100644 --- a/src/types/command/impl_comment.rs +++ b/src/types/command/impl_comment.rs @@ -103,6 +103,8 @@ impl CommandComment for Command { Self::StdOutPostProcess { .. } => "Post process stdout of last `shell` command", Self::ShowTasks => "Show running background tasks", + Self::SignalSuspend => "Suspend the current session", + Self::ToggleHiddenFiles => "Toggle hidden files displaying", Self::SwitchLineNums(_) => "Switch line numbering", diff --git a/src/types/command/impl_from_str.rs b/src/types/command/impl_from_str.rs index 7caa4003d..36cb28aab 100644 --- a/src/types/command/impl_from_str.rs +++ b/src/types/command/impl_from_str.rs @@ -118,6 +118,8 @@ impl std::str::FromStr for Command { Self::ZoxideInteractive(arg.to_string()) ); + simple_command_conversion_case!(command, CMD_SIGNAL_SUSPEND, Self::SignalSuspend); + if command == CMD_QUIT { match arg { "--force" => Ok(Self::Quit(QuitAction::Force)), diff --git a/src/types/command/mod.rs b/src/types/command/mod.rs index 8ceef963b..19ac8d7d4 100644 --- a/src/types/command/mod.rs +++ b/src/types/command/mod.rs @@ -151,6 +151,8 @@ pub enum Command { }, ShowTasks, + SignalSuspend, + ToggleHiddenFiles, SwitchLineNums(LineNumberStyle),