bashterminalttyterminfotput

Obtain cursor color in terminal


Is there any way to determine what the color of the cursor is in a terminal running something like vim? I know that you can use tput cols and tput rows to determine the height and width of the terminal, are there similar tools for cursor color/obtaining the ansi standard foreground/background color of any character location in the current terminal?


Solution

  • The answer to your question is "No, there is no standard way to do that."

    Consider that your terminal is modelled after ancient text terminals (like DEC VT100 and the like) which communicated with a server over a serial port or modem. And those terminals were in turn modelled after TeleTYpe (tty) devices which were connected to computers back in the 1960s.

    Teletype machines ("dumb" terminals) provided no data back to the server that was not typed in to the keyboard. Devices like the VT100 ("smart" terminals) provided VERY LITTLE back to the server, but the list of what's available hasn't changed in many years.

    Other resources:

    Note that not all terminals are VT100/VT220, and your system may have locak extensions that provide what you need in a non-standard way.

    For extra reading, have a look at man termcap and man terminfo. Check out the references in the "SEE ALSO" section of those pages.