Skip to content

Commit 6031861

Browse files
authored
Merge pull request cli#12720 from cli/kw/fix-invalid-ansi
Fix invalid ANSI SGR escape code in JSON and diff colorization
2 parents ad41bb9 + 48951ac commit 6031861

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

pkg/cmd/pr/diff/diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func fetchDiff(httpClient *http.Client, baseRepo ghrepo.Interface, prNumber int,
190190
const lineBufferSize = 4096
191191

192192
var (
193-
colorHeader = []byte("\x1b[1;38m")
193+
colorHeader = []byte("\x1b[1;37m")
194194
colorAddition = []byte("\x1b[32m")
195195
colorRemoval = []byte("\x1b[31m")
196196
colorReset = []byte("\x1b[m")

pkg/cmd/pr/diff/diff_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func Test_diffRun(t *testing.T) {
179179
Patch: false,
180180
},
181181
wantFields: []string{"number"},
182-
wantStdout: fmt.Sprintf(testDiff, "\x1b[m", "\x1b[1;38m", "\x1b[32m", "\x1b[31m"),
182+
wantStdout: fmt.Sprintf(testDiff, "\x1b[m", "\x1b[1;37m", "\x1b[32m", "\x1b[31m"),
183183
httpStubs: func(reg *httpmock.Registry) {
184184
stubDiffRequest(reg, "application/vnd.github.v3.diff", fmt.Sprintf(testDiff, "", "", "", ""))
185185
},
@@ -313,7 +313,7 @@ func Test_colorDiffLines(t *testing.T) {
313313
"%[4]s+foo%[2]s\n%[5]s-b%[1]sr%[2]s\n%[3]s+++ baz%[2]s\n",
314314
strings.Repeat("a", 2*lineBufferSize),
315315
"\x1b[m",
316-
"\x1b[1;38m",
316+
"\x1b[1;37m",
317317
"\x1b[32m",
318318
"\x1b[31m",
319319
),

pkg/jsoncolor/jsoncolor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
const (
12-
colorDelim = "1;38" // bright white
12+
colorDelim = "1;37" // bold white
1313
colorKey = "1;34" // bright blue
1414
colorNull = "36" // cyan
1515
colorString = "32" // green

pkg/jsoncolor/jsoncolor_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestWrite(t *testing.T) {
3434
r: bytes.NewBufferString(`{}`),
3535
indent: "",
3636
},
37-
wantW: "\x1b[1;38m{\x1b[m\x1b[1;38m}\x1b[m\n",
37+
wantW: "\x1b[1;37m{\x1b[m\x1b[1;37m}\x1b[m\n",
3838
wantErr: false,
3939
},
4040
{
@@ -43,9 +43,9 @@ func TestWrite(t *testing.T) {
4343
r: bytes.NewBufferString(`{"hash":{"a":1,"b":2},"array":[3,4]}`),
4444
indent: "\t",
4545
},
46-
wantW: "\x1b[1;38m{\x1b[m\n\t\x1b[1;34m\"hash\"\x1b[m\x1b[1;38m:\x1b[m " +
47-
"\x1b[1;38m{\x1b[m\n\t\t\x1b[1;34m\"a\"\x1b[m\x1b[1;38m:\x1b[m 1\x1b[1;38m,\x1b[m\n\t\t\x1b[1;34m\"b\"\x1b[m\x1b[1;38m:\x1b[m 2\n\t\x1b[1;38m}\x1b[m\x1b[1;38m,\x1b[m" +
48-
"\n\t\x1b[1;34m\"array\"\x1b[m\x1b[1;38m:\x1b[m \x1b[1;38m[\x1b[m\n\t\t3\x1b[1;38m,\x1b[m\n\t\t4\n\t\x1b[1;38m]\x1b[m\n\x1b[1;38m}\x1b[m\n",
46+
wantW: "\x1b[1;37m{\x1b[m\n\t\x1b[1;34m\"hash\"\x1b[m\x1b[1;37m:\x1b[m " +
47+
"\x1b[1;37m{\x1b[m\n\t\t\x1b[1;34m\"a\"\x1b[m\x1b[1;37m:\x1b[m 1\x1b[1;37m,\x1b[m\n\t\t\x1b[1;34m\"b\"\x1b[m\x1b[1;37m:\x1b[m 2\n\t\x1b[1;37m}\x1b[m\x1b[1;37m,\x1b[m" +
48+
"\n\t\x1b[1;34m\"array\"\x1b[m\x1b[1;37m:\x1b[m \x1b[1;37m[\x1b[m\n\t\t3\x1b[1;37m,\x1b[m\n\t\t4\n\t\x1b[1;37m]\x1b[m\n\x1b[1;37m}\x1b[m\n",
4949
wantErr: false,
5050
},
5151
{
@@ -63,7 +63,7 @@ func TestWrite(t *testing.T) {
6363
r: bytes.NewBufferString(`{{`),
6464
indent: "",
6565
},
66-
wantW: "\x1b[1;38m{\x1b[m\n",
66+
wantW: "\x1b[1;37m{\x1b[m\n",
6767
wantErr: true,
6868
},
6969
}

0 commit comments

Comments
 (0)