Jelajahi Sumber

drop the info header that named one channel's effect for all of them

The text output's first line was `Zones[0].Effect`, printed above the zone
lines with nothing saying which zone it belonged to. A board running three
different effects therefore printed one of them twice, and the header read as
a mode the whole keyboard was in.

The header is gone and the text is one line per channel, which is what a
person compares. The JSON is untouched: `mode` keeps its place there, because
that is a shape agents already parse and the summarising fields are
documented as the first selected zone's.
Paul-Dieter Klumpp 1 Minggu lalu
induk
melakukan
c2fcb444fc
3 mengubah file dengan 49 tambahan dan 3 penghapusan
  1. 0 1
      README.md
  2. 43 0
      cmd/qmk-rgb-tool/info_test.go
  3. 6 2
      cmd/qmk-rgb-tool/output.go

+ 0 - 1
README.md

@@ -379,7 +379,6 @@ so **ID 46 has no name and the tool does not invent one**:
 $ qmk-rgb-tool effect backlight 46
 Effect set to index 46
 $ qmk-rgb-tool info
-unknown
   Backlight    on   unknown                      brightness 255  speed 127  color hsv:0,255
 ```
 

+ 43 - 0
cmd/qmk-rgb-tool/info_test.go

@@ -111,6 +111,49 @@ func TestInfoSuccessfulRecord(t *testing.T) {
 	}
 }
 
+func TestInfoTextOutputIsOneLinePerChannelAndNoHeader(t *testing.T) {
+	t.Cleanup(vendoredDefinitions(t))
+	// Three channels running three different effects, which is the case a header
+	// could not honestly summarise: it used to print the first channel's effect
+	// above all of them, so `breathe` appeared twice and read as a mode the whole
+	// keyboard was in.
+	protocol := &fakeInfoProtocol{
+		values: map[infoKey][]byte{
+			{channel: 2, param: 1}: {75},
+			{channel: 2, param: 2}: {4},
+			{channel: 2, param: 3}: {1},
+			{channel: 2, param: 4}: {3, 255},
+			{channel: 3, param: 1}: {255},
+			{channel: 3, param: 2}: {5},
+			{channel: 3, param: 3}: {4},
+			{channel: 3, param: 4}: {3, 255},
+			{channel: 4, param: 1}: {160},
+			{channel: 4, param: 2}: {1},
+			{channel: 4, param: 3}: {1},
+			{channel: 4, param: 4}: {8, 255},
+		},
+		errors: make(map[infoKey]error),
+	}
+	t.Cleanup(stubOpenTarget(t, protocol, impact80Display(), impact80Channels(), 0x36B0, 0x309F))
+
+	var stdout bytes.Buffer
+	cmd := NewInfoCmd()
+	cmd.SetOut(&stdout)
+	cmd.SilenceErrors = true
+	cmd.SilenceUsage = true
+	cmd.SetArgs(nil)
+	if err := cmd.Execute(); err != nil {
+		t.Fatalf("Execute() error = %v", err)
+	}
+
+	want := "  logo         on   breathe                      brightness  75  speed   1  color hsv:3,255\n" +
+		"  backlight    on   breathing                    brightness 255  speed   4  color hsv:3,255\n" +
+		"  side         on   wave                         brightness 160  speed   1  color hsv:8,255\n"
+	if got := stdout.String(); got != want {
+		t.Errorf("stdout =\n%q\nwant\n%q", got, want)
+	}
+}
+
 func TestInfoErrorRecord(t *testing.T) {
 	t.Cleanup(vendoredDefinitions(t))
 	protocol := &fakeInfoProtocol{

+ 6 - 2
cmd/qmk-rgb-tool/output.go

@@ -41,9 +41,13 @@ func printEffectListText(out io.Writer, catalog *intrgb.Catalog, channels []via.
 	return nil
 }
 
-// printZoneInfoText writes one line per zone, which is what a person compares.
+// printZoneInfoText writes one line per zone, which is what a person compares,
+// and nothing else. A header naming the keyboard's "mode" was the first zone's
+// effect, so a board running three different effects printed one of them twice,
+// as a line above the others that looked like it applied to all of them. The
+// effect of every channel is on its own line; `mode` remains in the JSON, which
+// is a shape this tool has always had.
 func printZoneInfoText(out io.Writer, state infoOutput) error {
-	fmt.Fprintf(out, "%s\n", state.Mode)
 	for _, z := range state.Zones {
 		enabled := "off"
 		if z.Enabled {