From 0d9068ef90d8d2f2e157dd39e42a95b40894241a Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Tue, 16 Mar 2021 23:06:20 +0000 Subject: [PATCH] radio menu first pass, complete --- .gitignore | 2 +- commander.go | 27 ++++++++++++++++++++------- go.mod | 5 ++++- go.sum | 19 +++++++++++++++++++ radiomenu.go | 26 ++++++++++++++++++++++++++ stations.go | 12 ++++++------ 6 files changed, 76 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index a6e040c..3933a54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .idea/ build/ vendor/ - +*.iml diff --git a/commander.go b/commander.go index 8adf706..b86ef56 100644 --- a/commander.go +++ b/commander.go @@ -1,8 +1,9 @@ package main import ( + "fmt" + "os" "os/exec" - "strings" ) func isInstalled(name string) bool { @@ -13,10 +14,22 @@ func isInstalled(name string) bool { return true } -func execute(cmdstr string) (string, error) { - cmdargs := strings.Split(cmdstr, " ") // string arrayified - cmd := cmdargs[0] // command - cmdargs = append(cmdargs[:0], cmdargs[1:]...) // argument array sans cmd - out, err := exec.Command(cmd, cmdargs...).CombinedOutput() - return string(out[:]), err +//func execute(cmdstr string) (string, error) { +// cmdargs := strings.Split(cmdstr, " ") // string arrayified +// cmd := cmdargs[0] // command +// cmdargs = append(cmdargs[:0], cmdargs[1:]...) // argument array sans cmd +// out, err := exec.Command(cmd, cmdargs...).CombinedOutput() +// return string(out[:]), err +//} + +func subExecute(program string, args ...string) ([]byte, error) { + cmd := exec.Command(program, args...) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + if err != nil { + fmt.Printf("%v\n", err) + } + return cmd.CombinedOutput() } diff --git a/go.mod b/go.mod index 63c67f4..125b23c 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module github.com/gmgauthier/gostations go 1.16 -require github.com/alyu/configparser v0.0.0-20191103060215-744e9a66e7bc +require ( + github.com/alyu/configparser v0.0.0-20191103060215-744e9a66e7bc + github.com/dixonwille/wmenu/v5 v5.1.0 +) diff --git a/go.sum b/go.sum index e386739..d8d6e44 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,21 @@ github.com/alyu/configparser v0.0.0-20191103060215-744e9a66e7bc h1:eN2FUvn4J1A31pICABioDYukoh1Tmlei6L3ImZUin/I= github.com/alyu/configparser v0.0.0-20191103060215-744e9a66e7bc/go.mod h1:BYq/NZTroWuzkvsTPJgRBqSHGxKMHCz06gtlfY/W5RU= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920 h1:d/cVoZOrJPJHKH1NdeUjyVAWKp4OpOT+Q+6T1sH7jeU= +github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920/go.mod h1:dv4zxwHi5C/8AeI+4gX4dCWOIvNi7I6JCSX0HvlKPgE= +github.com/dixonwille/wlog/v3 v3.0.1 h1:ViTSsNNndHlKW5S89x5O0KSTpTT9zdPqrkA/TZYY8+s= +github.com/dixonwille/wlog/v3 v3.0.1/go.mod h1:fPYZR9Ne5gFh3N8b3CuXVWHWxkY6Yg1wCeS3Km6Nc0I= +github.com/dixonwille/wmenu/v5 v5.1.0 h1:sKBHDoQ945NRvK0Eitd0kHDYHl1IYOSr1sdCK9c+Qr0= +github.com/dixonwille/wmenu/v5 v5.1.0/go.mod h1:l6EGfXHaN6DPgv5+V5RY+cydAXJsj/oDZVczcdukPzc= +github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAONeMXrxql8uvOKuAZSu8aM5RUGv+1C6IJaEho= +github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkYFkPcDKwRXegd+iM6E7matEszMG5HhwytU8= +github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk= +github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM= +github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/radiomenu.go b/radiomenu.go index 1110061..753bd6e 100644 --- a/radiomenu.go +++ b/radiomenu.go @@ -1,3 +1,29 @@ package main +import ( + "fmt" + "github.com/dixonwille/wmenu/v5" + "os" +) +func Quit() { + os.Exit(0) +} + +func RadioMenu(stations []stationRecord) *wmenu.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: '" + opts[0].Text + "' at url - "+ val +"\n") + stdout, _ := subExecute(player(), options(), val) + fmt.Println(stdout) + return nil + }) + for _, station := range stations { + menu.Option(station.Name, station.Url, false, nil ) + } + menu.Option("Quit", nil, true, nil) + return menu +} \ No newline at end of file diff --git a/stations.go b/stations.go index 0cd52d9..4e15029 100644 --- a/stations.go +++ b/stations.go @@ -37,12 +37,12 @@ func main(){ } stations, _ := StationSearch(name, country, state, tags, notok) - for _, station := range stations { - fmt.Printf("%+v\n", station) + + menu := RadioMenu(stations) + err := menu.Run() + if err != nil { + fmt.Println(err.Error()) + os.Exit(1) } - fmt.Println(len(stations)) - - //mainMenu = RadioMenu(station_list) - } \ No newline at end of file