package rgb import ( "fmt" "os" "strings" "github.com/spf13/cobra" intrgb "github.com/wobkey/rgb/internal/rgb" "github.com/wobkey/rgb/internal/via" ) func resolveEffectTargets(name string, zones []intrgb.Zone) ([]intrgb.EffectTarget, []intrgb.Zone, error) { if name == "static" { name = "solid" } return intrgb.ResolveEffect(name, zones) } func NewEffectCmd() *cobra.Command { return &cobra.Command{ Use: "effect ", Short: "Set RGB effect", Long: "Set the RGB lighting effect on the connected keyboard.", Args: cobra.ExactArgs(1), RunE: func(_ *cobra.Command, args []string) error { zones, err := selectedZones() if err != nil { return err } targets, skipped, err := resolveEffectTargets(args[0], zones) if err != nil { return err } if len(skipped) > 0 { skippedNames := make([]string, len(skipped)) for i, zone := range skipped { skippedNames[i] = string(zone) } fmt.Fprintf(os.Stderr, "Warning: effect not supported on zone(s): %s\n", strings.Join(skippedNames, ", ")) } proto, _, err := OpenDevice() if err != nil { return err } defer proto.Close() for _, target := range targets { if err := proto.SetValue(via.LEDType(target.Zone.Channel()), uint8(intrgb.EffectID), target.ID); err != nil { return fmt.Errorf("set effect on %s: %w", target.Zone, err) } } fmt.Printf("Effect set to %q\n", args[0]) return nil }, } }