Skip to content

Commit c40b361

Browse files
committed
refactor: replace fatih/color with go-pretty
1 parent b8ee28e commit c40b361

File tree

5 files changed

+41
-34
lines changed

5 files changed

+41
-34
lines changed

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ go 1.24.6
44

55
require (
66
github.com/BurntSushi/toml v1.5.0
7-
github.com/fatih/color v1.18.0
87
github.com/gkampitakis/go-snaps v0.5.14
98
github.com/google/go-cmp v0.7.0
109
github.com/google/osv-scalibr v0.3.3-0.20250919162947-bcadd5b8f946
10+
github.com/jedib0t/go-pretty/v6 v6.6.7
1111
github.com/tidwall/jsonc v0.3.2
1212
golang.org/x/mod v0.27.0
1313
gopkg.in/yaml.v3 v3.0.1
@@ -20,12 +20,13 @@ require (
2020
github.com/kr/pretty v0.3.1 // indirect
2121
github.com/kr/text v0.2.0 // indirect
2222
github.com/maruel/natural v1.1.1 // indirect
23-
github.com/mattn/go-colorable v0.1.13 // indirect
24-
github.com/mattn/go-isatty v0.0.20 // indirect
23+
github.com/mattn/go-runewidth v0.0.16 // indirect
24+
github.com/rivo/uniseg v0.4.7 // indirect
2525
github.com/rogpeppe/go-internal v1.13.1 // indirect
2626
github.com/tidwall/gjson v1.18.0 // indirect
2727
github.com/tidwall/match v1.1.1 // indirect
2828
github.com/tidwall/pretty v1.2.1 // indirect
2929
github.com/tidwall/sjson v1.2.5 // indirect
3030
golang.org/x/sys v0.33.0 // indirect
31+
golang.org/x/text v0.26.0 // indirect
3132
)

go.sum

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
22
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
33
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
4-
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
5-
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
66
github.com/gkampitakis/ciinfo v0.3.2 h1:JcuOPk8ZU7nZQjdUhctuhQofk7BGHuIy0c9Ez8BNhXs=
77
github.com/gkampitakis/ciinfo v0.3.2/go.mod h1:1NIwaOcFChN4fa/B0hEBdAb6npDlFL8Bwx4dfRLRqAo=
88
github.com/gkampitakis/go-diff v1.3.2 h1:Qyn0J9XJSDTgnsgHRdz9Zp24RaJeKMUHg2+PDZZdC4M=
@@ -15,21 +15,27 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
1515
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
1616
github.com/google/osv-scalibr v0.3.3-0.20250919162947-bcadd5b8f946 h1:b6158og59wx3u1CQnPwn4BUmt8PQrSND8aAJomM6304=
1717
github.com/google/osv-scalibr v0.3.3-0.20250919162947-bcadd5b8f946/go.mod h1:YeOH2wz0HlccjDbYYYTcX01ZyAuwqhZcpQFV7Cxsrwo=
18+
github.com/jedib0t/go-pretty/v6 v6.6.7 h1:m+LbHpm0aIAPLzLbMfn8dc3Ht8MW7lsSO4MPItz/Uuo=
19+
github.com/jedib0t/go-pretty/v6 v6.6.7/go.mod h1:YwC5CE4fJ1HFUDeivSV1r//AmANFHyqczZk+U6BDALU=
1820
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1921
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
2022
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
2123
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
2224
github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo=
2325
github.com/maruel/natural v1.1.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg=
24-
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
25-
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
26-
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
27-
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
28-
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
26+
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
27+
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
2928
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
29+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
30+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
31+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
32+
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
33+
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
3034
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
3135
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
3236
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
37+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
38+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
3339
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
3440
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
3541
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
@@ -44,10 +50,10 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
4450
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
4551
golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ=
4652
golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc=
47-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
48-
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4953
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
5054
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
55+
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
56+
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
5157
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
5258
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5359
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

internal/reporter/report.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/fatih/color"
87
"github.com/g-rath/osv-detector/internal"
98
"github.com/g-rath/osv-detector/pkg/database"
109
"github.com/g-rath/osv-detector/pkg/lockfile"
10+
"github.com/jedib0t/go-pretty/v6/text"
1111
)
1212

1313
type PackageDetailsWithVulnerabilities struct {
@@ -62,14 +62,14 @@ func (r Report) formatLineByLine() string {
6262

6363
lines = append(lines, fmt.Sprintf(
6464
" %s %s",
65-
color.YellowString("%s@%s", pkg.Name, pkg.Version),
66-
color.RedString("is affected by the following vulnerabilities:"),
65+
text.FgYellow.Sprintf("%s@%s", pkg.Name, pkg.Version),
66+
text.FgRed.Sprintf("is affected by the following vulnerabilities:"),
6767
))
6868

6969
for _, vulnerability := range pkg.Vulnerabilities {
7070
lines = append(lines, fmt.Sprintf(
7171
" %s %s",
72-
color.CyanString("%s:", vulnerability.ID),
72+
text.FgCyan.Sprintf("%s:", vulnerability.ID),
7373
vulnerability.Describe(),
7474
))
7575
}
@@ -93,7 +93,7 @@ func (r Report) describeIgnores() string {
9393
return ""
9494
}
9595

96-
return color.YellowString(
96+
return text.FgYellow.Sprintf(
9797
" (%d %s ignored)",
9898
count,
9999
Form(count, "was", "were"),
@@ -112,7 +112,7 @@ func (r Report) String() string {
112112
if count == 0 {
113113
return fmt.Sprintf(
114114
" %s%s\n",
115-
color.GreenString("no %s vulnerabilities found", word),
115+
text.FgGreen.Sprintf("no %s vulnerabilities found", word),
116116
ignoreMsg,
117117
)
118118
}
@@ -121,7 +121,7 @@ func (r Report) String() string {
121121
out += "\n"
122122

123123
out += fmt.Sprintf("\n %s%s\n",
124-
color.RedString(
124+
text.FgRed.Sprintf(
125125
"%d %s %s found in %s",
126126
count,
127127
word,

internal/reporter/reporter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"fmt"
77
"io"
88

9-
"github.com/fatih/color"
109
"github.com/g-rath/osv-detector/pkg/database"
1110
"github.com/g-rath/osv-detector/pkg/lockfile"
11+
"github.com/jedib0t/go-pretty/v6/text"
1212
)
1313

1414
type Reporter struct {
@@ -82,10 +82,10 @@ func (r *Reporter) PrintDatabaseLoadErr(err error) {
8282
msg := err.Error()
8383

8484
if errors.Is(err, database.ErrOfflineDatabaseNotFound) {
85-
msg = color.RedString("no local version of the database was found, and --offline flag was set")
85+
msg = text.FgRed.Sprintf("no local version of the database was found, and --offline flag was set")
8686
}
8787

88-
r.PrintErrorf(" %s\n", color.RedString("failed: %s", msg))
88+
r.PrintErrorf(" %s\n", text.FgRed.Sprintf("failed: %s", msg))
8989
}
9090

9191
func (r *Reporter) PrintKnownEcosystems() {

main.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"sort"
1111
"strings"
1212

13-
"github.com/fatih/color"
1413
"github.com/g-rath/osv-detector/internal"
1514
"github.com/g-rath/osv-detector/internal/configer"
1615
"github.com/g-rath/osv-detector/internal/reporter"
1716
"github.com/g-rath/osv-detector/pkg/database"
1817
"github.com/g-rath/osv-detector/pkg/lockfile"
18+
"github.com/jedib0t/go-pretty/v6/text"
1919
)
2020

2121
// these come from goreleaser
@@ -88,11 +88,11 @@ func (dbs OSVDatabases) check(r *reporter.Reporter, lockf lockfile.Lockfile, ign
8888
results, err := db.Check(lockf.Packages)
8989

9090
if err != nil {
91-
r.PrintErrorf("%s", color.RedString(fmt.Sprintf(
91+
r.PrintErrorf("%s", text.FgRed.Sprintf(
9292
" an api error occurred while trying to check the packages listed in %s: %v\n",
9393
lockf.FilePath,
9494
err,
95-
)))
95+
))
9696

9797
continue
9898
}
@@ -157,13 +157,13 @@ func uniqueDBConfigs(configs []*configer.Config) []database.Config {
157157
func describeDB(db database.DB) string {
158158
switch tt := db.(type) {
159159
case *database.APIDB:
160-
return "using batches of " + color.YellowString("%d", tt.BatchSize)
160+
return "using batches of " + text.FgYellow.Sprintf("%d", tt.BatchSize)
161161
case *database.ZipDB:
162162
count := tt.VulnerabilitiesCount
163163

164164
return fmt.Sprintf(
165165
"%s %s, including withdrawn - last updated %s",
166-
color.YellowString("%d", count),
166+
text.FgYellow.Sprintf("%d", count),
167167
reporter.Form(count, "vulnerability", "vulnerabilities"),
168168
tt.UpdatedAt,
169169
)
@@ -172,7 +172,7 @@ func describeDB(db database.DB) string {
172172

173173
return fmt.Sprintf(
174174
"%s %s, including withdrawn",
175-
color.YellowString("%d", count),
175+
text.FgYellow.Sprintf("%d", count),
176176
reporter.Form(count, "vulnerability", "vulnerabilities"),
177177
)
178178
}
@@ -626,8 +626,8 @@ This flag can be passed multiple times to ignore different vulnerabilities`)
626626

627627
r.PrintTextf(
628628
"%s: found %s %s\n",
629-
color.MagentaString("%s", lockf.FilePath),
630-
color.YellowString("%d", len(lockf.Packages)),
629+
text.FgMagenta.Sprint(lockf.FilePath),
630+
text.FgYellow.Sprintf("%d", len(lockf.Packages)),
631631
reporter.Form(len(lockf.Packages), "package", "packages"),
632632
)
633633

@@ -652,15 +652,15 @@ This flag can be passed multiple times to ignore different vulnerabilities`)
652652
ignoresStr = "skipping any ignores"
653653
} else {
654654
ignores = append(ignores, config.Ignore...)
655-
ignoresStr = color.YellowString("%d %s",
655+
ignoresStr = text.FgYellow.Sprintf("%d %s",
656656
len(config.Ignore),
657657
reporter.Form(len(config.Ignore), "ignore", "ignores"),
658658
)
659659
}
660660

661661
r.PrintTextf(
662662
" Using config at %s (%s)\n",
663-
color.MagentaString(config.FilePath),
663+
text.FgMagenta.Sprint(config.FilePath),
664664
ignoresStr,
665665
)
666666
}
@@ -677,7 +677,7 @@ This flag can be passed multiple times to ignore different vulnerabilities`)
677677

678678
r.PrintTextf(
679679
" Using db %s%s\n",
680-
color.HiCyanString(db.Name()),
680+
text.FgHiCyan.Sprint(db.Name()),
681681
desc,
682682
)
683683
}
@@ -740,7 +740,7 @@ func writeUpdatedConfigs(r *reporter.Reporter, vulnsPerConfig map[string]map[str
740740
if err == nil {
741741
lines = append(lines, fmt.Sprintf(
742742
"Updated %s with %d %s\n",
743-
color.MagentaString(configPath),
743+
text.FgMagenta.Sprint(configPath),
744744
len(vulns),
745745
reporter.Form(len(vulns), "vulnerability", "vulnerabilities"),
746746
))

0 commit comments

Comments
 (0)