Googled a lot and found curs_set()
or putp(tigetstr() )
can be used to hide/show the tty cursor. I'd like to minimize the dependency on other libs so I'm wondering if I can do this without using libtinfo
/libncurses
or calling external commands (like setterm
, tput
). Is there any ioctl()
command for this?
There are basically three approaches:
If your program is executed only on the console terminal (for example, because the machine is not network-connected), or by most common terminals only, you can assume UTF-8 character set and ANSI escape codes.
This means that to hide the cursor, you print "\033[?25l"
to the terminal, and "\033[?25h"
to show the cursor.
For proper terminal support, you use the terminfo library.
You could read the terminfo database directly, but that would be pretty pointless, because if it is installed, you also have the curses functions used to access it (tgetent()
/tgetnum()
/tgetflag()
).
You should then also have your program be locale-aware, and use e.g. iconv()
to convert between character sets, rather than assume UTF-8.
Use curses or ncursesw (with wide character support).