Deprecate ColorScheme.Gray for ColorScheme.Muted

This commit converts all of the places using ColorScheme.Gray and ColorScheme.Grayf to Muted and Mutedf.

There is a little extra tidying up with local variable names or converting code to use Mutedf format.
This commit is contained in:
Andy Feller 2025-04-06 10:18:48 -04:00
parent b52c131d4c
commit 918cafc222
24 changed files with 60 additions and 60 deletions

View file

@ -138,7 +138,7 @@ func createRun(opts *CreateOptions) error {
processMessage = fmt.Sprintf("Creating gist %s", gistName)
}
}
fmt.Fprintf(errOut, "%s %s\n", cs.Gray("-"), processMessage)
fmt.Fprintf(errOut, "%s %s\n", cs.Muted("-"), processMessage)
httpClient, err := opts.HttpClient()
if err != nil {

View file

@ -230,7 +230,7 @@ func PromptGists(prompter prompter.Prompter, client *http.Client, host string, c
for i, gist := range gists {
gistTime := text.FuzzyAgo(time.Now(), gist.UpdatedAt)
// TODO: support dynamic maxWidth
opts[i] = fmt.Sprintf("%s %s %s", cs.Bold(gist.Filename()), gist.TruncDescription(), cs.Gray(gistTime))
opts[i] = fmt.Sprintf("%s %s %s", cs.Bold(gist.Filename()), gist.TruncDescription(), cs.Muted(gistTime))
}
result, err := prompter.Select("Select a gist", "", opts)

View file

@ -140,7 +140,7 @@ func viewRun(opts *ViewOptions) error {
if len(gist.Files) == 1 || opts.Filename != "" {
return fmt.Errorf("error: file is binary")
}
_, err = fmt.Fprintln(opts.IO.Out, cs.Gray("(skipping rendering binary content)"))
_, err = fmt.Fprintln(opts.IO.Out, cs.Muted("(skipping rendering binary content)"))
return nil
}
@ -197,7 +197,7 @@ func viewRun(opts *ViewOptions) error {
for i, fn := range filenames {
if showFilenames {
fmt.Fprintf(opts.IO.Out, "%s\n\n", cs.Gray(fn))
fmt.Fprintf(opts.IO.Out, "%s\n\n", cs.Muted(fn))
}
if err := render(gist.Files[fn]); err != nil {
return err

View file

@ -38,13 +38,13 @@ func PrintIssues(io *iostreams.IOStreams, now time.Time, prefix string, totalCou
}
table.AddField(text.RemoveExcessiveWhitespace(issue.Title))
table.AddField(issueLabelList(&issue, cs, isTTY))
table.AddTimeField(now, issue.UpdatedAt, cs.Gray)
table.AddTimeField(now, issue.UpdatedAt, cs.Muted)
table.EndRow()
}
_ = table.Render()
remaining := totalCount - len(issues)
if remaining > 0 {
fmt.Fprintf(io.Out, cs.Gray("%sAnd %d more\n"), prefix, remaining)
fmt.Fprintf(io.Out, cs.Muted("%sAnd %d more\n"), prefix, remaining)
}
}

View file

@ -228,7 +228,7 @@ func printHumanIssuePreview(opts *ViewOptions, baseRepo ghrepo.Interface, issue
var md string
var err error
if issue.Body == "" {
md = fmt.Sprintf("\n %s\n\n", cs.Gray("No description provided"))
md = fmt.Sprintf("\n %s\n\n", cs.Muted("No description provided"))
} else {
md, err = markdown.Render(issue.Body,
markdown.WithTheme(opts.IO.TerminalTheme()),
@ -250,7 +250,7 @@ func printHumanIssuePreview(opts *ViewOptions, baseRepo ghrepo.Interface, issue
}
// Footer
fmt.Fprintf(out, cs.Gray("View this issue on GitHub: %s\n"), issue.URL)
fmt.Fprintf(out, cs.Muted("View this issue on GitHub: %s\n"), issue.URL)
return nil
}

View file

@ -30,7 +30,7 @@ func addRow(tp *tableprinter.TablePrinter, io *iostreams.IOStreams, o check) {
markColor = cs.Yellow
case "skipping", "cancel":
mark = "-"
markColor = cs.Gray
markColor = cs.Muted
}
if io.IsStdoutTTY() {

View file

@ -879,37 +879,37 @@ func renderPullRequestPlain(w io.Writer, params map[string]interface{}, state *s
}
func renderPullRequestTTY(io *iostreams.IOStreams, params map[string]interface{}, state *shared.IssueMetadataState) error {
iofmt := io.ColorScheme()
cs := io.ColorScheme()
out := io.Out
fmt.Fprint(out, "Would have created a Pull Request with:\n")
fmt.Fprintf(out, "%s: %s\n", iofmt.Bold("Title"), params["title"].(string))
fmt.Fprintf(out, "%s: %t\n", iofmt.Bold("Draft"), params["draft"])
fmt.Fprintf(out, "%s: %s\n", iofmt.Bold("Base"), params["baseRefName"])
fmt.Fprintf(out, "%s: %s\n", iofmt.Bold("Head"), params["headRefName"])
fmt.Fprintf(out, "%s: %s\n", cs.Bold("Title"), params["title"].(string))
fmt.Fprintf(out, "%s: %t\n", cs.Bold("Draft"), params["draft"])
fmt.Fprintf(out, "%s: %s\n", cs.Bold("Base"), params["baseRefName"])
fmt.Fprintf(out, "%s: %s\n", cs.Bold("Head"), params["headRefName"])
if len(state.Labels) != 0 {
fmt.Fprintf(out, "%s: %s\n", iofmt.Bold("Labels"), strings.Join(state.Labels, ", "))
fmt.Fprintf(out, "%s: %s\n", cs.Bold("Labels"), strings.Join(state.Labels, ", "))
}
if len(state.Reviewers) != 0 {
fmt.Fprintf(out, "%s: %s\n", iofmt.Bold("Reviewers"), strings.Join(state.Reviewers, ", "))
fmt.Fprintf(out, "%s: %s\n", cs.Bold("Reviewers"), strings.Join(state.Reviewers, ", "))
}
if len(state.Assignees) != 0 {
fmt.Fprintf(out, "%s: %s\n", iofmt.Bold("Assignees"), strings.Join(state.Assignees, ", "))
fmt.Fprintf(out, "%s: %s\n", cs.Bold("Assignees"), strings.Join(state.Assignees, ", "))
}
if len(state.Milestones) != 0 {
fmt.Fprintf(out, "%s: %s\n", iofmt.Bold("Milestones"), strings.Join(state.Milestones, ", "))
fmt.Fprintf(out, "%s: %s\n", cs.Bold("Milestones"), strings.Join(state.Milestones, ", "))
}
if len(state.Projects) != 0 {
fmt.Fprintf(out, "%s: %s\n", iofmt.Bold("Projects"), strings.Join(state.Projects, ", "))
fmt.Fprintf(out, "%s: %s\n", cs.Bold("Projects"), strings.Join(state.Projects, ", "))
}
fmt.Fprintf(out, "%s: %t\n", iofmt.Bold("MaintainerCanModify"), params["maintainerCanModify"])
fmt.Fprintf(out, "%s: %t\n", cs.Bold("MaintainerCanModify"), params["maintainerCanModify"])
fmt.Fprintf(out, "%s\n", iofmt.Bold("Body:"))
fmt.Fprintf(out, "%s\n", cs.Bold("Body:"))
// Body
var md string
var err error
if len(params["body"].(string)) == 0 {
md = fmt.Sprintf("%s\n", iofmt.Gray("No description provided"))
md = fmt.Sprintf("%s\n", cs.Muted("No description provided"))
} else {
md, err = markdown.Render(params["body"].(string),
markdown.WithTheme(io.TerminalTheme()),

View file

@ -191,7 +191,7 @@ func reviewRun(opts *ReviewOptions) error {
switch reviewData.State {
case api.ReviewComment:
fmt.Fprintf(opts.IO.ErrOut, "%s Reviewed pull request %s#%d\n", cs.Gray("-"), ghrepo.FullName(baseRepo), pr.Number)
fmt.Fprintf(opts.IO.ErrOut, "%s Reviewed pull request %s#%d\n", cs.Muted("-"), ghrepo.FullName(baseRepo), pr.Number)
case api.ReviewApprove:
fmt.Fprintf(opts.IO.ErrOut, "%s Approved pull request %s#%d\n", cs.SuccessIcon(), ghrepo.FullName(baseRepo), pr.Number)
case api.ReviewRequestChanges:

View file

@ -62,7 +62,7 @@ func CommentList(io *iostreams.IOStreams, comments api.Comments, reviews api.Pul
hiddenCount := totalCount - retrievedCount
if preview && hiddenCount > 0 {
fmt.Fprint(&b, cs.Gray(fmt.Sprintf("———————— Not showing %s ————————", text.Pluralize(hiddenCount, "comment"))))
fmt.Fprint(&b, cs.Muted(fmt.Sprintf("———————— Not showing %s ————————", text.Pluralize(hiddenCount, "comment"))))
fmt.Fprintf(&b, "\n\n\n")
}
@ -79,7 +79,7 @@ func CommentList(io *iostreams.IOStreams, comments api.Comments, reviews api.Pul
}
if preview && hiddenCount > 0 {
fmt.Fprint(&b, cs.Gray("Use --comments to view the full conversation"))
fmt.Fprint(&b, cs.Muted("Use --comments to view the full conversation"))
fmt.Fprintln(&b)
}
@ -122,7 +122,7 @@ func formatComment(io *iostreams.IOStreams, comment Comment, newest bool) (strin
var md string
var err error
if comment.Content() == "" {
md = fmt.Sprintf("\n %s\n\n", cs.Gray("No body provided"))
md = fmt.Sprintf("\n %s\n\n", cs.Muted("No body provided"))
} else {
md, err = markdown.Render(comment.Content(),
markdown.WithTheme(io.TerminalTheme()),
@ -135,7 +135,7 @@ func formatComment(io *iostreams.IOStreams, comment Comment, newest bool) (strin
// Footer
if comment.Link() != "" {
fmt.Fprintf(&b, cs.Gray("View the full review: %s\n\n"), comment.Link())
fmt.Fprintf(&b, cs.Muted("View the full review: %s\n\n"), comment.Link())
}
return b.String(), nil

View file

@ -60,7 +60,7 @@ func PrintHeader(io *iostreams.IOStreams, s string) {
}
func PrintMessage(io *iostreams.IOStreams, s string) {
fmt.Fprintln(io.Out, io.ColorScheme().Gray(s))
fmt.Fprintln(io.Out, io.ColorScheme().Muted(s))
}
func ListNoResults(repoName string, itemName string, hasFilters bool) error {
@ -83,7 +83,7 @@ func ListHeader(repoName string, itemName string, matchCount int, totalMatchCoun
}
func PrCheckStatusSummaryWithColor(cs *iostreams.ColorScheme, checks api.PullRequestChecksStatus) string {
var summary = cs.Gray("No checks")
var summary = cs.Muted("No checks")
if checks.Total > 0 {
if checks.Failing > 0 {
if checks.Failing == checks.Total {

View file

@ -316,6 +316,6 @@ func printPrs(io *iostreams.IOStreams, totalCount int, prs ...api.PullRequest) {
}
remaining := totalCount - len(prs)
if remaining > 0 {
fmt.Fprintf(w, cs.Gray(" And %d more\n"), remaining)
fmt.Fprintf(w, cs.Muted(" And %d more\n"), remaining)
}
}

View file

@ -260,7 +260,7 @@ func printHumanPrPreview(opts *ViewOptions, baseRepo ghrepo.Interface, pr *api.P
var md string
var err error
if pr.Body == "" {
md = fmt.Sprintf("\n %s\n\n", cs.Gray("No description provided"))
md = fmt.Sprintf("\n %s\n\n", cs.Muted("No description provided"))
} else {
md, err = markdown.Render(pr.Body,
markdown.WithTheme(opts.IO.TerminalTheme()),
@ -282,7 +282,7 @@ func printHumanPrPreview(opts *ViewOptions, baseRepo ghrepo.Interface, pr *api.P
}
// Footer
fmt.Fprintf(out, cs.Gray("View this pull request on GitHub: %s\n"), pr.URL)
fmt.Fprintf(out, cs.Muted("View this pull request on GitHub: %s\n"), pr.URL)
return nil
}

View file

@ -129,19 +129,19 @@ func viewRun(opts *ViewOptions) error {
}
func renderReleaseTTY(io *iostreams.IOStreams, release *shared.Release) error {
iofmt := io.ColorScheme()
cs := io.ColorScheme()
w := io.Out
fmt.Fprintf(w, "%s\n", iofmt.Bold(release.TagName))
fmt.Fprintf(w, "%s\n", cs.Bold(release.TagName))
if release.IsDraft {
fmt.Fprintf(w, "%s • ", iofmt.Red("Draft"))
fmt.Fprintf(w, "%s • ", cs.Red("Draft"))
} else if release.IsPrerelease {
fmt.Fprintf(w, "%s • ", iofmt.Yellow("Pre-release"))
fmt.Fprintf(w, "%s • ", cs.Yellow("Pre-release"))
}
if release.IsDraft {
fmt.Fprintf(w, "%s\n", iofmt.Gray(fmt.Sprintf("%s created this %s", release.Author.Login, text.FuzzyAgo(time.Now(), release.CreatedAt))))
fmt.Fprintf(w, "%s\n", cs.Mutedf("%s created this %s", release.Author.Login, text.FuzzyAgo(time.Now(), release.CreatedAt)))
} else {
fmt.Fprintf(w, "%s\n", iofmt.Gray(fmt.Sprintf("%s released this %s", release.Author.Login, text.FuzzyAgo(time.Now(), *release.PublishedAt))))
fmt.Fprintf(w, "%s\n", cs.Mutedf("%s released this %s", release.Author.Login, text.FuzzyAgo(time.Now(), *release.PublishedAt)))
}
renderedDescription, err := markdown.Render(release.Body,
@ -153,7 +153,7 @@ func renderReleaseTTY(io *iostreams.IOStreams, release *shared.Release) error {
fmt.Fprintln(w, renderedDescription)
if len(release.Assets) > 0 {
fmt.Fprintf(w, "%s\n", iofmt.Bold("Assets"))
fmt.Fprintf(w, "%s\n", cs.Bold("Assets"))
//nolint:staticcheck // SA1019: Showing NAME|SIZE headers adds nothing to table.
table := tableprinter.New(io, tableprinter.NoHeader)
for _, a := range release.Assets {
@ -168,7 +168,7 @@ func renderReleaseTTY(io *iostreams.IOStreams, release *shared.Release) error {
fmt.Fprint(w, "\n")
}
fmt.Fprintf(w, "%s\n", iofmt.Gray(fmt.Sprintf("View on GitHub: %s", release.URL)))
fmt.Fprintln(w, cs.Mutedf("View on GitHub: %s", release.URL))
return nil
}

View file

@ -119,9 +119,9 @@ func renderLicense(license *api.License, opts *ViewOptions) error {
cs := opts.IO.ColorScheme()
var out strings.Builder
if opts.IO.IsStdoutTTY() {
out.WriteString(fmt.Sprintf("\n%s\n", cs.Gray(license.Description)))
out.WriteString(fmt.Sprintf("\n%s\n", cs.Grayf("To implement: %s", license.Implementation)))
out.WriteString(fmt.Sprintf("\n%s\n\n", cs.Grayf("For more information, see: %s", license.HTMLURL)))
out.WriteString(fmt.Sprintf("\n%s\n", cs.Muted(license.Description)))
out.WriteString(fmt.Sprintf("\n%s\n", cs.Mutedf("To implement: %s", license.Implementation)))
out.WriteString(fmt.Sprintf("\n%s\n\n", cs.Mutedf("For more information, see: %s", license.HTMLURL)))
}
out.WriteString(license.Body)
_, err := opts.IO.Out.Write([]byte(out.String()))

View file

@ -181,7 +181,7 @@ func viewRun(opts *ViewOptions) error {
var readmeContent string
if readme == nil {
readmeContent = cs.Gray("This repository does not have a README")
readmeContent = cs.Muted("This repository does not have a README")
} else if isMarkdownFile(readme.Filename) {
var err error
readmeContent, err = markdown.Render(readme.Content,
@ -197,7 +197,7 @@ func viewRun(opts *ViewOptions) error {
description := repo.Description
if description == "" {
description = cs.Gray("No description provided")
description = cs.Muted("No description provided")
}
repoData := struct {
@ -209,7 +209,7 @@ func viewRun(opts *ViewOptions) error {
FullName: cs.Bold(fullName),
Description: description,
Readme: readmeContent,
View: cs.Gray(fmt.Sprintf("View this repository on GitHub: %s", openURL)),
View: cs.Mutedf("View this repository on GitHub: %s", openURL),
}
return tmpl.Execute(stdout, repoData)

View file

@ -52,7 +52,7 @@ func RenderAnnotations(cs *iostreams.ColorScheme, annotations []Annotation) stri
for _, a := range annotations {
lines = append(lines, fmt.Sprintf("%s %s", AnnotationSymbol(cs, a), a.Message))
lines = append(lines, cs.Grayf("%s: %s#%d\n", a.JobName, a.Path, a.StartLine))
lines = append(lines, cs.Mutedf("%s: %s#%d\n", a.JobName, a.Path, a.StartLine))
}
return strings.Join(lines, "\n")

View file

@ -575,7 +575,7 @@ func Symbol(cs *iostreams.ColorScheme, status Status, conclusion Conclusion) (st
case Success:
return cs.SuccessIconWithColor(noColor), cs.Green
case Skipped, Neutral:
return "-", cs.Gray
return "-", cs.Muted
default:
return cs.FailureIconWithColor(noColor), cs.Red
}

View file

@ -397,7 +397,7 @@ func runView(opts *ViewOptions) error {
for _, a := range artifacts {
expiredBadge := ""
if a.Expired {
expiredBadge = cs.Gray(" (expired)")
expiredBadge = cs.Muted(" (expired)")
}
fmt.Fprintf(out, "%s%s\n", a.Name, expiredBadge)
}
@ -411,7 +411,7 @@ func runView(opts *ViewOptions) error {
} else {
fmt.Fprintf(out, "For more information about a job, try: gh run view --job=<job-id>\n")
}
fmt.Fprintf(out, cs.Gray("View this run on GitHub: %s\n"), run.URL)
fmt.Fprintln(out, cs.Mutedf("View this run on GitHub: %s", run.URL))
if opts.ExitStatus && shared.IsFailureState(run.Conclusion) {
return cmdutil.SilentError
@ -423,7 +423,7 @@ func runView(opts *ViewOptions) error {
} else {
fmt.Fprintf(out, "To see the full job log, try: gh run view --log --job=%d\n", selectedJob.ID)
}
fmt.Fprintf(out, cs.Gray("View this run on GitHub: %s\n"), run.URL)
fmt.Fprintln(out, cs.Mutedf("View this run on GitHub: %s", run.URL))
if opts.ExitStatus && shared.IsFailureState(selectedJob.Conclusion) {
return cmdutil.SilentError

View file

@ -161,7 +161,7 @@ func displayResults(io *iostreams.IOStreams, now time.Time, results search.Commi
tp.AddField(commit.Sha)
tp.AddField(text.RemoveExcessiveWhitespace(commit.Info.Message))
tp.AddField(commit.Author.Login)
tp.AddTimeField(now, commit.Info.Author.Date, cs.Gray)
tp.AddTimeField(now, commit.Info.Author.Date, cs.Muted)
tp.EndRow()
}
if io.IsStdoutTTY() {

View file

@ -171,14 +171,14 @@ func displayResults(io *iostreams.IOStreams, now time.Time, results search.Repos
tags = append(tags, "archived")
}
info := strings.Join(tags, ", ")
infoColor := cs.Gray
infoColor := cs.Muted
if repo.IsPrivate {
infoColor = cs.Yellow
}
tp.AddField(repo.FullName, tableprinter.WithColor(cs.Bold))
tp.AddField(text.RemoveExcessiveWhitespace(repo.Description))
tp.AddField(info, tableprinter.WithColor(infoColor))
tp.AddTimeField(now, repo.UpdatedAt, cs.Gray)
tp.AddTimeField(now, repo.UpdatedAt, cs.Muted)
tp.EndRow()
}
if io.IsStdoutTTY() {

View file

@ -132,7 +132,7 @@ func displayIssueResults(io *iostreams.IOStreams, now time.Time, et EntityType,
}
tp.AddField(text.RemoveExcessiveWhitespace(issue.Title))
tp.AddField(listIssueLabels(&issue, cs, tp.IsTTY()))
tp.AddTimeField(now, issue.UpdatedAt, cs.Gray)
tp.AddTimeField(now, issue.UpdatedAt, cs.Muted)
tp.EndRow()
}

View file

@ -740,7 +740,7 @@ func statusRun(opts *StatusOptions) error {
errs := sg.authErrors.ToSlice()
sort.Strings(errs)
for _, msg := range errs {
fmt.Fprintln(out, cs.Gray(fmt.Sprintf("warning: %s", msg)))
fmt.Fprintln(out, cs.Mutedf("warning: %s", msg))
}
}

View file

@ -175,7 +175,7 @@ func viewWorkflowContent(opts *ViewOptions, client *api.Client, repo ghrepo.Inte
out := opts.IO.Out
fileName := workflow.Base()
fmt.Fprintf(out, "%s - %s\n", cs.Bold(workflow.Name), cs.Gray(fileName))
fmt.Fprintf(out, "%s - %s\n", cs.Bold(workflow.Name), cs.Muted(fileName))
fmt.Fprintf(out, "ID: %s", cs.Cyanf("%d", workflow.ID))
codeBlock := fmt.Sprintf("```yaml\n%s\n```", yaml)

View file

@ -142,7 +142,7 @@ func (c *ColorScheme) GreenBold(t string) string {
return greenBold(t)
}
// Use Muted instead for thematically contrasting color.
// Deprecated: Use Muted instead for thematically contrasting color.
func (c *ColorScheme) Gray(t string) string {
if !c.enabled {
return t
@ -153,7 +153,7 @@ func (c *ColorScheme) Gray(t string) string {
return gray(t)
}
// Use Mutedf instead for thematically contrasting color.
// Deprecated: Use Mutedf instead for thematically contrasting color.
func (c *ColorScheme) Grayf(t string, args ...interface{}) string {
return c.Gray(fmt.Sprintf(t, args...))
}
@ -255,7 +255,7 @@ func (c *ColorScheme) ColorFromString(s string) func(string) string {
case "green":
fn = c.Green
case "gray":
fn = c.Gray
fn = c.Muted
case "magenta":
fn = c.Magenta
case "cyan":