summaryrefslogtreecommitdiff
path: root/client/debug_window.go
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2025-06-02 16:35:45 -0500
committercitrons <citrons@mondecitronne.com>2025-06-02 16:37:32 -0500
commitfad6126fb15a70396c34bad3b9604379cb78ce33 (patch)
treecc14970a1706c2f1ac11fef5b692e4def72f6b25 /client/debug_window.go
parent54ff79635d52588602c401abbe86e6927c5a18b5 (diff)
debugger
Diffstat (limited to 'client/debug_window.go')
-rw-r--r--client/debug_window.go82
1 files changed, 82 insertions, 0 deletions
diff --git a/client/debug_window.go b/client/debug_window.go
new file mode 100644
index 0000000..c45198d
--- /dev/null
+++ b/client/debug_window.go
@@ -0,0 +1,82 @@
+package main
+
+import (
+ "citrons.xyz/talk/client/window"
+ "citrons.xyz/talk/tui"
+ "citrons.xyz/talk/proto"
+ "strings"
+ "fmt"
+ "bufio"
+)
+
+type debugWindow struct {
+ window.DefaultWindow
+ sendChan chan<- proto.Line
+}
+
+type debugWindowLocation struct{}
+
+func (l debugWindowLocation) CreateWindow() window.Window {
+ var dw debugWindow
+ globalApp.Debug(&dw)
+ return &dw
+}
+
+type debugLine struct {
+ index int
+ client bool
+ line string
+}
+
+func (l debugLine) Id() string {
+ return fmt.Sprintf("debug.%d", l.index)
+}
+
+func (l debugLine) Show(odd bool) {
+ tui.Push("", tui.Box {
+ Width: tui.Fill, Height: tui.Children, Dir: tui.Right,
+ })
+
+ tui.Push("", tui.Box {
+ Width: tui.TextSize, Height: tui.TextSize, Dir: tui.Right,
+ Style: &tui.Style {Fg: tui.BrightBlack, Bg: colorDefault[odd]},
+ })
+ if l.client {
+ tui.Text("client: ", nil)
+ } else {
+ tui.Text("server: ", nil)
+ }
+ tui.Pop()
+
+ tui.Push("", tui.Box {Width: tui.TextSize, Height: tui.TextSize})
+ tui.Text(l.line, nil)
+ tui.Pop()
+
+ tui.Pop()
+}
+
+func (dw *debugWindow) SetSendChan(send chan<- proto.Line) {
+ dw.sendChan = send
+}
+
+func (dw *debugWindow) OnLine(line proto.Line, client bool) {
+ var sb strings.Builder
+ proto.WriteLine(bufio.NewWriter(&sb), line)
+ lastIndex++
+ dw.Buf.Add(debugLine {lastIndex, client, strings.TrimSpace(sb.String())})
+}
+
+func (dw *debugWindow) Send(text string) {
+ line, err := proto.ReadLine(bufio.NewReader(strings.NewReader(text + "\n")))
+ if err != nil {
+ globalApp.cmdWindow.err("that is not a valid protocol line!")
+ } else {
+ dw.sendChan <- line
+ lastIndex++
+ }
+ dw.In.SetText("")
+}
+
+func (dw *debugWindow) Kill() {
+ globalApp.Debug(nil)
+}