From c96dcea8ac91354349cc41103a054ce0ac45abea Mon Sep 17 00:00:00 2001 From: raul Date: Thu, 16 May 2024 11:58:22 +0200 Subject: [PATCH] Wrap selection back to beginning and viceversa --- tui-test-2/main.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tui-test-2/main.go b/tui-test-2/main.go index ac3b884..2a4edbb 100644 --- a/tui-test-2/main.go +++ b/tui-test-2/main.go @@ -1,12 +1,9 @@ package main import ( - //"fmt" "fmt" - "log" - "strings" - "github.com/jroimartin/gocui" + "log" ) func main() { @@ -20,8 +17,8 @@ func ui() { } defer g.Close() g.SetManagerFunc(layout) - g.Mouse = true - g.Cursor = false + g.Mouse = false + //g.Cursor = true initKeybindings(g) @@ -83,7 +80,14 @@ func initKeybindings(g *gocui.Gui) error { func scrollSongs(v *gocui.View, dy int) error { _, currentY := v.Cursor() - v.SetCursor(0, currentY+dy) + songs := v.BufferLines() + if currentY == len(songs)-2 && dy == +1 { + v.SetCursor(0, 0) + } else if currentY == 0 && dy == -1 { + v.SetCursor(0, len(songs)-2) + } else { + v.SetCursor(0, currentY+dy) + } return nil } @@ -96,7 +100,9 @@ func playSong(g *gocui.Gui, v *gocui.View) error { _, currentlySelected := v.Cursor() songs := v.BufferLines() - fmt.Fprintln(currentlyPlaying, fmt.Sprintf("Playing song number %v (%v)", currentlySelected, strings.TrimLeft(songs[currentlySelected], " "))) + fmt.Fprintln(currentlyPlaying, fmt.Sprintf("Playing song number %v (%v)", currentlySelected, songs[currentlySelected])) + // fmt.Fprintln(currentlyPlaying, len(songs)) + // fmt.Fprintln(currentlyPlaying, currentlySelected) return nil }