File: winop.go

package info (click to toggle)
golang-github-charmbracelet-x 0.0~git20251028.0cf22f8%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,940 kB
  • sloc: sh: 124; makefile: 5
file content (59 lines) | stat: -rw-r--r-- 1,561 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package ansi

import (
	"strconv"
	"strings"
)

const (
	// ResizeWindowWinOp is a window operation that resizes the terminal
	// window.
	//
	// Deprecated: Use constant number directly with [WindowOp].
	ResizeWindowWinOp = 4

	// RequestWindowSizeWinOp is a window operation that requests a report of
	// the size of the terminal window in pixels. The response is in the form:
	//  CSI 4 ; height ; width t
	//
	// Deprecated: Use constant number directly with [WindowOp].
	RequestWindowSizeWinOp = 14

	// RequestCellSizeWinOp is a window operation that requests a report of
	// the size of the terminal cell size in pixels. The response is in the form:
	//  CSI 6 ; height ; width t
	//
	// Deprecated: Use constant number directly with [WindowOp].
	RequestCellSizeWinOp = 16
)

// WindowOp (XTWINOPS) is a sequence that manipulates the terminal window.
//
//	CSI Ps ; Ps ; Ps t
//
// Ps is a semicolon-separated list of parameters.
// 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
func WindowOp(p int, ps ...int) string {
	if p <= 0 {
		return ""
	}

	if len(ps) == 0 {
		return "\x1b[" + strconv.Itoa(p) + "t"
	}

	params := make([]string, 0, len(ps)+1)
	params = append(params, strconv.Itoa(p))
	for _, p := range ps {
		if p >= 0 {
			params = append(params, strconv.Itoa(p))
		}
	}

	return "\x1b[" + strings.Join(params, ";") + "t"
}

// XTWINOPS is an alias for [WindowOp].
func XTWINOPS(p int, ps ...int) string {
	return WindowOp(p, ps...)
}