feat: suspend process (Ctrl-Z) (#120)

This commit is contained in:
三咲雅 · Misaki Masa 2023-09-07 16:08:51 +08:00 committed by GitHub
parent 0ff1479ce0
commit 230362d6c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 7 deletions

1
Cargo.lock generated
View File

@ -378,6 +378,7 @@ dependencies = [
"crossterm",
"futures",
"indexmap 2.0.0",
"libc",
"natord",
"notify",
"parking_lot",

View File

@ -57,6 +57,7 @@ impl Executor {
"escape" => cx.manager.active_mut().escape(),
"quit" => cx.manager.quit(&cx.tasks),
"close" => cx.manager.close(&cx.tasks),
"suspend" => cx.manager.suspend(),
// Navigation
"arrow" => {

View File

@ -50,19 +50,27 @@ impl Signals {
#[cfg(not(target_os = "windows"))]
fn spawn_system_task(&self) -> Result<JoinHandle<()>> {
use libc::{SIGHUP, SIGINT, SIGQUIT, SIGTERM};
use libc::{SIGCONT, SIGHUP, SIGINT, SIGQUIT, SIGTERM};
let tx = self.tx.clone();
let mut signals = signal_hook_tokio::Signals::new([SIGHUP, SIGTERM, SIGINT, SIGQUIT])?;
let mut signals = signal_hook_tokio::Signals::new([
// Terminating signals
SIGHUP, SIGTERM, SIGQUIT, SIGINT, //
// Job control signals
SIGCONT,
])?;
Ok(tokio::spawn(async move {
while let Some(signal) = signals.next().await {
match signal {
SIGHUP | SIGTERM | SIGINT | SIGQUIT => {
SIGHUP | SIGTERM | SIGQUIT | SIGINT => {
if tx.send(Event::Quit).is_err() {
break;
}
}
SIGCONT => {
tx.send(Event::Stop(false, None)).ok();
}
_ => {}
}
}

View File

@ -4,6 +4,7 @@ keymap = [
{ on = [ "<Esc>" ], exec = "escape", desc = "Exit visual mode, clear selected, or cancel search" },
{ on = [ "q" ], exec = "quit", desc = "Exit the process" },
{ on = [ "<C-q>" ], exec = "close", desc = "Close the current tab, or quit if it is last tab" },
{ on = [ "<C-z>" ], exec = "suspend", desc = "Suspend the process" },
# Navigation
{ on = [ "k" ], exec = "arrow -1", desc = "Move cursor up" },

View File

@ -14,6 +14,7 @@ async-channel = "^1"
crossterm = "^0"
futures = "^0"
indexmap = "^2"
libc = "^0"
natord = "^1"
notify = { version = "^6", default-features = false, features = [ "macos_fsevent" ] }
parking_lot = "^0"

View File

@ -121,6 +121,14 @@ impl Manager {
self.quit(tasks)
}
pub fn suspend(&mut self) -> bool {
tokio::spawn(async move {
emit!(Stop(true)).await;
unsafe { libc::raise(libc::SIGTSTP) };
});
false
}
pub fn open(&mut self, interactive: bool) -> bool {
let mut files: Vec<_> = self
.selected()

View File

@ -1 +1 @@
{"language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp"," Überzug"," Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs"],"version":"0.2","flagWords":[]}
{"language":"en","words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp"," Überzug"," Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT"],"version":"0.2","flagWords":[]}