mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: suspend process (Ctrl-Z) (#120)
This commit is contained in:
parent
0ff1479ce0
commit
230362d6c7
7 changed files with 27 additions and 7 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -378,6 +378,7 @@ dependencies = [
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"futures",
|
"futures",
|
||||||
"indexmap 2.0.0",
|
"indexmap 2.0.0",
|
||||||
|
"libc",
|
||||||
"natord",
|
"natord",
|
||||||
"notify",
|
"notify",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ impl Executor {
|
||||||
"escape" => cx.manager.active_mut().escape(),
|
"escape" => cx.manager.active_mut().escape(),
|
||||||
"quit" => cx.manager.quit(&cx.tasks),
|
"quit" => cx.manager.quit(&cx.tasks),
|
||||||
"close" => cx.manager.close(&cx.tasks),
|
"close" => cx.manager.close(&cx.tasks),
|
||||||
|
"suspend" => cx.manager.suspend(),
|
||||||
|
|
||||||
// Navigation
|
// Navigation
|
||||||
"arrow" => {
|
"arrow" => {
|
||||||
|
|
|
||||||
|
|
@ -50,19 +50,27 @@ impl Signals {
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
fn spawn_system_task(&self) -> Result<JoinHandle<()>> {
|
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 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 {
|
Ok(tokio::spawn(async move {
|
||||||
while let Some(signal) = signals.next().await {
|
while let Some(signal) = signals.next().await {
|
||||||
match signal {
|
match signal {
|
||||||
SIGHUP | SIGTERM | SIGINT | SIGQUIT => {
|
SIGHUP | SIGTERM | SIGQUIT | SIGINT => {
|
||||||
if tx.send(Event::Quit).is_err() {
|
if tx.send(Event::Quit).is_err() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SIGCONT => {
|
||||||
|
tx.send(Event::Stop(false, None)).ok();
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
[manager]
|
[manager]
|
||||||
|
|
||||||
keymap = [
|
keymap = [
|
||||||
{ on = [ "<Esc>" ], exec = "escape", desc = "Exit visual mode, clear selected, or cancel search" },
|
{ on = [ "<Esc>" ], exec = "escape", desc = "Exit visual mode, clear selected, or cancel search" },
|
||||||
{ on = [ "q" ], exec = "quit", desc = "Exit the process" },
|
{ 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-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
|
# Navigation
|
||||||
{ on = [ "k" ], exec = "arrow -1", desc = "Move cursor up" },
|
{ on = [ "k" ], exec = "arrow -1", desc = "Move cursor up" },
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ async-channel = "^1"
|
||||||
crossterm = "^0"
|
crossterm = "^0"
|
||||||
futures = "^0"
|
futures = "^0"
|
||||||
indexmap = "^2"
|
indexmap = "^2"
|
||||||
|
libc = "^0"
|
||||||
natord = "^1"
|
natord = "^1"
|
||||||
notify = { version = "^6", default-features = false, features = [ "macos_fsevent" ] }
|
notify = { version = "^6", default-features = false, features = [ "macos_fsevent" ] }
|
||||||
parking_lot = "^0"
|
parking_lot = "^0"
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,14 @@ impl Manager {
|
||||||
self.quit(tasks)
|
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 {
|
pub fn open(&mut self, interactive: bool) -> bool {
|
||||||
let mut files: Vec<_> = self
|
let mut files: Vec<_> = self
|
||||||
.selected()
|
.selected()
|
||||||
|
|
|
||||||
|
|
@ -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":[]}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue