I am wanting to write a function to ask the user input using Python curses. The problem I am having is I want to have the cursor hidden in other parts of the program except in the text-box. I intend to use this function in many cases and if the cursor is hidden before the function call, it should be returned to that state and vise versa. To do this I need to be able to read the state of the cursor. How do I do this? (Something like this?)
if curses.get_cursor_state() == 0:
#Hidden
hidden=True
else:
hidden=False
#Textbox code here
if hidden:
curs_set(0)
else:
curs_set(1)
The only way I'm aware of to check the cursor visibility state is to first set the visibility state:
When you call
curses.curs_set, if it works, it returns the previous cursor state. There doesn't seem to be any other way to check it. Fortunately, it sounds like you want to have the cursor visible during this section anyway, so you can doto temporarily ensure the cursor is visible, and restore the old state afterward.