ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.73k stars 401 forks source link

Cursor state (blinking, block, underline, ...) is not reset after exiting a program #792

Closed psychon closed 9 months ago

psychon commented 9 months ago

Hi,

running the examples/component/focus_cursor.cpp example and exiting with ctrl+c leaves the cursor in the terminal in the state that I last picked. If I understand correctly, exiting by ctrl+c is actually caught and is supposed to reset the terminal to its original state, but I might be wrong here.

In xterm, running reset "fixes" this, but in urxvt the cursor state even survives a reset.

ArthurSonzogni commented 9 months ago

Thanks!

It looks like something specific to this terminal.

This was initially implemented here: https://github.com/ArthurSonzogni/FTXUI/pull/505/files#diff-8b8c62b9f0fa9b20149ff00446386cc2ec079a0afc1c2e2828be4436df563cb6

I guess I meant to restore the cursor using:

  on_exit_functions.push([=] {
    std::cout << "\033[?25h";  // Enable cursor.
    std::cout << "\033[?1 q";  // Cursor block blinking.
  });

But this was only the "Cursor block blinking" one.

We would need a way to get the terminal to report the current cursor before modifyfing it.

psychon commented 9 months ago

I can confirm that for urxvt, the cursor no longer ends up as an underline, but is a block again after exiting a program. However, it started blinking after exiting the print_key_press example, which it did not do before. I can live with that (and terminals are complicated...).