Merge pull request #12720 from cli/kw/fix-invalid-ansi

Fix invalid ANSI SGR escape code in JSON and diff colorization
This commit is contained in:
Kynan Ware 2026-03-02 15:12:15 -07:00 committed by GitHub
commit 60318613d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 9 deletions

View file

@ -190,7 +190,7 @@ func fetchDiff(httpClient *http.Client, baseRepo ghrepo.Interface, prNumber int,
const lineBufferSize = 4096
var (
colorHeader = []byte("\x1b[1;38m")
colorHeader = []byte("\x1b[1;37m")
colorAddition = []byte("\x1b[32m")
colorRemoval = []byte("\x1b[31m")
colorReset = []byte("\x1b[m")

View file

@ -179,7 +179,7 @@ func Test_diffRun(t *testing.T) {
Patch: false,
},
wantFields: []string{"number"},
wantStdout: fmt.Sprintf(testDiff, "\x1b[m", "\x1b[1;38m", "\x1b[32m", "\x1b[31m"),
wantStdout: fmt.Sprintf(testDiff, "\x1b[m", "\x1b[1;37m", "\x1b[32m", "\x1b[31m"),
httpStubs: func(reg *httpmock.Registry) {
stubDiffRequest(reg, "application/vnd.github.v3.diff", fmt.Sprintf(testDiff, "", "", "", ""))
},
@ -313,7 +313,7 @@ func Test_colorDiffLines(t *testing.T) {
"%[4]s+foo%[2]s\n%[5]s-b%[1]sr%[2]s\n%[3]s+++ baz%[2]s\n",
strings.Repeat("a", 2*lineBufferSize),
"\x1b[m",
"\x1b[1;38m",
"\x1b[1;37m",
"\x1b[32m",
"\x1b[31m",
),

View file

@ -9,7 +9,7 @@ import (
)
const (
colorDelim = "1;38" // bright white
colorDelim = "1;37" // bold white
colorKey = "1;34" // bright blue
colorNull = "36" // cyan
colorString = "32" // green

View file

@ -34,7 +34,7 @@ func TestWrite(t *testing.T) {
r: bytes.NewBufferString(`{}`),
indent: "",
},
wantW: "\x1b[1;38m{\x1b[m\x1b[1;38m}\x1b[m\n",
wantW: "\x1b[1;37m{\x1b[m\x1b[1;37m}\x1b[m\n",
wantErr: false,
},
{
@ -43,9 +43,9 @@ func TestWrite(t *testing.T) {
r: bytes.NewBufferString(`{"hash":{"a":1,"b":2},"array":[3,4]}`),
indent: "\t",
},
wantW: "\x1b[1;38m{\x1b[m\n\t\x1b[1;34m\"hash\"\x1b[m\x1b[1;38m:\x1b[m " +
"\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" +
"\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",
wantW: "\x1b[1;37m{\x1b[m\n\t\x1b[1;34m\"hash\"\x1b[m\x1b[1;37m:\x1b[m " +
"\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" +
"\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",
wantErr: false,
},
{
@ -63,7 +63,7 @@ func TestWrite(t *testing.T) {
r: bytes.NewBufferString(`{{`),
indent: "",
},
wantW: "\x1b[1;38m{\x1b[m\n",
wantW: "\x1b[1;37m{\x1b[m\n",
wantErr: true,
},
}