-
Notifications
You must be signed in to change notification settings - Fork 287
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
[RfC] Support for backgrounding an application via Ctrl+Z
+ fg
#494
Comments
Crossterm supports signal handling with resize events already. It looks like it is possible to integrate this behavior quite easily. I will take a look into your linked comment and see the details of this issue. |
That's great, thank you! As the tui maintainer talked about the possibility to stop supporting the |
Interesting, great work on your end! I wrote the |
Thanks for the heads-up, actually I didn't know about The only reason to keep In any case, if you have anything I can help with, just let me know. In one possible future of this we would put threaded async input handling (as in crosstermion) into Just as a note: Right now all my tools consume |
Haha, yea, it could be possible to support all redox features, but I think it is a waste of time for a small userbase. The library should probably focus on solid support for 99.5% of the users.
Crossterm supports async input ontop of futures, why do you think crosstermion has something special to offer on top of this?
Crossterm is quite to stable and should be almost ready for a 1.0, I don't have a lot of time to work on it, this signal issue might be interesting to get working. For the rest #407 is hard to get fixed. I am not sure on why /dev/tty can not be opened on MacOs systems. Perhaps you have some knowledge in that area? |
You are right, probably I could put this chunk of code anywhere where it's needed without using a common crate or have that functionality in
I have no knowledge, unfortunately, but will be giving it a spin to see what happens. Maybe I can figure something out.
But it's great that you are as responsive as you are when dealing with issues and PRs - this makes a massive difference and enables others to fix up what they need! |
I did take a look at the issue, just to realize that it probably takes quite a while to truly understand how everything is working with async events from the ground up, especially given my generally lack of knowledge on how a (BSD) tty actually works, and what shortcomings there might be compared to Linux. This is where I would be interested to know how curses does it, assuming it's the most complete and most portable implementation out there. That said, a possible approach for me was to try to implement this myself in the simplest possible way - it would certainly be interesting to start to understand the machinery I use every day :D. |
I'm trying to combat this too. I haven't found anything on the Internet about Ctrl+Z handling! The only clue is using if let Event::Key(key) = input {
if let KeyCode::Char('z') = key.code {
if key.modifiers.contains(KeyModifiers::CONTROL) {
.... Because it looks like the signal loop is endless, so I had to run it in a separate thread via |
I was able to mostly bring this feature back here. If the app is called directly from shell, then you're basically all set. But if called from another app ( The basic idea is to run this: disable_raw_mode().unwrap();
std::io::stdout().execute(LeaveAlternateScreen).unwrap();
signal_hook::low_level::emulate_default_handler(SIGTSTP).unwrap(); The thread (and I think all children) will stop executing on the last line. And when you resume it will start from the line below (where signal was fired). Since the app uses tokio runtime, I also had to use the tokio adapter crate. And additionally, the ratatui screen must be cleared after the CONT signal is received as well as other stuff: enable_raw_mode().unwrap();
std::io::stdout().execute(EnterAlternateScreen).unwrap(); That's it. But I think disabling the initial remapping of Ctrl+Z is the only right way to go (when crossterm-rs initializes its key press listener or whatever). |
Hi,
I am the maintainer of
dua
, a tool to visualize disk usage and act on it, usingtui
with either thetermion
orcrossterm
backend.Recently an issue popped up indicating that backgrounding an application with Ctrl+Z does not work as expected, leaving the terminal in a messy state (independently of the application having to handle Ctrl+Z itself in RAW mode). The long version of what's happening there is in this comment, in short one would need capabilities to install signal handlers for SIGTSTP and SIGCONT, along with the ability to send oneself a signal to stop a process.
In theory, the
crossterm
project is in the best position to implement this in a cross-platform way, which in theory could work for othertui
backends as well, liketermion
.As the maintainer of the
crosstermion
crate, I could imagine implementing a proof of concept as well, probably without windows support.What do you think about this, I am keen to hear your thoughts.
Thank you
The text was updated successfully, but these errors were encountered: