Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: suspend process (Ctrl-Z) #120

Merged
merged 1 commit into from
Sep 7, 2023
Merged

feat: suspend process (Ctrl-Z) #120

merged 1 commit into from
Sep 7, 2023

Conversation

sxyazi
Copy link
Owner

@sxyazi sxyazi commented Sep 7, 2023

New Feature: You can press Ctrl-Z to suspend Yazi in the background, and then use fg to resume it

An implementation of the feature request: #105

Close #105


1.mp4

@sxyazi sxyazi merged commit 230362d into main Sep 7, 2023
@sxyazi sxyazi deleted the pr-117d4e41 branch September 7, 2023 08:08
@teto
Copy link

teto commented Sep 7, 2023

that's weird, I've recompiled from scratch 230362d and I cant suspend (nixos). Would be curious if someone else can try

@sxyazi
Copy link
Owner Author

sxyazi commented Sep 7, 2023

@teto Hey, this is a new command, if you're not using the default config, you'll need to add it to your config file:

{ on = [ "<C-z>" ], exec = "suspend", desc = "Suspend the process" },

@teto
Copy link

teto commented Sep 7, 2023

ha I see. I am not familiar with how it is implemented usually but this mapping works for 99% of the software out of the box, I feel like this should be maybe a (compiled) default.

BTW: it worked.

@sxyazi
Copy link
Owner Author

sxyazi commented Sep 7, 2023

I feel like this should be maybe a (compiled) default

It is already included in the default config of Yazi, so this is the default behavior.

For users who were using their own config files before this feature was introduced, they will need to add it themselves. I want to clarify -- this is based on Yazi's conservative expectation of user config, rather than bringing uncertain "surprises" to users, it seems better to let users find and add them when they truly need them.


I am not familiar with how it is implemented usually but this mapping works for 99% of the software out of the box

Regarding the implementation details, Yazi and similar TUI apps run in raw mode, accepting all user input. Therefore, Ctrl-Z cannot be handled by bash/zsh, and can only be listened to and processed by Yazi when users press it.

@teto
Copy link

teto commented Sep 7, 2023

Thank you very much for the explanation, I supposed that yazi was catching everything; I guess in most cases, zsh catches the Ctrl-Z and is the one sending the signal.

this is based on Yazi's conservative expectation of user config, rather than bringing uncertain "surprises" to users

I dont really mind either way but in this case the uncertain surprise is to have "Ctrl-Z" not working IMO. The number of times I had a misfunctioning program that I stopped with Ctrl-C is huge. Let's say for some reason yazi goes into an infinite loop, having Ctrl-C registered automatically makes sense

@sxyazi
Copy link
Owner Author

sxyazi commented Sep 7, 2023

I supposed that yazi was catching everything; I guess in most cases, zsh catches the Ctrl-Z and is the one sending the signal

Yes, when a TUI app is running in raw mode, it needs to handle all user keypresses by itself. However, when running in cooked mode, keys like Ctrl-Z and Ctrl-C are typically handled by the shell.

Let's say for some reason yazi goes into an infinite loop, having Ctrl-C registered automatically makes sense

Given the reasons mentioned above, this doesn't seem to hold true. Since Ctrl-C needs to be handled by the TUI app, not the shell, there might not be an opportunity to process Ctrl-C when the app is consuming 100% CPU.

in this case the uncertain surprise is to have "Ctrl-Z" not working IMO

Are you meaning hardcoding the registration of Ctrl-Z for all users in the code? If that's the case, it seems like an impact on potential user keybindings. Some users (like me) may not frequently use the "suspend" and could have Ctrl-Z bound to other actions, considering that this key is close to Ctrl :)

@teto
Copy link

teto commented Sep 7, 2023

Are you meaning hardcoding the registration of Ctrl-Z for all users in the code? If that's the case, it seems like an impact on potential user keybindings. Some users (like me) may not frequently use the "suspend" and could have Ctrl-Z bound to other actions, considering that this key is close to Ctrl :)

since yazi doesn't merge the default config with user's config, what I suggest is something we do in neovim too: when the program starts, it maps Ctrl-z to suspend before loading the system/user configuration: users are thus free to remap Ctrl-Z.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ctrl-z doesn't send yazi to foregroud
2 participants