Skip to content

Commit 976d543

Browse files
committed
Color printing most things now. mod update
1 parent c33d682 commit 976d543

File tree

19 files changed

+418
-104
lines changed

19 files changed

+418
-104
lines changed

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
release:
1111
name: Release
12-
runs-on: ubuntu-22.04
12+
runs-on: ubuntu-24.04
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v4
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup Go
1919
uses: actions/setup-go@v5
2020
with:
21-
go-version: '1.22'
21+
go-version: '1.24'
2222
check-latest: true
2323
- name: Release
2424
uses: goreleaser/goreleaser-action@v6

cmd/kefw2/cmd/color_print.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cmd
2+
3+
import (
4+
"github.com/fatih/color"
5+
)
6+
7+
var (
8+
headerPrinter = color.New(color.FgCyan) // .Add(color.Bold)
9+
contentPrinter = color.New(color.FgYellow).Add(color.Bold)
10+
taskConpletedPrinter = color.New(color.FgGreen).Add(color.Bold)
11+
errorPrinter = color.New(color.FgRed).Add(color.Bold)
12+
)

cmd/kefw2/cmd/config.go

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

324
import (

cmd/kefw2/cmd/config_speaker.go

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

324
import (
@@ -55,10 +76,11 @@ var speakerDiscoverCmd = &cobra.Command{
5576
return
5677
}
5778
for _, speaker := range newSpeakers {
58-
fmt.Printf("Found speaker: %s (%s)\n", speaker.Name, speaker.IPAddress)
79+
headerPrinter.Print("Found speaker: ")
80+
contentPrinter.Printf("%s (%s)\n", speaker.Name, speaker.IPAddress)
5981
if save {
6082
if err := addSpeaker(speaker.IPAddress); err != nil {
61-
fmt.Printf("Error adding speaker (%s): %s\n", speaker.IPAddress, err)
83+
errorPrinter.Printf("Error adding speaker (%s): %s\n", speaker.IPAddress, err)
6284
}
6385
}
6486
}
@@ -71,7 +93,7 @@ var speakerAddCmd = &cobra.Command{
7193
Long: `Add a speaker`,
7294
Run: func(cmd *cobra.Command, args []string) {
7395
if err := addSpeaker(args[0]); err != nil {
74-
fmt.Printf("Error adding speaker (%s): %s\n", args[0], err)
96+
errorPrinter.Printf("Error adding speaker (%s): %s\n", args[0], err)
7597
}
7698
},
7799
}
@@ -83,11 +105,11 @@ var speakerRemoveCmd = &cobra.Command{
83105
Long: `Remove a speaker`,
84106
Run: func(cmd *cobra.Command, args []string) {
85107
if len(args) != 1 {
86-
fmt.Println("Error: missing speaker IP address")
108+
errorPrinter.Println("Error: missing speaker IP address")
87109
return
88110
}
89111
if err := removeSpeaker(args[0]); err != nil {
90-
fmt.Printf("Error removing speaker (%s): %s\n", args[0], err)
112+
errorPrinter.Printf("Error removing speaker (%s): %s\n", args[0], err)
91113
}
92114
},
93115
}
@@ -101,9 +123,9 @@ var speakerListCmd = &cobra.Command{
101123
defaultSpeakerIP := viper.GetString("defaultSpeaker")
102124
for _, speaker := range speakers {
103125
if speaker.IPAddress == defaultSpeakerIP {
104-
fmt.Printf("%s (%s) [default]\n", speaker.Name, speaker.IPAddress)
126+
contentPrinter.Printf("%s (%s) [default]\n", speaker.Name, speaker.IPAddress)
105127
} else {
106-
fmt.Printf("%s (%s)\n", speaker.Name, speaker.IPAddress)
128+
contentPrinter.Printf("%s (%s)\n", speaker.Name, speaker.IPAddress)
107129
}
108130
}
109131
},
@@ -116,11 +138,12 @@ var speakerSetDefaultCmd = &cobra.Command{
116138
Long: "Set default speaker",
117139
Run: func(cmd *cobra.Command, args []string) {
118140
if len(args) != 1 {
119-
fmt.Printf("Default speaker is: %s (%s)\n", defaultSpeaker.Name, defaultSpeaker.IPAddress)
141+
headerPrinter.Print("Default speaker: ")
142+
contentPrinter.Printf("%s (%s)\n", defaultSpeaker.Name, defaultSpeaker.IPAddress)
120143
return
121144
}
122145
if err := setDefaultSpeaker(args[0]); err != nil {
123-
fmt.Printf("Error setting default speaker (%s): %s\n", args[0], err)
146+
errorPrinter.Printf("Error setting default speaker (%s): %s\n", args[0], err)
124147
}
125148
},
126149
ValidArgsFunction: ConfiguredSpeakersCompletion,
@@ -136,10 +159,13 @@ func addSpeaker(host string) (err error) {
136159
}
137160
speakers = append(speakers, speaker)
138161
viper.Set("speakers", speakers)
139-
fmt.Printf("Added speaker: %s (%s)\n", speaker.Name, speaker.IPAddress)
162+
taskConpletedPrinter.Print("Added speaker: ")
163+
contentPrinter.Printf("%s (%s)\n", speaker.Name, speaker.IPAddress)
164+
140165
if len(speakers) == 1 {
141166
viper.Set("defaultSpeaker", speaker.IPAddress)
142-
fmt.Printf("Set default speaker: %s (%s)\n", speaker.Name, speaker.IPAddress)
167+
taskConpletedPrinter.Printf("Saved default speaker: ")
168+
contentPrinter.Printf("%s (%s)\n", speaker.Name, speaker.IPAddress)
143169
}
144170
viper.WriteConfig()
145171
return
@@ -150,7 +176,7 @@ func removeSpeaker(host string) (err error) {
150176
if speaker.IPAddress == host {
151177
speakers = append(speakers[:i], speakers[i+1:]...)
152178
viper.Set("speakers", speakers)
153-
fmt.Printf("Removed speaker: %s (%s)\n", speaker.Name, speaker.IPAddress)
179+
taskConpletedPrinter.Printf("Removed speaker: %s (%s)\n", speaker.Name, speaker.IPAddress)
154180
viper.WriteConfig()
155181
return
156182
}

cmd/kefw2/cmd/eq_profile.go

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

324
import (

cmd/kefw2/cmd/maxvolume.go

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

324
import (
4-
"fmt"
525
"os"
626

727
"github.com/spf13/cobra"
@@ -17,17 +37,18 @@ var maxVolumeCmd = &cobra.Command{
1737
Run: func(cmd *cobra.Command, args []string) {
1838
if len(args) != 1 {
1939
volume, _ := currentSpeaker.GetMaxVolume()
20-
fmt.Printf("Max volume is: %d%%\n", volume)
40+
headerPrinter.Print("Max volume: ")
41+
contentPrinter.Printf("%d%%\n", volume)
2142
return
2243
}
2344
volume, err := parseVolume(args[0])
2445
if err != nil {
25-
fmt.Println(err)
46+
errorPrinter.Println(err)
2647
os.Exit(1)
2748
}
2849
err = currentSpeaker.SetMaxVolume(volume)
2950
if err != nil {
30-
fmt.Println(err)
51+
errorPrinter.Println(err)
3152
os.Exit(1)
3253
}
3354
},

cmd/kefw2/cmd/mute.go

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

324
import (
@@ -9,19 +30,25 @@ import (
930

1031
// muteCmd toggles the mute state of the speakers
1132
var muteCmd = &cobra.Command{
12-
Use: "mute",
33+
Use: "mute on/off",
1334
Short: "Get or adjust the mute state of the speakers",
1435
Long: `Get or adjust the mute state of the speakers`,
1536
Args: cobra.MaximumNArgs(1),
1637
Run: func(cmd *cobra.Command, args []string) {
1738
if len(args) != 1 {
1839
mute, _ := currentSpeaker.IsMuted()
19-
fmt.Printf("Speakers are muted: %t\n", mute)
40+
if mute {
41+
headerPrinter.Print("Speakers are ")
42+
contentPrinter.Println("muted")
43+
} else {
44+
headerPrinter.Print("Speakers are ")
45+
contentPrinter.Println("not muted")
46+
}
2047
return
2148
}
2249
mute, err := parseMuteArg(args[0])
2350
if err != nil {
24-
fmt.Println(err)
51+
errorPrinter.Println(err)
2552
os.Exit(1)
2653
}
2754
if mute {
@@ -30,7 +57,7 @@ var muteCmd = &cobra.Command{
3057
err = currentSpeaker.Unmute()
3158
}
3259
if err != nil {
33-
fmt.Println(err)
60+
errorPrinter.Println(err)
3461
os.Exit(1)
3562
}
3663
},

cmd/kefw2/cmd/next_track.go

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

324
import (
4-
"fmt"
525
"os"
626

727
"github.com/spf13/cobra"
@@ -16,16 +36,16 @@ var nextTrackCmd = &cobra.Command{
1636
Run: func(cmd *cobra.Command, args []string) {
1737
canControlPlayback, err := currentSpeaker.CanControlPlayback()
1838
if err != nil {
19-
fmt.Printf("Can't skip track: %s\n", err.Error())
39+
errorPrinter.Printf("Can't skip track: %s\n", err.Error())
2040
os.Exit(1)
2141
}
2242
if !canControlPlayback {
23-
fmt.Println("Not on WiFi/BT source.")
43+
errorPrinter.Println("Not on WiFi/BT source.")
2444
os.Exit(0)
2545
}
2646
err = currentSpeaker.NextTrack()
2747
if err != nil {
28-
fmt.Println(err)
48+
errorPrinter.Println(err)
2949
os.Exit(1)
3050
}
3151
},

cmd/kefw2/cmd/off.go

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

324
import (
4-
"fmt"
5-
625
"github.com/spf13/cobra"
726
)
827

@@ -15,8 +34,10 @@ var offCmd = &cobra.Command{
1534
Run: func(cmd *cobra.Command, args []string) {
1635
err := currentSpeaker.PowerOff()
1736
if err != nil {
18-
fmt.Println(err)
37+
errorPrinter.Println(err)
1938
}
39+
taskConpletedPrinter.Print("Speakers are now ")
40+
contentPrinter.Println("off")
2041
},
2142
}
2243

0 commit comments

Comments
 (0)