Add client TUI scrolling

This commit is contained in:
raul 2024-05-06 13:31:44 +02:00
parent 7eb991a4e4
commit c63028dea0
1 changed files with 28 additions and 0 deletions

View File

@ -143,6 +143,17 @@ func sendToServer(g *gocui.Gui, v *gocui.View) error {
return nil 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 { 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)
@ -155,6 +166,23 @@ func initKeybindings(g *gocui.Gui) error {
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)
} }
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 return nil
} }