termcap.go 654 B

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