beautify the menu

This commit is contained in:
Greg Gauthier 2021-03-16 23:49:14 +00:00
parent f3cabfa83b
commit 721632ac82

View File

@ -6,24 +6,35 @@ import (
"os" "os"
) )
func Short( s string, i int ) string {
runes := []rune( s )
if len( runes ) > i {
return string( runes[:i] )
}
return s
}
func Quit() { func Quit() {
os.Exit(0) os.Exit(0)
} }
func RadioMenu(stations []stationRecord) *wmenu.Menu { func RadioMenu(stations []stationRecord) *wmenu.Menu {
fmt.Println("...Radio Menu...")
menu := wmenu.NewMenu("What is your choice?") menu := wmenu.NewMenu("What is your choice?")
menu.Action( menu.Action(
func (opts []wmenu.Opt) error { func (opts []wmenu.Opt) error {
if opts[0].Text == "Quit"{Quit()} if opts[0].Text == "Quit"{Quit()}
val := fmt.Sprintf("%s",opts[0].Value) val := fmt.Sprintf("%s",opts[0].Value)
fmt.Printf("Streaming: '" + opts[0].Text + "' at url - "+ val +"\n") fmt.Printf("Streaming: " + opts[0].Text + "\n")
stdout, _ := subExecute(player(), options(), val) stdout, _ := subExecute(player(), options(), val)
fmt.Println(stdout) fmt.Println(stdout)
menu.Run() menu.Run()
return nil return nil
}) })
for _, station := range stations { for _, station := range stations {
menu.Option(station.Name, station.Url, false, nil ) 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) menu.Option("Quit", nil, true, nil)
return menu return menu