Wrap selection back to beginning and viceversa

This commit is contained in:
raul 2024-05-16 11:58:22 +02:00
parent 17bf35e591
commit c96dcea8ac
1 changed files with 14 additions and 8 deletions

View File

@ -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
}