Skip to content

Commit 45304da

Browse files
committed
refactor: replace fatih/color with go-pretty
1 parent 65566db commit 45304da

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.15
98
github.com/google/go-cmp v0.7.0
109
github.com/google/osv-scalibr v0.3.5-0.20251002191929-de9496dc5aa2
10+
github.com/jedib0t/go-pretty/v6 v6.7.5
1111
github.com/tidwall/jsonc v0.3.2
1212
golang.org/x/mod v0.30.0
1313
golang.org/x/sync v0.16.0
@@ -21,12 +21,13 @@ require (
2121
github.com/kr/pretty v0.3.1 // indirect
2222
github.com/kr/text v0.2.0 // indirect
2323
github.com/maruel/natural v1.1.1 // indirect
24-
github.com/mattn/go-colorable v0.1.13 // indirect
25-
github.com/mattn/go-isatty v0.0.20 // indirect
24+
github.com/mattn/go-runewidth v0.0.16 // indirect
25+
github.com/rivo/uniseg v0.4.7 // indirect
2626
github.com/rogpeppe/go-internal v1.13.1 // indirect
2727
github.com/tidwall/gjson v1.18.0 // indirect
2828
github.com/tidwall/match v1.1.1 // indirect
2929
github.com/tidwall/pretty v1.2.1 // indirect
3030
github.com/tidwall/sjson v1.2.5 // indirect
3131
golang.org/x/sys v0.33.0 // indirect
32+
golang.org/x/text v0.26.0 // indirect
3233
)

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.5-0.20251002191929-de9496dc5aa2 h1:2hTIOqFloEiruBSVKrwfz25H/aRICGttAAxLFfaKFdA=
1717
github.com/google/osv-scalibr v0.3.5-0.20251002191929-de9496dc5aa2/go.mod h1:yrL4tlR1cXIb2TUyEmtOdTR5tYYuXzfSprEfwyqp2qU=
18+
github.com/jedib0t/go-pretty/v6 v6.7.5 h1:9dJSWTJnsXJVVAbvxIFxeHf/JxoJd7GUl5o3UzhtuiM=
19+
github.com/jedib0t/go-pretty/v6 v6.7.5/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=
@@ -46,10 +52,10 @@ golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
4652
golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
4753
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
4854
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
49-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
50-
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5155
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
5256
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
57+
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
58+
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
5359
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
5460
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
5561
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 {
@@ -90,10 +90,10 @@ func (r *Reporter) PrintDatabaseLoadErr(err error) {
9090
msg := err.Error()
9191

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

96-
r.PrintErrorf(" %s\n", color.RedString("failed: %s", msg))
96+
r.PrintErrorf(" %s\n", text.FgRed.Sprintf("failed: %s", msg))
9797
}
9898

9999
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
"slices"
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
@@ -91,11 +91,11 @@ func (dbs OSVDatabases) check(r *reporter.Reporter, lockf lockfile.Lockfile, ign
9191
results, err := db.Check(lockf.Packages)
9292

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

100100
continue
101101
}
@@ -160,13 +160,13 @@ func uniqueDBConfigs(configs []*configer.Config) []database.Config {
160160
func describeDB(db database.DB) string {
161161
switch tt := db.(type) {
162162
case *database.APIDB:
163-
return "using batches of " + color.YellowString("%d", tt.BatchSize)
163+
return "using batches of " + text.FgYellow.Sprintf("%d", tt.BatchSize)
164164
case *database.ZipDB:
165165
count := tt.VulnerabilitiesCount
166166

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

176176
return fmt.Sprintf(
177177
"%s %s, including withdrawn",
178-
color.YellowString("%d", count),
178+
text.FgYellow.Sprintf("%d", count),
179179
reporter.Form(count, "vulnerability", "vulnerabilities"),
180180
)
181181
}
@@ -644,8 +644,8 @@ This flag can be passed multiple times to ignore different vulnerabilities`)
644644

645645
r.PrintTextf(
646646
"%s: found %s %s\n",
647-
color.MagentaString("%s", lockf.FilePath),
648-
color.YellowString("%d", len(lockf.Packages)),
647+
text.FgMagenta.Sprint(lockf.FilePath),
648+
text.FgYellow.Sprintf("%d", len(lockf.Packages)),
649649
reporter.Form(len(lockf.Packages), "package", "packages"),
650650
)
651651

@@ -670,15 +670,15 @@ This flag can be passed multiple times to ignore different vulnerabilities`)
670670
ignoresStr = "skipping any ignores"
671671
} else {
672672
ignores = append(ignores, config.Ignore...)
673-
ignoresStr = color.YellowString("%d %s",
673+
ignoresStr = text.FgYellow.Sprintf("%d %s",
674674
len(config.Ignore),
675675
reporter.Form(len(config.Ignore), "ignore", "ignores"),
676676
)
677677
}
678678

679679
r.PrintTextf(
680680
" Using config at %s (%s)\n",
681-
color.MagentaString(config.FilePath),
681+
text.FgMagenta.Sprint(config.FilePath),
682682
ignoresStr,
683683
)
684684
}
@@ -695,7 +695,7 @@ This flag can be passed multiple times to ignore different vulnerabilities`)
695695

696696
r.PrintTextf(
697697
" Using db %s%s\n",
698-
color.HiCyanString(db.Name()),
698+
text.FgHiCyan.Sprint(db.Name()),
699699
desc,
700700
)
701701
}
@@ -760,7 +760,7 @@ func writeUpdatedConfigs(r *reporter.Reporter, vulnsPerConfig map[string]map[str
760760
if err == nil {
761761
lines = append(lines, fmt.Sprintf(
762762
"Updated %s with %d %s\n",
763-
color.MagentaString(configPath),
763+
text.FgMagenta.Sprint(configPath),
764764
len(vulns),
765765
reporter.Form(len(vulns), "vulnerability", "vulnerabilities"),
766766
))

0 commit comments

Comments
 (0)