Skip to content

Commit bea55b9

Browse files
authored
Merge pull request #2042 from rsteube/fastfetch-move-actions
fastfetch: moved actions
2 parents aeae2a2 + b0cd30f commit bea55b9

File tree

5 files changed

+92
-23
lines changed

5 files changed

+92
-23
lines changed

completers/fastfetch_completer/cmd/root.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
"github.com/rsteube/carapace"
9+
"github.com/rsteube/carapace-bin/pkg/actions/tools/fastfetch"
910
"github.com/spf13/cobra"
1011
)
1112

@@ -50,8 +51,6 @@ func init() {
5051
return
5152
}
5253

53-
actionBools := carapace.ActionValues("true", "false")
54-
actionColors := carapace.ActionValues("black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "default")
5554
actionMap := carapace.ActionMap{}
5655

5756
for _, flags := range groups {
@@ -64,11 +63,11 @@ func init() {
6463
switch flag.Arg.Type {
6564
case "bool":
6665
rootCmd.Flags().BoolP(flag.Long, flag.Short, false, flag.Desc)
67-
actionMap[flag.Long] = actionBools
66+
actionMap[flag.Long] = carapace.ActionValues("true", "false")
6867

6968
case "color":
7069
rootCmd.Flags().StringP(flag.Long, flag.Short, "", flag.Desc)
71-
actionMap[flag.Long] = actionColors
70+
actionMap[flag.Long] = fastfetch.ActionColors()
7271

7372
case "command":
7473
rootCmd.Flags().StringP(flag.Long, flag.Short, "", flag.Desc)
@@ -89,10 +88,7 @@ func init() {
8988

9089
case "config":
9190
rootCmd.Flags().StringP(flag.Long, flag.Short, "", flag.Desc)
92-
actionMap[flag.Long] = carapace.ActionExecCommand("fastfetch", "--list-presets", "autocompletion")(func(output []byte) carapace.Action {
93-
presets := strings.Split(strings.TrimRight(string(output), "\n"), "\n")
94-
return carapace.ActionValues(presets...)
95-
})
91+
actionMap[flag.Long] = fastfetch.ActionPresets()
9692

9793
case "enum":
9894
rootCmd.Flags().StringP(flag.Long, flag.Short, "", flag.Desc)
@@ -104,13 +100,7 @@ func init() {
104100

105101
case "logo":
106102
rootCmd.Flags().StringP(flag.Long, flag.Short, "", flag.Desc)
107-
actionMap[flag.Long] = carapace.ActionExecCommand("fastfetch", "--list-logos", "autocompletion")(func(output []byte) carapace.Action {
108-
res := []string{"none", "Disable logo", "small", "Show small logo if supported"}
109-
for _, logo := range strings.Split(strings.TrimRight(string(output), "\n"), "\n") {
110-
res = append(res, logo, "Builtin logo")
111-
}
112-
return carapace.ActionValuesDescribed(res...)
113-
})
103+
actionMap[flag.Long] = fastfetch.ActionLogos()
114104

115105
case "num":
116106
rootCmd.Flags().IntP(flag.Long, flag.Short, 0, flag.Desc)
@@ -121,14 +111,7 @@ func init() {
121111

122112
case "structure":
123113
rootCmd.Flags().StringP(flag.Long, flag.Short, "", flag.Desc)
124-
actionMap[flag.Long] = carapace.ActionExecCommand("fastfetch", "--list-modules", "autocompletion")(func(output []byte) carapace.Action {
125-
var texts []string
126-
for _, line := range strings.Split(strings.TrimRight(string(output), "\n"), "\n") {
127-
name, desc, _ := strings.Cut(line, ":")
128-
texts = append(texts, name, desc)
129-
}
130-
return carapace.ActionValuesDescribed(texts...).UniqueList(":")
131-
})
114+
actionMap[flag.Long] = fastfetch.ActionModules().UniqueList(":")
132115

133116
default:
134117
rootCmd.Flags().StringP(flag.Long, flag.Short, "", flag.Desc)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package fastfetch
2+
3+
import (
4+
"github.com/rsteube/carapace"
5+
"github.com/rsteube/carapace/pkg/style"
6+
)
7+
8+
// ActionColors completes colors
9+
//
10+
// black
11+
// red
12+
func ActionColors() carapace.Action {
13+
return carapace.ActionStyledValues(
14+
"black", style.Black,
15+
"red", style.Red,
16+
"green", style.Green,
17+
"yellow", style.Yellow,
18+
"blue", style.Blue,
19+
"magenta", style.Magenta,
20+
"cyan", style.Cyan,
21+
"white", style.White,
22+
"default", style.Default,
23+
)
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package fastfetch
2+
3+
import (
4+
"strings"
5+
6+
"github.com/rsteube/carapace"
7+
"github.com/rsteube/carapace/pkg/style"
8+
)
9+
10+
// ActionLogos completes logos
11+
//
12+
// Alter
13+
// Amazon
14+
func ActionLogos() carapace.Action {
15+
return carapace.ActionExecCommand("fastfetch", "--list-logos", "autocompletion")(func(output []byte) carapace.Action {
16+
logos := strings.Split(strings.TrimRight(string(output), "\n"), "\n")
17+
return carapace.Batch(
18+
carapace.ActionValuesDescribed(
19+
"none", "Disable logo",
20+
"small", "Show small logo if supported",
21+
),
22+
carapace.ActionValues(logos...).Style(style.Blue).Tag("builtin logos"),
23+
).ToA()
24+
})
25+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package fastfetch
2+
3+
import (
4+
"strings"
5+
6+
"github.com/rsteube/carapace"
7+
)
8+
9+
// ActionModules completes modules
10+
//
11+
// Board (Print mather board name and other info)
12+
// Break (Print a empty line)
13+
func ActionModules() carapace.Action {
14+
return carapace.ActionExecCommand("fastfetch", "--list-modules", "autocompletion")(func(output []byte) carapace.Action {
15+
var texts []string
16+
for _, line := range strings.Split(strings.TrimRight(string(output), "\n"), "\n") {
17+
name, desc, _ := strings.Cut(line, ":")
18+
texts = append(texts, name, desc)
19+
}
20+
return carapace.ActionValuesDescribed(texts...)
21+
})
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package fastfetch
2+
3+
import (
4+
"strings"
5+
6+
"github.com/rsteube/carapace"
7+
)
8+
9+
// ActionPresets completes presets
10+
func ActionPresets() carapace.Action {
11+
return carapace.ActionExecCommand("fastfetch", "--list-presets", "autocompletion")(func(output []byte) carapace.Action {
12+
presets := strings.Split(strings.TrimRight(string(output), "\n"), "\n")
13+
return carapace.ActionValues(presets...)
14+
})
15+
}

0 commit comments

Comments
 (0)