package main import ( "citrons.xyz/talk/client/window" "citrons.xyz/talk/tui" "citrons.xyz/talk/proto" "fmt" ) type cmdWindowLocation struct {} type cmdWindow struct { window.DefaultWindow } 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: style = &tui.Style {Bg: colorErr[odd], Fg: tui.White} case logCmd: style = &tui.Style {Bg: colorCmd[odd], Fg: tui.White} } 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 (l cmdWindowLocation) CreateWindow() window.Window { return &globalApp.cmdWindow } func (w *cmdWindow) Location() window.Location { return cmdWindowLocation {} } func (w *cmdWindow) Send(text string) { if text == ":wq" { globalApp.quit = true } } func (w *cmdWindow) ShowStatusLine() { tui.Text("command window", &tui.Style { Bg: tui.White, Fg: tui.Black, Italic: true, }) } func (w *cmdWindow) showPreview() { bottom := w.Buf.Bottom() if bottom == nil { return } msg := bottom.Msg() tui.Push("command window container", tui.Box { Width: tui.Fill, Height: tui.Children, }) var isOverflow bool tui.Push(msg.Id(), tui.Box { Width: tui.Fill, Height: tui.Children, Style: &tui.Style {Fg: tui.White, Bg: colorDefault[bottom.IsOdd()]}, Overflow: true, MaxHeight: 7, IsOverflow: &isOverflow, }) msg.Show(bottom.IsOdd()) tui.Pop() tui.Push("command window border", tui.Box { Width: tui.Fill, Height: 1, Dir: tui.Left, Style: &tui.Style {Bg: tui.White, Fg: tui.Black}, }) if isOverflow { tui.Push("", tui.Box {Width: tui.TextSize, Height: 1, NoWrap: true}) tui.Text("[MORE]", nil) tui.Pop() } tui.Push("", tui.Box {Width: tui.Fill, Height: 1}) tui.Pop() tui.Push("command window status", tui.Box { Width: tui.TextSize, Height: 1, NoWrap: true, }) w.ShowStatusLine() tui.Pop() tui.Pop() tui.Pop() } func (w *cmdWindow) info(f string, a ...any) { lastIndex++ w.Buf.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logInfo}) } func (w *cmdWindow) err(f string, a ...any) { lastIndex++ w.Buf.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logErr}) } func (w *cmdWindow) fail(o proto.Object) { w.err(proto.Strfail(o)) } func (w *cmdWindow) cmd(f string, a ...any) { lastIndex++ w.Buf.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logCmd}) }