From fad6126fb15a70396c34bad3b9604379cb78ce33 Mon Sep 17 00:00:00 2001 From: citrons Date: Mon, 2 Jun 2025 16:35:45 -0500 Subject: debugger --- client/debug_window.go | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 client/debug_window.go (limited to 'client/debug_window.go') 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) +} -- cgit v1.2.3