Search code examples
cncursestty

"curs_set()" failed to return the previous cursor state


According to the curs_set man page:

The curs_set routine sets the cursor state to invisible, normal, or very visible for visibility equal to 0, 1, or 2 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?


Solution

  • As reminded by @vonaka in the comment, the man page also says (in a separate NOTES section):

    Both ncurses and SVr4 will call curs_set() in endwin() if curs_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.