Skip to content

Commit b52c131

Browse files
authored
Merge pull request cli#10709 from cli/andyfeller/table-datetime-contrast-github-cli-832
Ensure table datetime columns have thematic, customizable muted text
2 parents bab2bc8 + b3c8c70 commit b52c131

15 files changed

Lines changed: 163 additions & 55 deletions

File tree

pkg/cmd/cache/list/list.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ func listRun(opts *ListOptions) error {
9999
}
100100
client := api.NewClientFromHTTP(httpClient)
101101

102+
cs := opts.IO.ColorScheme()
102103
opts.IO.StartProgressIndicator()
103104
result, err := shared.GetCaches(client, repo, shared.GetCachesOptions{Limit: opts.Limit, Sort: opts.Sort, Order: opts.Order, Key: opts.Key, Ref: opts.Ref})
104105
opts.IO.StopProgressIndicator()
105106
if err != nil {
106-
return fmt.Errorf("%s Failed to get caches: %w", opts.IO.ColorScheme().FailureIcon(), err)
107+
return fmt.Errorf("%s Failed to get caches: %w", cs.FailureIcon(), err)
107108
}
108109

109110
if len(result.ActionsCaches) == 0 && opts.Exporter == nil {
@@ -130,11 +131,11 @@ func listRun(opts *ListOptions) error {
130131

131132
tp := tableprinter.New(opts.IO, tableprinter.WithHeader("ID", "KEY", "SIZE", "CREATED", "ACCESSED"))
132133
for _, cache := range result.ActionsCaches {
133-
tp.AddField(opts.IO.ColorScheme().Cyan(fmt.Sprintf("%d", cache.Id)))
134+
tp.AddField(cs.Cyanf("%d", cache.Id))
134135
tp.AddField(cache.Key)
135136
tp.AddField(humanFileSize(cache.SizeInBytes))
136-
tp.AddTimeField(opts.Now, cache.CreatedAt, opts.IO.ColorScheme().Gray)
137-
tp.AddTimeField(opts.Now, cache.LastAccessedAt, opts.IO.ColorScheme().Gray)
137+
tp.AddTimeField(opts.Now, cache.CreatedAt, cs.Muted)
138+
tp.AddTimeField(opts.Now, cache.LastAccessedAt, cs.Muted)
138139
tp.EndRow()
139140
}
140141

pkg/cmd/codespace/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (a *App) List(ctx context.Context, opts *listOptions, exporter cmdutil.Expo
152152
case false:
153153
nameColor = cs.Yellow
154154
case true:
155-
nameColor = cs.Gray
155+
nameColor = cs.Muted
156156
}
157157

158158
tp.AddField(formattedName, tableprinter.WithColor(nameColor))
@@ -172,7 +172,7 @@ func (a *App) List(ctx context.Context, opts *listOptions, exporter cmdutil.Expo
172172
if err != nil {
173173
return fmt.Errorf("error parsing date %q: %w", c.CreatedAt, err)
174174
}
175-
tp.AddTimeField(time.Now(), ct, cs.Gray)
175+
tp.AddTimeField(time.Now(), ct, cs.Muted)
176176

177177
if hasNonProdVSCSTarget {
178178
tp.AddField(c.VSCSTarget)

pkg/cmd/factory/default.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/cli/cli/v2/pkg/cmd/extension"
2020
"github.com/cli/cli/v2/pkg/cmdutil"
2121
"github.com/cli/cli/v2/pkg/iostreams"
22+
xcolor "github.com/cli/go-gh/v2/pkg/x/color"
2223
)
2324

2425
var ssoHeader string
@@ -292,6 +293,8 @@ func ioStreams(f *cmdutil.Factory) *iostreams.IOStreams {
292293
io.SetPager(pager.Value)
293294
}
294295

296+
io.SetAccessibleColorsEnabled(xcolor.IsAccessibleColorsEnabled())
297+
295298
return io
296299
}
297300

pkg/cmd/gist/list/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func printTable(io *iostreams.IOStreams, gists []shared.Gist, filter *regexp.Reg
206206
tableprinter.WithColor(highlightFilesFunc(&gist)),
207207
)
208208
tp.AddField(visibility, tableprinter.WithColor(visColor))
209-
tp.AddTimeField(time.Now(), gist.UpdatedAt, cs.Gray)
209+
tp.AddTimeField(time.Now(), gist.UpdatedAt, cs.Muted)
210210
tp.EndRow()
211211
}
212212

pkg/cmd/gist/list/list_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ func Test_listRun(t *testing.T) {
487487
},
488488
wantOut: heredoc.Docf(`
489489
%[1]s[0;4;39mID %[1]s[0m %[1]s[0;4;39mDESCRIPTION %[1]s[0m %[1]s[0;4;39mFILES %[1]s[0m %[1]s[0;4;39mVISIBILITY%[1]s[0m %[1]s[0;4;39mUPDATED %[1]s[0m
490-
1234 %[1]s[0;30;43mocto%[1]s[0m%[1]s[0;1;39m match in the description%[1]s[0m 1 file %[1]s[0;32mpublic %[1]s[0m %[1]s[38;5;242mabout 6 hours ago%[1]s[m
491-
2345 %[1]s[0;1;39mmatch in the file name %[1]s[0m %[1]s[0;30;43m2 files%[1]s[0m %[1]s[0;31msecret %[1]s[0m %[1]s[38;5;242mabout 6 hours ago%[1]s[m
490+
1234 %[1]s[0;30;43mocto%[1]s[0m%[1]s[0;1;39m match in the description%[1]s[0m 1 file %[1]s[0;32mpublic %[1]s[0m %[1]s[38;5;242mabout 6 hours ago%[1]s[0m
491+
2345 %[1]s[0;1;39mmatch in the file name %[1]s[0m %[1]s[0;30;43m2 files%[1]s[0m %[1]s[0;31msecret %[1]s[0m %[1]s[38;5;242mabout 6 hours ago%[1]s[0m
492492
`, "\x1b"),
493493
},
494494
{
@@ -694,7 +694,7 @@ func Test_highlightMatch(t *testing.T) {
694694

695695
for _, tt := range tests {
696696
t.Run(tt.name, func(t *testing.T) {
697-
cs := iostreams.NewColorScheme(tt.color, false, false, iostreams.NoTheme)
697+
cs := iostreams.NewColorScheme(tt.color, false, false, false, iostreams.NoTheme)
698698

699699
matched := false
700700
got, err := highlightMatch(tt.input, regex, &matched, cs.Blue, cs.Highlight)

pkg/cmd/gpg-key/list/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func listRun(opts *ListOptions) error {
7878
t.AddField(gpgKey.Emails.String())
7979
t.AddField(gpgKey.KeyID)
8080
t.AddField(gpgKey.PublicKey, tableprinter.WithTruncate(truncateMiddle))
81-
t.AddTimeField(now, gpgKey.CreatedAt, cs.Gray)
81+
t.AddTimeField(now, gpgKey.CreatedAt, cs.Muted)
8282
expiresAt := gpgKey.ExpiresAt.Format(time.RFC3339)
8383
if t.IsTTY() {
8484
if gpgKey.ExpiresAt.IsZero() {
@@ -87,7 +87,7 @@ func listRun(opts *ListOptions) error {
8787
expiresAt = gpgKey.ExpiresAt.Format("2006-01-02")
8888
}
8989
}
90-
t.AddField(expiresAt, tableprinter.WithColor(cs.Gray))
90+
t.AddField(expiresAt, tableprinter.WithColor(cs.Muted))
9191
t.EndRow()
9292
}
9393

pkg/cmd/pr/list/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func listRun(opts *ListOptions) error {
224224
if !isTTY {
225225
table.AddField(shared.PrStateWithDraft(&pr))
226226
}
227-
table.AddTimeField(opts.Now(), pr.CreatedAt, cs.Gray)
227+
table.AddTimeField(opts.Now(), pr.CreatedAt, cs.Muted)
228228
table.EndRow()
229229
}
230230
err = table.Render()

pkg/cmd/release/list/list.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func listRun(opts *ListOptions) error {
8888
}
8989

9090
table := tableprinter.New(opts.IO, tableprinter.WithHeader("Title", "Type", "Tag name", "Published"))
91-
iofmt := opts.IO.ColorScheme()
91+
cs := opts.IO.ColorScheme()
9292
for _, rel := range releases {
9393
title := text.RemoveExcessiveWhitespace(rel.Name)
9494
if title == "" {
@@ -100,13 +100,13 @@ func listRun(opts *ListOptions) error {
100100
var badgeColor func(string) string
101101
if rel.IsLatest {
102102
badge = "Latest"
103-
badgeColor = iofmt.Green
103+
badgeColor = cs.Green
104104
} else if rel.IsDraft {
105105
badge = "Draft"
106-
badgeColor = iofmt.Red
106+
badgeColor = cs.Red
107107
} else if rel.IsPrerelease {
108108
badge = "Pre-release"
109-
badgeColor = iofmt.Yellow
109+
badgeColor = cs.Yellow
110110
}
111111
table.AddField(badge, tableprinter.WithColor(badgeColor))
112112

@@ -116,7 +116,7 @@ func listRun(opts *ListOptions) error {
116116
if rel.PublishedAt.IsZero() {
117117
pubDate = rel.CreatedAt
118118
}
119-
table.AddTimeField(time.Now(), pubDate, iofmt.Gray)
119+
table.AddTimeField(time.Now(), pubDate, cs.Muted)
120120
table.EndRow()
121121
}
122122
err = table.Render()

pkg/cmd/repo/deploy-key/list/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func listRun(opts *ListOptions) error {
9090
}
9191
t.AddField(sshType)
9292
t.AddField(deployKey.Key, tableprinter.WithTruncate(truncateMiddle))
93-
t.AddTimeField(now, deployKey.CreatedAt, cs.Gray)
93+
t.AddTimeField(now, deployKey.CreatedAt, cs.Muted)
9494
t.EndRow()
9595
}
9696

pkg/cmd/repo/list/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func listRun(opts *ListOptions) error {
181181
totalMatchCount := len(listResult.Repositories)
182182
for _, repo := range listResult.Repositories {
183183
info := repoInfo(repo)
184-
infoColor := cs.Gray
184+
infoColor := cs.Muted
185185

186186
if repo.IsPrivate {
187187
infoColor = cs.Yellow
@@ -195,7 +195,7 @@ func listRun(opts *ListOptions) error {
195195
tp.AddField(repo.NameWithOwner, tableprinter.WithColor(cs.Bold))
196196
tp.AddField(text.RemoveExcessiveWhitespace(repo.Description))
197197
tp.AddField(info, tableprinter.WithColor(infoColor))
198-
tp.AddTimeField(opts.Now(), *t, cs.Gray)
198+
tp.AddTimeField(opts.Now(), *t, cs.Muted)
199199
tp.EndRow()
200200
}
201201

0 commit comments

Comments
 (0)