-
Notifications
You must be signed in to change notification settings - Fork 7
/
color.go
56 lines (50 loc) · 940 Bytes
/
color.go
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
package main
import (
"bytes"
"github.com/charmbracelet/x/ansi"
)
//nolint:mnd
func handleTerminalColor(p *ansi.Parser) (string, error) {
parts := bytes.Split(p.Data(), []byte{';'})
if len(parts) != 2 {
// Invalid, ignore
return "", errInvalid
}
arg := string(parts[1])
var buf string
if arg == "?" {
buf += "Request"
} else {
buf += "Set"
}
switch p.Cmd() {
case 10:
buf += " foreground color"
case 11:
buf += " background color"
case 12:
buf += " cursor color"
}
if arg == "?" {
buf += " to " + arg
}
return buf, nil
}
//nolint:mnd
func handleResetTerminalColor(p *ansi.Parser) (string, error) {
parts := bytes.Split(p.Data(), []byte{';'})
if len(parts) != 1 {
// Invalid, ignore
return "", errInvalid
}
var buf string
switch p.Cmd() {
case 110:
buf += "Reset foreground color"
case 111:
buf += "Reset background color"
case 112:
buf += "Reset cursor color"
}
return buf, nil
}