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.OnLine(line, true) dw.sendChan <- line lastIndex++ } dw.In.SetText("") } func (dw *debugWindow) ShowStatusLine() { tui.Text("enter protocol line:", &tui.Style { Bg: tui.White, Fg: tui.Black, Italic: true, }) } func (dw *debugWindow) Kill() { globalApp.Debug(nil) }