According to the curs_set
man page:
The
curs_set
routine sets the cursor state to invisible, normal, or very visible forvisibility
equal to0
,1
, or2
respectively. If the terminal supports the visibility requested, the previous cursor state is returned; otherwise,ERR
is returned.
But the following simple program did not return the previous state:
[STEP 107] # cat curs_set.c
#include <stdio.h>
#include <curses.h>
int main()
{
int ret;
initscr();
ret = curs_set(1);
endwin();
printf("curs_set() returned %d\n", ret);
return 0;
}
[STEP 108] # gcc curs_set.c -lncurses
[STEP 109] # setterm -cursor off
[STEP 110] # ./a.out <-- cursor invisible
curs_set() returned 1 <-- why not 0?
[STEP 111] # tput civis <-- cursor visible
[STEP 112] # ./a.out <-- cursor invisible
curs_set() returned 1 <-- why not 0?
[STEP 113] # <-- cursor visible
Did I miss something?
As reminded by @vonaka in the comment, the man page also says (in a separate NOTES section):
Both
ncurses
andSVr4
will callcurs_set()
inendwin()
ifcurs_set()
has been called to make the cursor other than normal, i.e., either invisible or very visible. There is no way for ncurses to determine the initial cursor state to restore that.