From e2dc5b6fbb6adf6f379ef0123c214a196211c305 Mon Sep 17 00:00:00 2001 From: citrons Date: Sun, 1 Jun 2025 15:38:17 -0500 Subject: joining channels --- client/ui.go | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 client/ui.go (limited to 'client/ui.go') diff --git a/client/ui.go b/client/ui.go new file mode 100644 index 0000000..386645e --- /dev/null +++ b/client/ui.go @@ -0,0 +1,86 @@ +package main + +import ( + "citrons.xyz/talk/client/window" + "citrons.xyz/talk/tui" + "zgo.at/termfo/keys" + "os" +) + +func (a *application) getWin() window.Window { + win := a.windowCache.Open(a.currentWindow) + if win == nil { + return emptyWindow {a.currentWindow} + } + return win +} + +func (a *application) onInput(ev tui.Event) { + tui.Selected = "input" + + win := a.getWin() + win.Input().Update(ev) + + buf := win.Buffer() + buf.Scroll(-ev.Mouse.Scroll * 2) + scroll := tui.Size().Height - 5 + switch ev.Key { + case keys.PageUp: + buf.Scroll(scroll) + case keys.PageDown: + buf.Scroll(-scroll) + case keys.Enter: + input := win.Input() + if !input.IsEmpty() { + is, text := isCommand(input.Text()) + if !is { + win.Send(text) + } else { + a.processCommand(text) + input.SetText("") + } + } + case 'h' | keys.Ctrl: + a.currentWindow = cmdWindowLocation {} + } + +} + +func (a *application) showNickBox() { + tui.Push("username", tui.Box {Width: tui.TextSize, Height: tui.TextSize}) + tui.Text("[", nil) + name := a.getNick() + name = string([]rune(name)[:8]) + tui.Text(name, nil) + tui.Text("] ", nil) + tui.Pop() +} + +func (a *application) show() { + tui.Clear() + s := tui.Size() + tui.Push("", tui.Box { + Width: tui.BoxSize(s.Width), Height: tui.BoxSize(s.Height), + }) + + a.getWin().Buffer().Show("buffer") + tui.Push("status", tui.Box { + Width: tui.Fill, Height: tui.BoxSize(1), Dir: tui.Right, + Style: &tui.Style {Bg: tui.White, Fg: tui.Black}, + }) + a.getWin().ShowStatusLine() + tui.Pop() + + tui.Push("input container", tui.Box { + Width: tui.Fill, Height: tui.Children, Dir: tui.Right, + }) + a.showNickBox() + a.getWin().Input().Show("input") + tui.Pop() + + tui.Pop() + tui.DrawLayout() + if tui.Present() != nil { + os.Exit(-1) + } +} \ No newline at end of file -- cgit v1.2.3