color.go 987 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/spf13/cobra"
  6. "netdome.biz/paul/impact-80/internal/rgb"
  7. )
  8. func NewColorCmd() *cobra.Command {
  9. return &cobra.Command{
  10. Use: "color <hex>",
  11. Short: "Set RGB color",
  12. Long: "Set the RGB color using a 6-digit hex code (e.g. \"ff0000\" for red).",
  13. Args: cobra.ExactArgs(1),
  14. Run: func(cmd *cobra.Command, args []string) {
  15. c, err := rgb.ParseHexColor(args[0])
  16. if err != nil {
  17. fmt.Fprintf(os.Stderr, "Error: %v\n", err)
  18. os.Exit(1)
  19. }
  20. zones, err := selectedZones()
  21. if err != nil {
  22. fmt.Fprintf(os.Stderr, "Error: %v\n", err)
  23. os.Exit(1)
  24. }
  25. proto, err := OpenDevice()
  26. if err != nil {
  27. fmt.Fprintf(os.Stderr, "Error: %v\n", err)
  28. os.Exit(1)
  29. }
  30. defer proto.Close()
  31. h, s, _ := c.HSV()
  32. if err := setColorOnZones(proto, zones, h, s); err != nil {
  33. fmt.Fprintf(os.Stderr, "Error setting color: %v\n", err)
  34. os.Exit(1)
  35. }
  36. fmt.Printf("Color set to %s\n", args[0])
  37. },
  38. }
  39. }