| 1 |
package ansi |
| 2 |
|
| 3 |
import ( |
| 4 |
"strconv" |
| 5 |
"strings" |
| 6 |
) |
| 7 |
|
| 8 |
const ( |
| 9 |
// ResizeWindowWinOp is a window operation that resizes the terminal |
| 10 |
// window. |
| 11 |
// |
| 12 |
// Deprecated: Use constant number directly with [WindowOp]. |
| 13 |
ResizeWindowWinOp = 4 |
| 14 |
|
| 15 |
// RequestWindowSizeWinOp is a window operation that requests a report of |
| 16 |
// the size of the terminal window in pixels. The response is in the form: |
| 17 |
// CSI 4 ; height ; width t |
| 18 |
// |
| 19 |
// Deprecated: Use constant number directly with [WindowOp]. |
| 20 |
RequestWindowSizeWinOp = 14 |
| 21 |
|
| 22 |
// RequestCellSizeWinOp is a window operation that requests a report of |
| 23 |
// the size of the terminal cell size in pixels. The response is in the form: |
| 24 |
// CSI 6 ; height ; width t |
| 25 |
// |
| 26 |
// Deprecated: Use constant number directly with [WindowOp]. |
| 27 |
RequestCellSizeWinOp = 16 |
| 28 |
) |
| 29 |
|
| 30 |
// WindowOp (XTWINOPS) is a sequence that manipulates the terminal window. |
| 31 |
// |
| 32 |
// CSI Ps ; Ps ; Ps t |
| 33 |
// |
| 34 |
// Ps is a semicolon-separated list of parameters. |
| 35 |
// 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 |
| 36 |
func WindowOp(p int, ps ...int) string { |
| 37 |
if p <= 0 { |
| 38 |
return "" |
| 39 |
} |
| 40 |
|
| 41 |
if len(ps) == 0 { |
| 42 |
return "\x1b[" + strconv.Itoa(p) + "t" |
| 43 |
} |
| 44 |
|
| 45 |
params := make([]string, 0, len(ps)+1) |
| 46 |
params = append(params, strconv.Itoa(p)) |
| 47 |
for _, p := range ps { |
| 48 |
if p >= 0 { |
| 49 |
params = append(params, strconv.Itoa(p)) |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
return "\x1b[" + strings.Join(params, ";") + "t" |
| 54 |
} |
| 55 |
|
| 56 |
// XTWINOPS is an alias for [WindowOp]. |
| 57 |
func XTWINOPS(p int, ps ...int) string { |
| 58 |
return WindowOp(p, ps...) |
| 59 |
} |