| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func RadioMenu(stations []stationRecord) *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) | 
					
						
							| 
									
										
										
										
											2021-03-16 23:49:14 +00:00
										 |  |  | 			fmt.Printf("Streaming: " + opts[0].Text + "\n") | 
					
						
							| 
									
										
										
										
											2021-03-16 23:06:20 +00:00
										 |  |  | 			stdout, _ := subExecute(player(), options(), val) | 
					
						
							|  |  |  | 			fmt.Println(stdout) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | } |