I am writing application on C++ that can change cursor state via ANSI sequences. I want to restore cursor visibility state after application is done.
You can easily achieve this in Windows:
#include <windows.h>
bool IsCursorVisible() {
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(out, &cursorInfo);
return cursorInfo.bVisible;
}
But with Linux situation becomes different. How can I achieve the same functionality on Linux or is there any cross-platform non-lib solution?
Some terminals (i.e., xterm and those which copy the feature from xterm) provide an extension to
DECRQMwhich gives the state fromDECTCEM.That has been a feature of xterm since 2010:
For other terminals, consult their documentation.