Skip to content

Commit

Permalink
Merge pull request #2042 from rsteube/fastfetch-move-actions
Browse files Browse the repository at this point in the history
fastfetch: moved actions
  • Loading branch information
rsteube authored Nov 27, 2023
2 parents aeae2a2 + b0cd30f commit bea55b9
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 23 deletions.
29 changes: 6 additions & 23 deletions completers/fastfetch_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/fastfetch"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -50,8 +51,6 @@ func init() {
return
}

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

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

case "color":
rootCmd.Flags().StringP(flag.Long, flag.Short, "", flag.Desc)
actionMap[flag.Long] = actionColors
actionMap[flag.Long] = fastfetch.ActionColors()

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

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

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

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

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

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

default:
rootCmd.Flags().StringP(flag.Long, flag.Short, "", flag.Desc)
Expand Down
24 changes: 24 additions & 0 deletions pkg/actions/tools/fastfetch/color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fastfetch

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/style"
)

// ActionColors completes colors
//
// black
// red
func ActionColors() carapace.Action {
return carapace.ActionStyledValues(
"black", style.Black,
"red", style.Red,
"green", style.Green,
"yellow", style.Yellow,
"blue", style.Blue,
"magenta", style.Magenta,
"cyan", style.Cyan,
"white", style.White,
"default", style.Default,
)
}
25 changes: 25 additions & 0 deletions pkg/actions/tools/fastfetch/logo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fastfetch

import (
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/style"
)

// ActionLogos completes logos
//
// Alter
// Amazon
func ActionLogos() carapace.Action {
return carapace.ActionExecCommand("fastfetch", "--list-logos", "autocompletion")(func(output []byte) carapace.Action {
logos := strings.Split(strings.TrimRight(string(output), "\n"), "\n")
return carapace.Batch(
carapace.ActionValuesDescribed(
"none", "Disable logo",
"small", "Show small logo if supported",
),
carapace.ActionValues(logos...).Style(style.Blue).Tag("builtin logos"),
).ToA()
})
}
22 changes: 22 additions & 0 deletions pkg/actions/tools/fastfetch/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fastfetch

import (
"strings"

"github.com/rsteube/carapace"
)

// ActionModules completes modules
//
// Board (Print mather board name and other info)
// Break (Print a empty line)
func ActionModules() carapace.Action {
return carapace.ActionExecCommand("fastfetch", "--list-modules", "autocompletion")(func(output []byte) carapace.Action {
var texts []string
for _, line := range strings.Split(strings.TrimRight(string(output), "\n"), "\n") {
name, desc, _ := strings.Cut(line, ":")
texts = append(texts, name, desc)
}
return carapace.ActionValuesDescribed(texts...)
})
}
15 changes: 15 additions & 0 deletions pkg/actions/tools/fastfetch/preset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package fastfetch

import (
"strings"

"github.com/rsteube/carapace"
)

// ActionPresets completes presets
func ActionPresets() carapace.Action {
return carapace.ActionExecCommand("fastfetch", "--list-presets", "autocompletion")(func(output []byte) carapace.Action {
presets := strings.Split(strings.TrimRight(string(output), "\n"), "\n")
return carapace.ActionValues(presets...)
})
}

0 comments on commit bea55b9

Please sign in to comment.