vendor/github.com/charmbracelet/x/ansi/termcap.go
31 lines · 654 bytes
1package ansi
2
3import (
4 "encoding/hex"
5 "strings"
6)
7
8// RequestTermcap (XTGETTCAP) 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
17func RequestTermcap(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}