gostations/radiomenu.go
Greg Gauthier ec5db53b8e
Some checks failed
gobuild / build (push) Failing after 4s
feat(cli): default to bubbles TUI, add find/play subcmds + JSON favorites
- implement internal/ui with bubbles list + ★ fav markers, filter, enter stub
- add data/favorites (JSON roundtrip, Add/Remove, XDG), config tests
- wire subcommands: `find -j`, `play [url|search]`
- gate legacy wmenu behind --legacy; keep old flags for seeding
- fix inverted -short guards, format string, go.mod deps
- add unit tests for radio prune, player IsInstalled, ui keys, etc.
2026-06-05 21:23:11 +01:00

50 lines
1.2 KiB
Go

package main
import (
"fmt"
"log"
"os"
"github.com/dixonwille/wmenu/v5"
"github.com/gmgauthier/gostations/internal/radio"
playerpkg "github.com/gmgauthier/gostations/internal/player"
)
func Short( s string, i int ) string {
runes := []rune( s )
if len( runes ) > i {
return string( runes[:i] )
}
return s
}
func Quit() {
os.Exit(0)
}
func RadioMenu(stations []radio.Station) *wmenu.Menu {
fmt.Println("...Radio Menu...")
menu := wmenu.NewMenu("What is your choice?")
menu.Action(
func (opts []wmenu.Opt) error {
if opts[0].Text == "Quit"{Quit()}
val := fmt.Sprintf("%s",opts[0].Value)
fmt.Printf("Streaming: %s\n", opts[0].Text)
leg := playerpkg.NewLegacy(player(), options())
_ = leg.Play(val) // legacy path; cleaned impl does Run + live stdio (no bogus CombinedOutput)
// no more fmt of stdout (that was the source of stray "[]")
err := menu.Run()
if err != nil {
log.Fatal("Oops! " + err.Error())
}
return nil
})
for _, station := range stations {
stationListing := fmt.Sprintf("%-40s %-5s %-5s %s", Short(station.Name, 40), station.Codec, station.Bitrate, station.Url)
menu.Option(stationListing, station.Url, false, nil )
}
menu.Option("Quit", nil, true, nil)
return menu
}