| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package main
- import (
- "fmt"
- "github.com/spf13/cobra"
- )
- func NewBrightnessCmd() *cobra.Command {
- return &cobra.Command{
- Use: "brightness <val>",
- Short: "Set RGB brightness",
- Long: "Set the RGB brightness value (0-255) and read it back, so a value the\n" +
- "keyboard clamps or rescales is reported instead of silently applied.",
- Args: cobra.ExactArgs(1),
- RunE: func(cmd *cobra.Command, args []string) error {
- val, err := ParseUint8(args[0])
- if err != nil {
- return err
- }
- zones, err := selectedZones()
- if err != nil {
- return err
- }
- proto, err := openRGBProtocol()
- if err != nil {
- return err
- }
- defer proto.Close()
- results, err := setBrightnessVerified(proto, zones, val)
- if err != nil {
- return fmt.Errorf("set brightness: %w", err)
- }
- // Claiming "set to N" when the keyboard holds something else is
- // the contradiction this read-back exists to prevent.
- if anyMismatch(results) {
- fmt.Fprintln(cmd.OutOrStdout(), formatResults("Brightness", results))
- return nil
- }
- fmt.Fprintf(cmd.OutOrStdout(), "Brightness set to %d\n", val)
- return nil
- },
- }
- }
|