1

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.

suizokukan
  • 1,303
  • 4
  • 18
  • 33

1 Answers1

3

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.

bennyl
  • 2,886
  • 2
  • 29
  • 43