diff options
| author | citrons <citrons@mondecitronne.com> | 2025-06-01 15:38:17 -0500 |
|---|---|---|
| committer | citrons <citrons@mondecitronne.com> | 2025-06-01 15:38:17 -0500 |
| commit | e2dc5b6fbb6adf6f379ef0123c214a196211c305 (patch) | |
| tree | cc976665dd2e0916af100b5c0f7f629cc1936b01 /client/cmd_window.go | |
| parent | e740e5478a43358fbbd79636483d000e01f88b7e (diff) | |
joining channels
Diffstat (limited to 'client/cmd_window.go')
| -rw-r--r-- | client/cmd_window.go | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/client/cmd_window.go b/client/cmd_window.go new file mode 100644 index 0000000..6a69bb9 --- /dev/null +++ b/client/cmd_window.go @@ -0,0 +1,134 @@ +package main + +import ( + "citrons.xyz/talk/client/buffer" + "citrons.xyz/talk/client/window" + "citrons.xyz/talk/tui" + "fmt" +) + +type cmdWindowLocation struct {} + +type cmdWindow struct { + buf buffer.Buffer + input tui.TextInput + login bool +} + +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.White} + 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 (l cmdWindowLocation) CreateWindow() window.Window { + return &globalApp.cmdWindow +} + +func (w *cmdWindow) Location() window.Location { + return cmdWindowLocation {} +} + +func (w *cmdWindow) Kill() {} + +func (w *cmdWindow) Buffer() *buffer.Buffer { + return &w.buf +} + +func (w *cmdWindow) Input() *tui.TextInput { + return &w.input +} + +func (w *cmdWindow) Send(text string) { + if w.login { + w.login = false + previousText := w.input.Text() + w.input.SetText("") + globalApp.auth(text, func(success bool) { + if !success { + w.loginMode() + w.input.SetText(previousText) + } + }) + } +} + +func (w *cmdWindow) ShowStatusLine() { + if !w.login { + tui.Text("command window", &tui.Style { + Bg: tui.White, Fg: tui.Black, Italic: true, + }) + } else { + tui.Text("[", nil) + tui.Text("login", &tui.Style { + Bg: tui.White, Fg: tui.Blue, Bold: true, + }) + tui.Text("]", nil) + tui.Text(" username:", nil) + } +} + +func (w *cmdWindow) loginMode() { + w.login = true + w.input.SetText("") +} + +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) cmd(f string, a ...any) { + lastIndex++ + w.buf.Add(logMsg {lastIndex, fmt.Sprintf(f, a...), logCmd}) +} |
