Skip to content

Commit

Permalink
add suspend command support
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiyaa committed Sep 27, 2024
1 parent 2bd540b commit af643db
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions config/keymap.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] },
Expand Down
9 changes: 6 additions & 3 deletions docs/configuration/keymap.toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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`
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/commands/signal.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
1 change: 1 addition & 0 deletions src/constants/command_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
];
2 changes: 2 additions & 0 deletions src/types/command/impl_appcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/types/command/impl_appexecute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/command/impl_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/types/command/impl_from_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
2 changes: 2 additions & 0 deletions src/types/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ pub enum Command {
},
ShowTasks,

SignalSuspend,

ToggleHiddenFiles,
SwitchLineNums(LineNumberStyle),

Expand Down

0 comments on commit af643db

Please sign in to comment.