winop.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package ansi
  2. import (
  3. "strconv"
  4. "strings"
  5. )
  6. const (
  7. // ResizeWindowWinOp is a window operation that resizes the terminal
  8. // window.
  9. ResizeWindowWinOp = 4
  10. // RequestWindowSizeWinOp is a window operation that requests a report of
  11. // the size of the terminal window in pixels. The response is in the form:
  12. // CSI 4 ; height ; width t
  13. RequestWindowSizeWinOp = 14
  14. // RequestCellSizeWinOp is a window operation that requests a report of
  15. // the size of the terminal cell size in pixels. The response is in the form:
  16. // CSI 6 ; height ; width t
  17. RequestCellSizeWinOp = 16
  18. )
  19. // WindowOp (XTWINOPS) is a sequence that manipulates the terminal window.
  20. //
  21. // CSI Ps ; Ps ; Ps t
  22. //
  23. // Ps is a semicolon-separated list of parameters.
  24. // See https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps;Ps;Ps-t.1EB0
  25. func WindowOp(p int, ps ...int) string {
  26. if p <= 0 {
  27. return ""
  28. }
  29. if len(ps) == 0 {
  30. return "\x1b[" + strconv.Itoa(p) + "t"
  31. }
  32. params := make([]string, 0, len(ps)+1)
  33. params = append(params, strconv.Itoa(p))
  34. for _, p := range ps {
  35. if p >= 0 {
  36. params = append(params, strconv.Itoa(p))
  37. }
  38. }
  39. return "\x1b[" + strings.Join(params, ";") + "t"
  40. }
  41. // XTWINOPS is an alias for [WindowOp].
  42. func XTWINOPS(p int, ps ...int) string {
  43. return WindowOp(p, ps...)
  44. }