Skip to content

Commit

Permalink
Color printing most things now. mod update
Browse files Browse the repository at this point in the history
  • Loading branch information
hilli committed Feb 16, 2025
1 parent c33d682 commit 976d543
Show file tree
Hide file tree
Showing 19 changed files with 418 additions and 104 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
release:
name: Release
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -18,7 +18,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
go-version: '1.24'
check-latest: true
- name: Release
uses: goreleaser/goreleaser-action@v6
Expand Down
12 changes: 12 additions & 0 deletions cmd/kefw2/cmd/color_print.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package cmd

import (
"github.com/fatih/color"
)

var (
headerPrinter = color.New(color.FgCyan) // .Add(color.Bold)
contentPrinter = color.New(color.FgYellow).Add(color.Bold)
taskConpletedPrinter = color.New(color.FgGreen).Add(color.Bold)
errorPrinter = color.New(color.FgRed).Add(color.Bold)
)
21 changes: 21 additions & 0 deletions cmd/kefw2/cmd/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
Copyright © 2023-2025 Jens Hilligsøe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cmd

import (
Expand Down
50 changes: 38 additions & 12 deletions cmd/kefw2/cmd/config_speaker.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
Copyright © 2023-2025 Jens Hilligsøe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cmd

import (
Expand Down Expand Up @@ -55,10 +76,11 @@ var speakerDiscoverCmd = &cobra.Command{
return
}
for _, speaker := range newSpeakers {
fmt.Printf("Found speaker: %s (%s)\n", speaker.Name, speaker.IPAddress)
headerPrinter.Print("Found speaker: ")
contentPrinter.Printf("%s (%s)\n", speaker.Name, speaker.IPAddress)
if save {
if err := addSpeaker(speaker.IPAddress); err != nil {
fmt.Printf("Error adding speaker (%s): %s\n", speaker.IPAddress, err)
errorPrinter.Printf("Error adding speaker (%s): %s\n", speaker.IPAddress, err)
}
}
}
Expand All @@ -71,7 +93,7 @@ var speakerAddCmd = &cobra.Command{
Long: `Add a speaker`,
Run: func(cmd *cobra.Command, args []string) {
if err := addSpeaker(args[0]); err != nil {
fmt.Printf("Error adding speaker (%s): %s\n", args[0], err)
errorPrinter.Printf("Error adding speaker (%s): %s\n", args[0], err)
}
},
}
Expand All @@ -83,11 +105,11 @@ var speakerRemoveCmd = &cobra.Command{
Long: `Remove a speaker`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Println("Error: missing speaker IP address")
errorPrinter.Println("Error: missing speaker IP address")
return
}
if err := removeSpeaker(args[0]); err != nil {
fmt.Printf("Error removing speaker (%s): %s\n", args[0], err)
errorPrinter.Printf("Error removing speaker (%s): %s\n", args[0], err)
}
},
}
Expand All @@ -101,9 +123,9 @@ var speakerListCmd = &cobra.Command{
defaultSpeakerIP := viper.GetString("defaultSpeaker")
for _, speaker := range speakers {
if speaker.IPAddress == defaultSpeakerIP {
fmt.Printf("%s (%s) [default]\n", speaker.Name, speaker.IPAddress)
contentPrinter.Printf("%s (%s) [default]\n", speaker.Name, speaker.IPAddress)
} else {
fmt.Printf("%s (%s)\n", speaker.Name, speaker.IPAddress)
contentPrinter.Printf("%s (%s)\n", speaker.Name, speaker.IPAddress)
}
}
},
Expand All @@ -116,11 +138,12 @@ var speakerSetDefaultCmd = &cobra.Command{
Long: "Set default speaker",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
fmt.Printf("Default speaker is: %s (%s)\n", defaultSpeaker.Name, defaultSpeaker.IPAddress)
headerPrinter.Print("Default speaker: ")
contentPrinter.Printf("%s (%s)\n", defaultSpeaker.Name, defaultSpeaker.IPAddress)
return
}
if err := setDefaultSpeaker(args[0]); err != nil {
fmt.Printf("Error setting default speaker (%s): %s\n", args[0], err)
errorPrinter.Printf("Error setting default speaker (%s): %s\n", args[0], err)
}
},
ValidArgsFunction: ConfiguredSpeakersCompletion,
Expand All @@ -136,10 +159,13 @@ func addSpeaker(host string) (err error) {
}
speakers = append(speakers, speaker)
viper.Set("speakers", speakers)
fmt.Printf("Added speaker: %s (%s)\n", speaker.Name, speaker.IPAddress)
taskConpletedPrinter.Print("Added speaker: ")
contentPrinter.Printf("%s (%s)\n", speaker.Name, speaker.IPAddress)

if len(speakers) == 1 {
viper.Set("defaultSpeaker", speaker.IPAddress)
fmt.Printf("Set default speaker: %s (%s)\n", speaker.Name, speaker.IPAddress)
taskConpletedPrinter.Printf("Saved default speaker: ")
contentPrinter.Printf("%s (%s)\n", speaker.Name, speaker.IPAddress)
}
viper.WriteConfig()
return
Expand All @@ -150,7 +176,7 @@ func removeSpeaker(host string) (err error) {
if speaker.IPAddress == host {
speakers = append(speakers[:i], speakers[i+1:]...)
viper.Set("speakers", speakers)
fmt.Printf("Removed speaker: %s (%s)\n", speaker.Name, speaker.IPAddress)
taskConpletedPrinter.Printf("Removed speaker: %s (%s)\n", speaker.Name, speaker.IPAddress)
viper.WriteConfig()
return
}
Expand Down
21 changes: 21 additions & 0 deletions cmd/kefw2/cmd/eq_profile.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
Copyright © 2023-2025 Jens Hilligsøe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cmd

import (
Expand Down
29 changes: 25 additions & 4 deletions cmd/kefw2/cmd/maxvolume.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
/*
Copyright © 2023-2025 Jens Hilligsøe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
Expand All @@ -17,17 +37,18 @@ var maxVolumeCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
volume, _ := currentSpeaker.GetMaxVolume()
fmt.Printf("Max volume is: %d%%\n", volume)
headerPrinter.Print("Max volume: ")
contentPrinter.Printf("%d%%\n", volume)
return
}
volume, err := parseVolume(args[0])
if err != nil {
fmt.Println(err)
errorPrinter.Println(err)
os.Exit(1)
}
err = currentSpeaker.SetMaxVolume(volume)
if err != nil {
fmt.Println(err)
errorPrinter.Println(err)
os.Exit(1)
}
},
Expand Down
35 changes: 31 additions & 4 deletions cmd/kefw2/cmd/mute.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
Copyright © 2023-2025 Jens Hilligsøe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cmd

import (
Expand All @@ -9,19 +30,25 @@ import (

// muteCmd toggles the mute state of the speakers
var muteCmd = &cobra.Command{
Use: "mute",
Use: "mute on/off",
Short: "Get or adjust the mute state of the speakers",
Long: `Get or adjust the mute state of the speakers`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
mute, _ := currentSpeaker.IsMuted()
fmt.Printf("Speakers are muted: %t\n", mute)
if mute {
headerPrinter.Print("Speakers are ")
contentPrinter.Println("muted")
} else {
headerPrinter.Print("Speakers are ")
contentPrinter.Println("not muted")
}
return
}
mute, err := parseMuteArg(args[0])
if err != nil {
fmt.Println(err)
errorPrinter.Println(err)
os.Exit(1)
}
if mute {
Expand All @@ -30,7 +57,7 @@ var muteCmd = &cobra.Command{
err = currentSpeaker.Unmute()
}
if err != nil {
fmt.Println(err)
errorPrinter.Println(err)
os.Exit(1)
}
},
Expand Down
28 changes: 24 additions & 4 deletions cmd/kefw2/cmd/next_track.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
/*
Copyright © 2023-2025 Jens Hilligsøe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
Expand All @@ -16,16 +36,16 @@ var nextTrackCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
canControlPlayback, err := currentSpeaker.CanControlPlayback()
if err != nil {
fmt.Printf("Can't skip track: %s\n", err.Error())
errorPrinter.Printf("Can't skip track: %s\n", err.Error())
os.Exit(1)
}
if !canControlPlayback {
fmt.Println("Not on WiFi/BT source.")
errorPrinter.Println("Not on WiFi/BT source.")
os.Exit(0)
}
err = currentSpeaker.NextTrack()
if err != nil {
fmt.Println(err)
errorPrinter.Println(err)
os.Exit(1)
}
},
Expand Down
27 changes: 24 additions & 3 deletions cmd/kefw2/cmd/off.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
/*
Copyright © 2023-2025 Jens Hilligsøe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

Expand All @@ -15,8 +34,10 @@ var offCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
err := currentSpeaker.PowerOff()
if err != nil {
fmt.Println(err)
errorPrinter.Println(err)
}
taskConpletedPrinter.Print("Speakers are now ")
contentPrinter.Println("off")
},
}

Expand Down
Loading

0 comments on commit 976d543

Please sign in to comment.