-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add a panic hook to reset terminal upon panic #83
Comments
hey orhun, how can I produce unexpected error in kmon? If you can mention some keybindings or any tips, I'm happy to contribute for this issue. |
Hey @eld4niz, you can simply trigger a panic by adding diff --git a/src/lib.rs b/src/lib.rs
index 4edb06a..810cbce 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -118,6 +118,7 @@ where
| Key::Ctrl('c')
| Key::Ctrl('d')
| Key::Esc => {
+ panic!("!");
if app.show_options {
app.show_options = false;
} else { So when you press By the way, there is an ongoing discussion about panic handler and termion here: ratatui/ratatui#1005 |
@orhun I'm trying to do this within kmon: save the termios value and restore it when panicking Specifically I want to implement this functionality: termion raw.rs Just with basic search I found they used this libc: pub use self::libc::termios as Termios; should I try to implement same functionality in |
Not sure if we should go that deep. But I'm happy to see how using that functionality looks before commenting too early. I was thinking we can simply go with this: https://ratatui.rs/how-to/develop-apps/panic-hooks/#termion |
I implemented the same as documentation in our let panic_hook = panic::take_hook();
panic::set_hook(Box::new(move |panic| {
let panic_cleanup = || -> Result<(), Box<dyn Error>> {
let mut output = io::stderr();
write!(
output,
"{} {} {}",
termion::clear::All,
termion::screen::ToMainScreen,
termion::cursor::Show
?;
output.into_raw_mode()?.suspend_raw_mode()?;
io::stderr().flush()?;
Ok(())
};
panic_cleanup().expect("failed to clean up for panic");
panic_hook(panic);
})); |
There is a new comment here: ratatui/ratatui#1005 (comment) |
hey @orhun, I implemented the function in that issue within our main.rsoutputThere's still problems with mouse(both in kitty/gnome terminal) as you can see from the output picture's last line. When you click left/right it returns ANSI characters(as I suppose). If you have suggestions, let me know. PS: I'm still new with TUIs, I can make some basic mistakes :) |
This looks good! 🚀 Can you send a PR? |
Yes, 5 dk'ya hazir :) |
@orhun first I created pr that's fully messed up lol, then opened new one with correction |
Is your feature request related to a problem? Please describe.
When an unexpected error happens, the terminal is messed up.
Describe the solution you'd like
Add a custom panic hook. See: ratatui/templates#13
Describe alternatives you've considered
None.
Additional context
The implementation might be the same as the linked pull request above.
The text was updated successfully, but these errors were encountered: