| 1 |
package ansi |
| 2 |
|
| 3 |
import ( |
| 4 |
"encoding/hex" |
| 5 |
"strings" |
| 6 |
) |
| 7 |
|
| 8 |
// XTGETTCAP (RequestTermcap) requests Termcap/Terminfo strings. |
| 9 |
// |
| 10 |
// DCS + q <Pt> ST |
| 11 |
// |
| 12 |
// Where <Pt> is a list of Termcap/Terminfo capabilities, encoded in 2-digit |
| 13 |
// hexadecimals, separated by semicolons. |
| 14 |
// |
| 15 |
// See: https://man7.org/linux/man-pages/man5/terminfo.5.html |
| 16 |
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands |
| 17 |
func XTGETTCAP(caps ...string) string { |
| 18 |
if len(caps) == 0 { |
| 19 |
return "" |
| 20 |
} |
| 21 |
|
| 22 |
s := "\x1bP+q" |
| 23 |
for i, c := range caps { |
| 24 |
if i > 0 { |
| 25 |
s += ";" |
| 26 |
} |
| 27 |
s += strings.ToUpper(hex.EncodeToString([]byte(c))) |
| 28 |
} |
| 29 |
|
| 30 |
return s + "\x1b\\" |
| 31 |
} |
| 32 |
|
| 33 |
// RequestTermcap is an alias for [XTGETTCAP]. |
| 34 |
func RequestTermcap(caps ...string) string { |
| 35 |
return XTGETTCAP(caps...) |
| 36 |
} |
| 37 |
|
| 38 |
// RequestTerminfo is an alias for [XTGETTCAP]. |
| 39 |
func RequestTerminfo(caps ...string) string { |
| 40 |
return XTGETTCAP(caps...) |
| 41 |
} |