From 370f21720856a143f791e7ec4448001c16394d8b Mon Sep 17 00:00:00 2001 From: raul Date: Mon, 6 May 2024 14:09:47 +0200 Subject: [PATCH] Add auto-scroll control --- cmd/clientFunc.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/clientFunc.go b/cmd/clientFunc.go index 439b701..ddd8388 100644 --- a/cmd/clientFunc.go +++ b/cmd/clientFunc.go @@ -162,6 +162,15 @@ func scrollView(v *gocui.View, dy int) error { return nil } +func autoscroll(g *gocui.Gui, v *gocui.View) error { + chatbox, err := g.View("chatbox") + if err != nil { + log.Panicf("Error happened setting autoscroll: %v\n", err) + } + chatbox.Autoscroll = true + return nil +} + func initKeybindings(g *gocui.Gui) error { if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { log.Panicln(err) @@ -171,6 +180,10 @@ func initKeybindings(g *gocui.Gui) error { // log.Panicln(err) // } + if err := g.SetKeybinding("textarea", gocui.KeyCtrlA, gocui.ModNone, autoscroll); err != nil { + log.Panicln(err) + } + if err := g.SetKeybinding("textarea", gocui.KeyEnter, gocui.ModNone, sendToServer); err != nil { log.Panicln(err) } @@ -222,7 +235,7 @@ func layout(g *gocui.Gui) error { if _, err := g.SetCurrentView("textarea"); err != nil { log.Panicln(err) } - textarea.Title = "Send message (Currently chatting as: " + Profile.Username + ")" + textarea.Title = "(" + Profile.Username + ") " + "Send message" + " (Ctrl+A: Autoscroll)" textarea.Wrap = true textarea.Editable = true }