Select individual lines from buffer
This commit is contained in:
parent
39727a66ae
commit
d4230db74f
|
@ -4,6 +4,7 @@ import (
|
|||
//"fmt"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/jroimartin/gocui"
|
||||
)
|
||||
|
@ -61,33 +62,45 @@ func initKeybindings(g *gocui.Gui) error {
|
|||
// }
|
||||
//
|
||||
if err := g.SetKeybinding("songSelection", gocui.KeyArrowDown, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
|
||||
selectSongs(v, +1)
|
||||
scrollSongs(v, +1)
|
||||
return nil
|
||||
}); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
if err := g.SetKeybinding("songSelection", gocui.KeyArrowUp, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
|
||||
selectSongs(v, -1)
|
||||
scrollSongs(v, -1)
|
||||
return nil
|
||||
}); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
if err := g.SetKeybinding("songSelection", gocui.KeyEnter, gocui.ModNone, playSong); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func selectSongs(v *gocui.View, dy int) error {
|
||||
//songSelection, err := g.View("songSelection")
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
func scrollSongs(v *gocui.View, dy int) error {
|
||||
_, currentY := v.Cursor()
|
||||
v.SetCursor(0, currentY+dy)
|
||||
return nil
|
||||
}
|
||||
|
||||
func playSong(g *gocui.Gui, v *gocui.View) error {
|
||||
currentlyPlaying, err := g.View("currentlyPlaying")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
currentlyPlaying.Clear()
|
||||
_, currentlySelected := v.Cursor()
|
||||
|
||||
songs := v.BufferLines()
|
||||
fmt.Fprintln(currentlyPlaying, fmt.Sprintf("Playing song number %v (%v)", currentlySelected, strings.TrimLeft(songs[currentlySelected], " ")))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func layout(g *gocui.Gui) error {
|
||||
maxX, maxY := g.Size()
|
||||
|
||||
|
|
Loading…
Reference in New Issue