-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathansi_parser.go
More file actions
731 lines (694 loc) · 17.8 KB
/
Copy pathansi_parser.go
File metadata and controls
731 lines (694 loc) · 17.8 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
package main
import (
"encoding/base64"
"fmt"
"strconv"
"strings"
"unicode/utf8"
"github.com/unxed/vtui"
)
type ParserState int
var DefaultTermAttr = vtui.SetIndexBoth(0, 7, 0) // Light Gray on Black (standard ANSI indices)
const (
StateGround ParserState = iota
StateEsc
StateEscIntermediate
StateCSI
StateOSC
StateAPC
)
// AnsiParser converts a stream of bytes into ScreenBuf operations.
type AnsiParser struct {
State ParserState
Params []string
CurParam strings.Builder
Intermediate string
Attr uint64
term *TerminalView
pty PtyBackend
runeBuf []byte
lastRune rune
}
func NewAnsiParser(t *TerminalView, p PtyBackend) *AnsiParser {
return &AnsiParser{
term: t,
pty: p,
Attr: DefaultTermAttr,
}
}
func (p *AnsiParser) Process(data []byte) {
if p == nil || len(data) == 0 {
return
}
strData := string(data)
// Эвристика: скрываем эхо технических команд синхронизации (Linux far2l и Windows f4),
// чтобы они не мусорили в логе и на экране.
if strings.HasPrefix(strData, "set +H; cd ") {
// Unix: отрезаем префикс far2l
idx := strings.Index(strData, "}\r\n")
if idx != -1 {
strData = strData[idx+3:]
}
}
// Unix: Вырезаем фоновые команды синхронизации директории
if strings.HasPrefix(strData, "set +H; { printf") {
idx := strings.Index(strData, "}\r\n")
if idx != -1 {
strData = strData[idx+3:]
}
}
for {
startIdx := strings.Index(strData, " cd '")
if startIdx == -1 {
break
}
endIdx := strings.Index(strData[startIdx:], "' # f4_sync")
if endIdx != -1 {
actualEnd := startIdx + endIdx + len("' # f4_sync")
if actualEnd < len(strData) && strData[actualEnd] == '\r' {
actualEnd++
}
if actualEnd < len(strData) && strData[actualEnd] == '\n' {
actualEnd++
}
vtui.DebugLog("ANSI_PARSER: Excising background Unix CD sync")
strData = strData[:startIdx] + "\r\x1b[2K" + strData[actualEnd:]
continue
}
break
}
// Windows f4: Вырезаем техническую команду смены папки из любого места в буфере.
// Это скрывает cd даже если он пришел вместе с промптом shell (screen scraping).
for {
startIdx := strings.Index(strData, "cd /d \"")
if startIdx == -1 {
break
}
endIdx := strings.Index(strData[startIdx:], "\" & ")
if endIdx != -1 {
if strings.HasPrefix(strData[startIdx+endIdx:], "\" & rem f4_sync") {
actualEnd := startIdx + endIdx + len("\" & rem f4_sync")
if actualEnd < len(strData) && strData[actualEnd] == '\r' {
actualEnd++
}
if actualEnd < len(strData) && strData[actualEnd] == '\n' {
actualEnd++
}
if actualEnd < len(strData) && strData[actualEnd] == '\r' {
actualEnd++
}
if actualEnd < len(strData) && strData[actualEnd] == '\n' {
actualEnd++
}
vtui.DebugLog("ANSI_PARSER: Excising background Windows CD sync")
strData = strData[:startIdx] + "\r\x1b[2K" + strData[actualEnd:]
continue
} else {
actualEnd := startIdx + endIdx + 4 // +4 чтобы захватить и "\" & "
vtui.DebugLog("ANSI_PARSER: Excising technical Windows CD sync from buffer")
strData = strData[:startIdx] + strData[actualEnd:]
continue
}
}
break
}
data = []byte(strData)
if len(data) == 0 {
return
}
// vtui.DebugLog("ANSI_PARSER: Processing %d bytes: [% 02X] (as string: %q)", len(data), data, strData)
for _, b := range data {
// vtui.DebugLog("PARSER: Byte 0x%02X State %v", b, p.State)
switch p.State {
case StateGround:
if b == 0x1b {
p.State = StateEsc
p.runeBuf = p.runeBuf[:0]
} else if b < 0x80 {
r := rune(b)
p.term.PutChar(r, p.Attr)
p.lastRune = r
p.runeBuf = p.runeBuf[:0]
} else {
p.runeBuf = append(p.runeBuf, b)
if utf8.FullRune(p.runeBuf) {
r, _ := utf8.DecodeRune(p.runeBuf)
p.term.PutChar(r, p.Attr)
p.lastRune = r
p.runeBuf = p.runeBuf[:0]
} else if len(p.runeBuf) >= 4 {
// Invalid sequence or too long, flush as is
p.term.PutChar(rune(p.runeBuf[0]), p.Attr)
p.runeBuf = p.runeBuf[1:]
}
}
case StateEsc:
if b == '[' {
p.State = StateCSI
p.Params = nil
p.CurParam.Reset()
p.Intermediate = ""
} else if b == ']' {
p.State = StateOSC
p.Params = nil
p.CurParam.Reset()
} else if b == '_' {
p.CurParam.Reset()
p.State = StateAPC
} else if b == '\\' {
// String Terminator (ST)
p.State = StateGround
} else if b >= 0x20 && b <= 0x2F {
// Промежуточные байты (например, '(' в ESC ( B)
p.State = StateEscIntermediate
} else {
p.handleEsc(b)
p.State = StateGround
}
case StateEscIntermediate:
if b >= 0x20 && b <= 0x2F {
// Продолжаем собирать промежуточные байты
} else {
// b — финальный байт (0x30-0x7E), завершаем последовательность
p.State = StateGround
}
case StateCSI:
if b >= 0x30 && b <= 0x39 { // '0'-'9'
p.CurParam.WriteByte(b)
} else if b == ';' {
p.Params = append(p.Params, p.CurParam.String())
p.CurParam.Reset()
} else if b >= 0x3C && b <= 0x3F { // < = > ?
p.CurParam.WriteByte(b)
} else if b >= 0x20 && b <= 0x2F {
// Intermediate bytes
p.Intermediate += string(b)
} else if b >= 0x40 && b <= 0x7E {
p.Params = append(p.Params, p.CurParam.String())
p.handleCSI(b)
p.State = StateGround
}
case StateOSC:
if b == 0x07 { // BEL
p.handleOSC()
p.State = StateGround
} else if b == 0x1b { // ESC
p.handleOSC()
p.State = StateEsc
} else {
p.CurParam.WriteByte(b)
}
case StateAPC:
if b == 0x07 { // BEL
p.handleAPC()
p.State = StateGround
} else if b == 0x1b { // ESC
p.handleAPC()
p.State = StateEsc
} else {
p.CurParam.WriteByte(b)
}
}
}
p.term.FlushLog()
}
func (p *AnsiParser) handleEsc(cmd byte) {
// vtui.DebugLog("ANSI_PARSER: ESC %c", cmd)
switch cmd {
case '7':
p.term.SaveCursor()
case '8':
p.term.RestoreCursor()
case 'M': // Reverse Index
p.term.ReverseIndex()
case 'D': // Index
p.term.Index()
case 'E': // Next Line
p.term.NextLine()
case 'c': // RIS - Reset to Initial State
p.term.ResetBuffer(p.term.Width, p.term.Height)
case '=', '>':
// Application/Numeric Keypad Mode - пока просто поглощаем
}
}
func (p *AnsiParser) handleCSI(cmd byte) {
// vtui.DebugLog("ANSI_PARSER: CSI %s %c (args: %v, intermediate: %q)", p.CurParam.String(), cmd, p.Params, p.Intermediate)
args := make([]int, len(p.Params))
// If there are no arguments, args will be an empty slice.
// This is important for correct handling of default commands.
for i, s := range p.Params {
s = strings.TrimLeft(s, "?<=>")
val, _ := strconv.Atoi(s)
args[i] = val
}
switch cmd {
case 'm':
if len(args) == 0 {
p.handleSGR(args, 0) // Default reset
} else {
for i := 0; i < len(args); {
consumed := p.handleSGR(args, i)
i += consumed
}
}
case 'H', 'f':
row, col := 1, 1
if len(args) > 0 && args[0] != 0 {
row = args[0]
}
if len(args) > 1 && args[1] != 0 {
col = args[1]
}
p.term.SetCursor(col-1, row-1)
case 'J':
mode := 0
if len(args) > 0 {
mode = args[0]
}
p.term.EraseDisplay(mode, p.Attr)
case 'K':
mode := 0
if len(args) > 0 {
mode = args[0]
}
p.term.EraseLine(mode, p.Attr)
case 'r': // DECSTBM - Set Top and Bottom Margins
top, bottom := 1, p.term.Height
if len(args) > 0 && args[0] != 0 {
top = args[0]
}
if len(args) > 1 && args[1] != 0 {
bottom = args[1]
}
p.term.ScrollTop = top - 1
p.term.ScrollBottom = bottom - 1
p.term.SetCursor(0, 0)
case 'c':
if p.pty != nil {
p.pty.Write([]byte("\x1b[?1;2c"))
}
case 't':
if len(args) > 0 && p.pty != nil {
if args[0] == 18 {
resp := fmt.Sprintf("\x1b[8;%d;%dt", p.term.Height, p.term.Width)
p.pty.Write([]byte(resp))
} else if args[0] == 14 {
resp := fmt.Sprintf("\x1b[4;%d;%dt", p.term.Height*16, p.term.Width*8)
p.pty.Write([]byte(resp))
} else if args[0] == 16 {
resp := fmt.Sprintf("\x1b[6;16;8t")
p.pty.Write([]byte(resp))
}
}
case 'h', 'l': // DECSET / DECRST
isSet := cmd == 'h'
for _, s := range p.Params {
s = strings.TrimLeft(s, "?")
switch s {
case "1":
p.term.ApplicationCursorKeys = isSet
case "1049", "47":
p.term.SetAltScreen(isSet)
if isSet {
p.term.EraseDisplay(2, p.Attr)
}
case "9001":
p.term.Win32InputMode = isSet
case "2004":
p.term.BracketedPasteMode = isSet
}
}
case 'L': // Insert blank lines
n := 1
if len(args) > 0 && args[0] != 0 {
n = args[0]
}
p.term.ScrollDown(p.term.CursorY, p.term.ScrollBottom, n)
case 'M': // Delete lines
n := 1
if len(args) > 0 && args[0] != 0 {
n = args[0]
}
p.term.scrollUp(p.term.CursorY, p.term.ScrollBottom, n)
case 'P': // Delete characters
n := 1
if len(args) > 0 && args[0] != 0 {
n = args[0]
}
p.term.DeleteCharacters(n, p.Attr)
case '@': // Insert blank characters
n := 1
if len(args) > 0 && args[0] != 0 {
n = args[0]
}
p.term.InsertBlankCharacters(n, p.Attr)
case 'S': // Scroll up (text moves up)
n := 1
if len(args) > 0 && args[0] != 0 {
n = args[0]
}
p.term.scrollUp(p.term.ScrollTop, p.term.ScrollBottom, n)
case 'T': // Scroll down (text moves down)
n := 1
if len(args) > 0 && args[0] != 0 {
n = args[0]
}
p.term.ScrollDown(p.term.ScrollTop, p.term.ScrollBottom, n)
case 'A':
n := 1
if len(args) > 0 && args[0] != 0 {
n = args[0]
}
p.term.SetCursor(p.term.CursorX, p.term.CursorY-n)
case 'B':
n := 1
if len(args) > 0 && args[0] != 0 {
n = args[0]
}
p.term.SetCursor(p.term.CursorX, p.term.CursorY+n)
case 'C':
n := 1
if len(args) > 0 && args[0] != 0 {
n = args[0]
}
p.term.SetCursor(p.term.CursorX+n, p.term.CursorY)
case 'D':
n := 1
if len(args) > 0 && args[0] != 0 {
n = args[0]
}
p.term.SetCursor(p.term.CursorX-n, p.term.CursorY)
case 'G', '`':
col := 1
if len(args) > 0 && args[0] != 0 {
col = args[0]
}
p.term.SetCursor(col-1, p.term.CursorY)
case 'd':
row := 1
if len(args) > 0 && args[0] != 0 {
row = args[0]
}
p.term.SetCursor(p.term.CursorX, row-1)
case 'n': // DSR - Device Status Report
if len(args) > 0 {
if args[0] == 5 {
if p.pty != nil {
p.pty.Write([]byte("\x1b[0n"))
}
} else if args[0] == 6 {
if p.pty != nil {
resp := fmt.Sprintf("\x1b[%d;%dR", p.term.CursorY+1, p.term.CursorX+1)
p.pty.Write([]byte(resp))
}
}
}
case 's':
if len(p.Params) == 0 || (len(p.Params) == 1 && p.Params[0] == "") {
p.term.SaveCursor()
}
case 'u':
s0 := ""
if len(p.Params) > 0 {
s0 = p.Params[0]
}
if s0 == "" {
p.term.RestoreCursor()
} else if strings.HasPrefix(s0, "=") {
flags, _ := strconv.Atoi(s0[1:])
mode := 1
if len(p.Params) > 1 {
mode, _ = strconv.Atoi(p.Params[1])
}
if mode == 1 {
p.term.KittyFlags = flags
} else if mode == 2 {
p.term.KittyFlags |= flags
} else if mode == 3 {
p.term.KittyFlags &= ^flags
}
} else if strings.HasPrefix(s0, ">") {
flags, _ := strconv.Atoi(s0[1:])
if len(p.term.KittyFlagsStack) >= 32 {
p.term.KittyFlagsStack = p.term.KittyFlagsStack[1:] // Limit stack size
}
p.term.KittyFlagsStack = append(p.term.KittyFlagsStack, p.term.KittyFlags)
p.term.KittyFlags = flags
} else if strings.HasPrefix(s0, "<") {
count, _ := strconv.Atoi(s0[1:])
if count <= 0 {
count = 1
}
for i := 0; i < count; i++ {
if len(p.term.KittyFlagsStack) == 0 {
p.term.KittyFlags = 0
break
}
last := len(p.term.KittyFlagsStack) - 1
p.term.KittyFlags = p.term.KittyFlagsStack[last]
p.term.KittyFlagsStack = p.term.KittyFlagsStack[:last]
}
} else if strings.HasPrefix(s0, "?") {
if p.pty != nil {
resp := fmt.Sprintf("\x1b[?%du", p.term.KittyFlags)
p.pty.Write([]byte(resp))
}
} else {
p.term.RestoreCursor()
}
case 'b': // REP - Repeat last character
n := 1
if len(args) > 0 && args[0] != 0 {
n = args[0]
}
p.term.RepeatLastChar(n, p.lastRune, p.Attr)
case 'X': // ECH - Erase Character
n := 1
if len(args) > 0 && args[0] != 0 {
n = args[0]
}
p.term.EraseCharacter(n, p.Attr)
case 'p': // DECRQM
if p.Intermediate == "$" {
p.handleDECRQM(args)
}
}
}
func (p *AnsiParser) handleDECRQM(args []int) {
if len(p.Params) == 0 || p.pty == nil {
return
}
// Ensure there is an actual mode number provided (not just an empty param or prefix)
modeStr := strings.TrimLeft(p.Params[0], "?<=>")
if modeStr == "" {
return
}
mode := args[0]
isDecPrivate := len(p.Params) > 0 && strings.HasPrefix(p.Params[0], "?")
state := 0 // 0 = not recognized
if isDecPrivate {
switch mode {
case 1:
if p.term.ApplicationCursorKeys {
state = 1
} else {
state = 2
}
case 47, 1049:
if p.term.UseAltScreen {
state = 1
} else {
state = 2
}
case 2004:
if p.term.BracketedPasteMode {
state = 1
} else {
state = 2
}
case 9001:
if p.term.Win32InputMode {
state = 1
} else {
state = 2
}
}
resp := fmt.Sprintf("\x1b[?%d;%d$y", mode, state)
p.pty.Write([]byte(resp))
} else {
resp := fmt.Sprintf("\x1b[%d;%d$y", mode, state)
p.pty.Write([]byte(resp))
}
}
func (p *AnsiParser) handleOSC() {
s := p.CurParam.String()
// vtui.DebugLog("ANSI_PARSER: OSC payload: %q", s)
p.CurParam.Reset()
if s == "" {
return
}
parts := strings.SplitN(s, ";", 2)
if len(parts) < 2 {
return
}
cmd, err := strconv.Atoi(parts[0])
if err != nil {
return
}
if cmd == 0 || cmd == 2 {
vtui.DebugLog("ANSI_OSC_TRACE: Received window title change: %q", parts[1])
p.term.Title = parts[1]
if p.term.OnTitleChange != nil {
p.term.OnTitleChange(p.term.Title)
}
return
}
if cmd == 133 {
// В последовательности OSC 133;C BEL, cmd это 133, а аргумент 'C' находится в parts[1]
if len(parts) > 1 {
p.term.HandleOSC133(parts[1])
}
return
}
if cmd == 52 {
subparts := strings.SplitN(parts[1], ";", 2)
if len(subparts) == 2 {
if subparts[1] == "?" {
if p.pty != nil {
go func(subCmd string) {
allowed := false
if vtui.GlobalClipboardAccessManager != nil {
auth := vtui.GlobalClipboardAccessManager.Authorize("Terminal_OSC52_Read")
if auth == 1 || auth == 2 {
allowed = true
}
}
if allowed {
clip := vtui.GetClipboard()
b64 := base64.StdEncoding.EncodeToString([]byte(clip))
p.pty.Write([]byte(fmt.Sprintf("\x1b]52;%s;%s\x07", subCmd, b64)))
}
}(subparts[0])
}
} else {
decoded, err := base64.StdEncoding.DecodeString(subparts[1])
if err == nil {
vtui.SetClipboard(string(decoded))
}
}
}
return
}
if cmd == 4 {
subparts := strings.SplitN(parts[1], ";", 2)
if len(subparts) < 2 {
return
}
idx, _ := strconv.Atoi(subparts[0])
if idx < 0 || idx >= 256 {
return
}
colorStr := subparts[1]
var rgbVal uint32
parsed := false
if strings.HasPrefix(colorStr, "#") && len(colorStr) >= 7 {
v, err := strconv.ParseUint(colorStr[1:7], 16, 32)
if err == nil {
rgbVal = uint32(v)
parsed = true
}
} else if strings.HasPrefix(colorStr, "rgb:") {
// format rgb:RR/GG/BB
rgbParts := strings.Split(colorStr[4:], "/")
if len(rgbParts) == 3 {
r, _ := strconv.ParseUint(rgbParts[0], 16, 8)
g, _ := strconv.ParseUint(rgbParts[1], 16, 8)
b, _ := strconv.ParseUint(rgbParts[2], 16, 8)
rgbVal = uint32((r << 16) | (g << 8) | b)
parsed = true
}
}
if parsed {
p.term.Palette[idx] = rgbVal
}
}
}
func (p *AnsiParser) handleAPC() {
s := p.CurParam.String()
p.CurParam.Reset()
if strings.HasPrefix(s, "far2l") {
p.term.HandleFar2lAPC(s)
}
}
func (p *AnsiParser) handleSGR(args []int, i int) int {
if len(args) == 0 {
p.Attr = DefaultTermAttr
return 1
}
n := args[i]
switch {
case n == 0:
p.Attr = DefaultTermAttr
case n == 1:
p.Attr |= vtui.ForegroundIntensity
case n == 2:
p.Attr |= vtui.ForegroundDim
case n == 4:
p.Attr |= vtui.CommonLvbUnderscore
case n == 5:
// Blink - ignored in many TUIs or mapped to intensity
case n == 7:
p.Attr |= vtui.CommonLvbReverse
case n == 9:
p.Attr |= vtui.CommonLvbStrikeout
case n == 22:
p.Attr &= ^(vtui.ForegroundIntensity | vtui.ForegroundDim)
case n == 24:
p.Attr &= ^vtui.CommonLvbUnderscore
case n == 27:
p.Attr &= ^vtui.CommonLvbReverse
case n == 29:
p.Attr &= ^vtui.CommonLvbStrikeout
case n >= 30 && n <= 37:
p.Attr = vtui.SetIndexFore(p.Attr, uint8(n-30))
case n == 38:
if i+2 < len(args) {
if args[i+1] == 5 { // 256 colors
idx := args[i+2]
if idx >= 0 && idx < 256 {
p.Attr = vtui.SetIndexFore(p.Attr, uint8(idx))
}
return 3
} else if args[i+1] == 2 && i+4 < len(args) { // TrueColor
r, g, b := uint32(args[i+2]), uint32(args[i+3]), uint32(args[i+4])
p.Attr = vtui.SetRGBFore(p.Attr, (r<<16)|(g<<8)|b)
return 5
}
}
case n == 39:
p.Attr = vtui.SetIndexFore(p.Attr, vtui.GetIndexFore(DefaultTermAttr))
case n >= 40 && n <= 47:
p.Attr = vtui.SetIndexBack(p.Attr, uint8(n-40))
case n == 48:
if i+2 < len(args) {
if args[i+1] == 5 { // 256 colors
idx := args[i+2]
if idx >= 0 && idx < 256 {
p.Attr = vtui.SetIndexBack(p.Attr, uint8(idx))
}
return 3
} else if args[i+1] == 2 && i+4 < len(args) { // TrueColor
r, g, b := uint32(args[i+2]), uint32(args[i+3]), uint32(args[i+4])
p.Attr = vtui.SetRGBBack(p.Attr, (r<<16)|(g<<8)|b)
return 5
}
}
case n == 49:
p.Attr = vtui.SetIndexBack(p.Attr, vtui.GetIndexBack(DefaultTermAttr))
case n >= 90 && n <= 97:
p.Attr = vtui.SetIndexFore(p.Attr, uint8(n-90+8))
case n >= 100 && n <= 107:
p.Attr = vtui.SetIndexBack(p.Attr, uint8(n-100+8))
}
return 1
}