2021-03-16 19:27:52 +00:00
|
|
|
package main
|
|
|
|
|
|
2021-03-16 23:06:20 +00:00
|
|
|
import (
|
|
|
|
|
"fmt"
|
2021-03-17 13:45:54 +00:00
|
|
|
"log"
|
2021-03-16 23:06:20 +00:00
|
|
|
"os"
|
2021-03-17 07:17:09 +00:00
|
|
|
|
|
|
|
|
"github.com/dixonwille/wmenu/v5"
|
refactor: reorganize into internal packages, fix critical panics and error handling
Move browser, config, player, and radio logic into internal/{config,radio,player,ui,version}.
Add cached API host resolution, context-aware HTTP client, and nil/length guards to eliminate
RandomIP, nslookup, reverseLookup, and GetStations panics. Replace subExecute with clean
legacyPlayer using Run-only execution. Fix inverted -short test guards, unformatted config
error messages, and "Erorr" typo. Remove obsolete vendor/GOPATH logic from build scripts.
Update callers in stations.go and radiomenu.go to new paths; retain shims for transition.
2026-06-05 20:10:54 +00:00
|
|
|
|
|
|
|
|
"github.com/gmgauthier/gostations/internal/radio"
|
|
|
|
|
playerpkg "github.com/gmgauthier/gostations/internal/player"
|
2021-03-16 23:06:20 +00:00
|
|
|
)
|
2021-03-16 19:27:52 +00:00
|
|
|
|
2021-03-16 23:49:14 +00:00
|
|
|
func Short( s string, i int ) string {
|
|
|
|
|
runes := []rune( s )
|
|
|
|
|
if len( runes ) > i {
|
|
|
|
|
return string( runes[:i] )
|
|
|
|
|
}
|
|
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-03-16 23:06:20 +00:00
|
|
|
func Quit() {
|
|
|
|
|
os.Exit(0)
|
|
|
|
|
}
|
|
|
|
|
|
refactor: reorganize into internal packages, fix critical panics and error handling
Move browser, config, player, and radio logic into internal/{config,radio,player,ui,version}.
Add cached API host resolution, context-aware HTTP client, and nil/length guards to eliminate
RandomIP, nslookup, reverseLookup, and GetStations panics. Replace subExecute with clean
legacyPlayer using Run-only execution. Fix inverted -short test guards, unformatted config
error messages, and "Erorr" typo. Remove obsolete vendor/GOPATH logic from build scripts.
Update callers in stations.go and radiomenu.go to new paths; retain shims for transition.
2026-06-05 20:10:54 +00:00
|
|
|
func RadioMenu(stations []radio.Station) *wmenu.Menu {
|
2021-03-16 23:49:14 +00:00
|
|
|
fmt.Println("...Radio Menu...")
|
2021-03-16 23:06:20 +00:00
|
|
|
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)
|
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 20:23:11 +00:00
|
|
|
fmt.Printf("Streaming: %s\n", opts[0].Text)
|
refactor: reorganize into internal packages, fix critical panics and error handling
Move browser, config, player, and radio logic into internal/{config,radio,player,ui,version}.
Add cached API host resolution, context-aware HTTP client, and nil/length guards to eliminate
RandomIP, nslookup, reverseLookup, and GetStations panics. Replace subExecute with clean
legacyPlayer using Run-only execution. Fix inverted -short test guards, unformatted config
error messages, and "Erorr" typo. Remove obsolete vendor/GOPATH logic from build scripts.
Update callers in stations.go and radiomenu.go to new paths; retain shims for transition.
2026-06-05 20:10:54 +00:00
|
|
|
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 "[]")
|
2021-03-17 13:45:54 +00:00
|
|
|
err := menu.Run()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal("Oops! " + err.Error())
|
|
|
|
|
}
|
2021-03-16 23:06:20 +00:00
|
|
|
return nil
|
|
|
|
|
})
|
|
|
|
|
for _, station := range stations {
|
2021-03-16 23:49:14 +00:00
|
|
|
stationListing := fmt.Sprintf("%-40s %-5s %-5s %s", Short(station.Name, 40), station.Codec, station.Bitrate, station.Url)
|
|
|
|
|
menu.Option(stationListing, station.Url, false, nil )
|
2021-03-16 23:06:20 +00:00
|
|
|
}
|
|
|
|
|
menu.Option("Quit", nil, true, nil)
|
|
|
|
|
return menu
|
|
|
|
|
}
|