Add auto-scroll control

This commit is contained in:
raul 2024-05-06 14:09:47 +02:00
parent bcaa1c12af
commit 370f217208
1 changed files with 14 additions and 1 deletions

View File

@ -162,6 +162,15 @@ func scrollView(v *gocui.View, dy int) error {
return nil 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 { func initKeybindings(g *gocui.Gui) error {
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil { if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Panicln(err) log.Panicln(err)
@ -171,6 +180,10 @@ func initKeybindings(g *gocui.Gui) error {
// log.Panicln(err) // 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 { if err := g.SetKeybinding("textarea", gocui.KeyEnter, gocui.ModNone, sendToServer); err != nil {
log.Panicln(err) log.Panicln(err)
} }
@ -222,7 +235,7 @@ func layout(g *gocui.Gui) error {
if _, err := g.SetCurrentView("textarea"); err != nil { if _, err := g.SetCurrentView("textarea"); err != nil {
log.Panicln(err) 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.Wrap = true
textarea.Editable = true textarea.Editable = true
} }