how to get current terminal color pair in bash

后端 未结 3 2199
长情又很酷
长情又很酷 2021-02-05 15:25

I would like to query and store the current terminal color pair in BASH e.g.:

#!/bin/bash

#some ANSI colour escape sequences
red=\"\\033[0;31m\"
grn=\"\\033[0;3         


        
3条回答
  •  星月不相逢
    2021-02-05 15:54

    The question was about the current color, not the cursor position.

    Both are "nonstandard" (though the latter, cursor position report is implemented by anything which has a valid claim to "VT100 emulator").

    However, xterm implements a set of escape sequences referred to as dynamic colors, which predate the ANSI color functionality. Those set the working colors including text foreground and background. I modified this in 2002 to allow an application to send the sequence with a "?" rather than a color to tell xterm to return the color value, e.g.,

    OSC 1 1 ? ST
    

    using the notation given in XTerm Control Sequences

提交回复
热议问题