-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstyle.go
More file actions
155 lines (139 loc) · 2.71 KB
/
Copy pathstyle.go
File metadata and controls
155 lines (139 loc) · 2.71 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package tui
import (
"strconv"
"strings"
"github.com/romanSPB15/tui-compose/v3/cell"
)
// Style — битовая маска стиля виджета.
type Style uint16
// Цвета (0–16)
const (
FrDefault = iota
FrBlack
FrRed
FrGreen
FrYellow
FrBlue
FrMagenta
FrCyan
FrWhite
FrBrightBlack
FrBrightRed
FrBrightGreen
FrBrightYellow
FrBrightBlue
FrBrightMagenta
FrBrightCyan
FrBrightWhite
)
// Атрибуты
const (
Bold Style = 1 << 10
Italic Style = 1 << 11
Underline Style = 1 << 12
Blink Style = 1 << 13
Reverse Style = 1 << 14
Reset Style = 1 << 15
)
const (
BgDefault Style = FrDefault << 5
BgBlack Style = FrBlack << 5
BgRed Style = FrRed << 5
BgGreen Style = FrGreen << 5
BgYellow Style = FrYellow << 5
BgBlue Style = FrBlue << 5
BgMagenta Style = FrMagenta << 5
BgCyan Style = FrCyan << 5
BgWhite Style = FrWhite << 5
BgBrightBlack Style = FrBrightBlack << 5
BgBrightRed Style = FrBrightRed << 5
BgBrightGreen Style = FrBrightGreen << 5
BgBrightYellow Style = FrBrightYellow << 5
BgBrightBlue Style = FrBrightBlue << 5
BgBrightMagenta Style = FrBrightMagenta << 5
BgBrightCyan Style = FrBrightCyan << 5
BgBrightWhite Style = FrBrightWhite << 5
)
func (s Style) String() string {
if s == 0 {
return ""
}
var codes []int
fg := int(s & 0x1F)
if fg != 0 {
if fg <= 8 {
codes = append(codes, fg+29)
} else {
codes = append(codes, fg+81)
}
}
bg := int((s >> 5) & 0x1F)
if bg != 0 {
if bg <= 8 {
codes = append(codes, bg+39)
} else {
codes = append(codes, bg+91)
}
}
if s&Bold != 0 {
codes = append(codes, 1)
}
if s&Italic != 0 {
codes = append(codes, 3)
}
if s&Underline != 0 {
codes = append(codes, 4)
}
if s&Blink != 0 {
codes = append(codes, 5)
}
if s&Reverse != 0 {
codes = append(codes, 7)
}
if s&Reset != 0 {
codes = []int{0}
}
codesString := []string{}
for _, v := range codes {
codesString = append(codesString, strconv.Itoa(v))
}
return "\x1b[" + strings.Join(codesString, ";") + "m"
}
func ConvertToCellStyle(s Style) cell.Style {
var cs cell.Style
fg := int(s & 0x1F)
if fg != 0 {
if fg <= 8 {
cs.Fg = strconv.Itoa(fg + 29)
} else {
cs.Fg = strconv.Itoa(fg + 81)
}
}
bg := int((s >> 5) & 0x1F)
if bg != 0 {
if bg <= 8 {
cs.Bg = strconv.Itoa(bg + 39)
} else {
cs.Bg = strconv.Itoa(bg + 91)
}
}
if s&Bold != 0 {
cs.Args |= cell.Bold
}
if s&Italic != 0 {
cs.Args |= cell.Italic
}
if s&Underline != 0 {
cs.Args |= cell.Underline
}
if s&Blink != 0 {
cs.Args |= cell.Blink
}
if s&Reverse != 0 {
cs.Args |= cell.Reverse
}
if s&Reset != 0 {
cs.Args |= cell.Reset
}
return cs
}