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
|
package main
import (
"citrons.xyz/talk/client/buffer"
"citrons.xyz/talk/tui"
"fmt"
)
type cmdBuffer struct {
buffer.Buffer
}
type logMsg struct {
index int
text string
logType logType
}
var lastIndex = 0
type logType int
const (
logInfo = iota
logErr
logCmd
)
func (m logMsg) Id() string {
return fmt.Sprintf("log.%d", m.index)
}
func (m logMsg) Show(odd bool) {
var style *tui.Style
switch m.logType {
case logErr:
var bg int32 = tui.Red
if odd {
bg = tui.BrightRed
}
style = &tui.Style {Bg: bg, Fg: tui.Black}
case logCmd:
var bg int32 = tui.Blue
if odd {
bg = tui.BrightBlue
}
style = &tui.Style {Bg: bg, Fg: tui.Black}
default:
}
tui.Push("", tui.Box {
Width: tui.Fill, Height: tui.Children, Style: style, Dir: tui.Right,
})
tui.Push("", tui.Box {Width: tui.TextSize, Height: tui.TextSize})
tui.Text("* ", nil)
tui.Pop()
tui.Push("", tui.Box {Width: tui.Fill, Height: tui.TextSize})
tui.Text(m.text, nil)
tui.Pop()
tui.Pop()
}
func (b *cmdBuffer) info(f string, a ...any) {
lastIndex++
b.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logInfo})
}
func (b *cmdBuffer) err(f string, a ...any) {
lastIndex++
b.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logErr})
}
func (b *cmdBuffer) cmd(f string, a ...any) {
lastIndex++
b.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logCmd})
}
|