diff options
| author | citrons <citrons@mondecitronne.com> | 2025-05-30 17:47:35 -0500 |
|---|---|---|
| committer | citrons <citrons@mondecitronne.com> | 2025-05-30 17:47:35 -0500 |
| commit | b3a01b28cbfe43ef22168a2f81803dccd4e56864 (patch) | |
| tree | 042a79f70fe1b6f08bc3ba6b0ea2dde127b1a1be /client/cmd_buffer.go | |
| parent | 194c63381a8b19f6a9198ff30a307b65acc2af76 (diff) | |
simple client
Diffstat (limited to 'client/cmd_buffer.go')
| -rw-r--r-- | client/cmd_buffer.go | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/client/cmd_buffer.go b/client/cmd_buffer.go new file mode 100644 index 0000000..ae96a0f --- /dev/null +++ b/client/cmd_buffer.go @@ -0,0 +1,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}) +} |
