kamiyaa / joshuto

ranger-like terminal file manager written in Rust
https://crates.io/crates/joshuto
GNU Lesser General Public License v3.0
3.46k stars 154 forks source link

Feature Request: Suspend process with ctrl+z #551

Closed s3igo closed 1 month ago

s3igo commented 3 months ago

In editors like Vim or TUI file managers like ranger, pressing ctrl+z sends a SIGTSTP signal to suspend the process, which can then be resumed with $ fg. It would be very useful if joshuto had this feature as well.

life00 commented 1 month ago

If the goal is to quickly be able to access the shell then for those who want such a feature you may just set some keymaps to spawn a shell. To exit you simply exit the shell as always (exit or ctrl+d).

Here is the config I use:

[default_view]
keymap = [
  { keys = ["s"], commands = [":shell "] },
  { keys = ["S"], commands = ["shell bash"] },
  { keys = ["'"], commands = ["shell bash"] },
]
s3igo commented 1 month ago

I agree that in many use cases, using :shell bash is sufficient. However, this approach has the drawback of potentially causing shell processes to nest deeper and deeper if not handled carefully, which is why I still believe this feature is valuable.

Additionally, for those who prefer a workflow where multiple background jobs, such as Vim instances, are kept running and managed using $ jobs to list them and $ fg %n to bring specific jobs to the foreground, it would be more convenient to have the ability to suspend processes with ctrl-z.

kamiyaa commented 1 month ago

I can look into this to allow a command to suspend joshuto :+1:

kamiyaa commented 1 month ago

Added suspend command support in af643dba97acbc16af603450a35bafa9b1dd9da0 which is mapped to ctrl+z by default.

There are some caveats here:

  1. This only works from within joshuto, It doesn't really work from external sources. ie. kill -s SIGTSTP $(pidof joshuto), it will cause the terminal to be all messed up. In the future, we can look into a global handler for these signals but it would probably require the handler to somehow reach into AppState and modify it
  2. This doesn't work with the bash alias function joshuto() { to allow you to exit to a specific directory. Once it suspends, this function will end and it won't try to cd to a directory
s3igo commented 1 month ago

Thank you for the implementation! It's working smoothly.