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 '0' | keys.Alt: 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), Style: &tui.Style {Fg: tui.White, Bg: colorDefault[false]}, }) a.getWin().Buffer().Show("buffer") tui.Push("input border", tui.Box { Width: tui.Fill, Height: 1, Dir: tui.Left, Style: &tui.Style {Bg: tui.White, Fg: tui.Black}, }) if a.getWin().Buffer().ScrollPos() > 0 { tui.Push("", tui.Box {Width: tui.TextSize, Height: 1, NoWrap: true}) if a.getWin().Buffer().AtTop() { tui.Text("[TOP]", nil) } else { tui.Text("[MORE]", nil) } tui.Pop() } tui.Push("", tui.Box {Width: tui.Fill, Height: 1}) tui.Pop() tui.Push("status", tui.Box {Width: tui.TextSize, Height: 1, NoWrap: true}) a.getWin().ShowStatusLine() tui.Pop() 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) } }