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

Untidy exit on std::terminate() #873

Open
JoshCollins746 opened this issue May 31, 2024 · 1 comment
Open

Untidy exit on std::terminate() #873

JoshCollins746 opened this issue May 31, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@JoshCollins746
Copy link

If the process exits by std::terminate() after calling ScreenInteractive::Install(), the terminal is left in an untidy state. Specifically it appears to be because ScreenInteractive::Uninstall() is not run. The obvious symptom that I am facing is that when the process exits in this way, mouse events (such as moving the mouse on the terminal) cause cause a bunch of escape sequences to appear. However, there may well be other cleanup steps that cause other issues I am overlooking. My workaround at the moment is to issue reset to restore the terminal state.

I was able to reproduce this issue on Ubuntu 22.04 using xterm (echo $TERM -> xterm-256color) by adding a call to std::terminate() directly after a Loop is constructed, for example line 45 at https://github.com/ArthurSonzogni/FTXUI/blob/7b1f4d435bedecc49abc3f935bd97dc997a41977/examples/component/custom_loop.cpp

I narrowed down the mouse specific issue to failure to Reset() (at least one of) DECMode::kMouseVt200, DECMode::kMouseAnyEvent, DECMode::kMouseUrxvtMode and DECMode::kMouseSgrExtMode, and was able to fix it by installing a terminate handler at the top of main() and manually issuing the missing cleanup:

std::set_terminate([] {
  std::cout << "\x1b["
                "?"
                "1000"
                ";"
                "1003"
                ";"
                "1015"
                ";"
                "1006"
                "l"
            << '\0' << std::flush;
});

I hope this helps to reproduce and understand the issue, and that nicely handling std::terminate() is something you would be interested in addressing.

@ArthurSonzogni
Copy link
Owner

Thanks for reporting it!

FTXUI does handle SIGSTP signal to cleanup when terminating the app. This is for event outside of the app.
Here, std::terminate is called from inside the app. It is not supported.

I guess we could add support for it too.

@ArthurSonzogni ArthurSonzogni self-assigned this Jun 2, 2024
@ArthurSonzogni ArthurSonzogni added the enhancement New feature or request label Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants