From c63028dea017d540be418cdadfb2b37e4cc13b6c Mon Sep 17 00:00:00 2001 From: raul Date: Mon, 6 May 2024 13:31:44 +0200 Subject: [PATCH] Add client TUI scrolling --- cmd/clientFunc.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cmd/clientFunc.go b/cmd/clientFunc.go index f4b1dc7..2fc6bd0 100644 --- a/cmd/clientFunc.go +++ b/cmd/clientFunc.go @@ -143,6 +143,17 @@ func sendToServer(g *gocui.Gui, v *gocui.View) error { return nil } +func scrollView(v *gocui.View, dy int) error { + if v != nil { + v.Autoscroll = false + ox, oy := v.Origin() + if err := v.SetOrigin(ox, oy+dy); err != nil { + return err + } + } + return nil +} + func initKeybindings(g *gocui.Gui) error { if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { log.Panicln(err) @@ -155,6 +166,23 @@ func initKeybindings(g *gocui.Gui) error { if err := g.SetKeybinding("textarea", gocui.KeyEnter, gocui.ModNone, sendToServer); err != nil { log.Panicln(err) } + + if err := g.SetKeybinding("chatbox", gocui.MouseWheelUp, gocui.ModNone, + func(g *gocui.Gui, v *gocui.View) error { + scrollView(v, -1) + return nil + }); err != nil { + log.Panicln(err) + } + + if err := g.SetKeybinding("chatbox", gocui.MouseWheelDown, gocui.ModNone, + func(g *gocui.Gui, v *gocui.View) error { + scrollView(v, 1) + return nil + }); err != nil { + log.Panicln(err) + } + return nil }