'(Python/rich) restore cursor default values on exit

I have a Python3.9+ project that runs on the command line on both Linux and Windows. I use rich to interact with the console. Out of curiosity I would like to know if it is possible to save the characteristics of the console cursor at the beginning of the program (at least, is the cursor visible ?) and to modify the console cursor according to these characteristics (at the end of the program).

I found nothing in the documentation.



Solution 1:[1]

In my case, I also used rich with python (3.8) and when my program exited, the terminal cursor was invisible. only reset will bring it back. I ended up registering an "atexit" hook that prints terminal control code that restore the terminal cursor.

atexit.register(lambda: print("\x1b[?25h"))  

This worked for me, Though I wish rich will have an option to restore the terminal settings on exit.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bennyl