Disable colorizing labels in issue list output

- Labels with dark color are not visible on a dark background
- "Raw" `issue view` output should never output color, not even with
  CLICOLOR_FORCE=1
This commit is contained in:
Mislav Marohnić 2021-08-03 16:02:16 +02:00
parent 4b499be96b
commit 930ee60ac5
2 changed files with 26 additions and 10 deletions

View file

@ -22,7 +22,7 @@ func PrintIssues(io *iostreams.IOStreams, prefix string, totalCount int, issues
issueNum = "#" + issueNum
}
issueNum = prefix + issueNum
labels := IssueLabelList(issue, cs)
labels := issueLabelList(&issue)
if labels != "" && table.IsTTY() {
labels = fmt.Sprintf("(%s)", labels)
}
@ -56,14 +56,14 @@ func truncateLabels(w int, t string) string {
return fmt.Sprintf("(%s)", truncated)
}
func IssueLabelList(issue api.Issue, cs *iostreams.ColorScheme) string {
func issueLabelList(issue *api.Issue) string {
if len(issue.Labels.Nodes) == 0 {
return ""
}
labelNames := make([]string, 0, len(issue.Labels.Nodes))
for _, label := range issue.Labels.Nodes {
labelNames = append(labelNames, cs.HexToRGB(label.Color, label.Name))
labelNames := make([]string, len(issue.Labels.Nodes))
for i, label := range issue.Labels.Nodes {
labelNames[i] = label.Name
}
return strings.Join(labelNames, ", ")

View file

@ -10,7 +10,6 @@ import (
"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/api"
"github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/pkg/cmd/issue/shared"
issueShared "github.com/cli/cli/pkg/cmd/issue/shared"
prShared "github.com/cli/cli/pkg/cmd/pr/shared"
"github.com/cli/cli/pkg/cmdutil"
@ -125,7 +124,7 @@ func viewRun(opts *ViewOptions) error {
return nil
}
return printRawIssuePreview(opts.IO.Out, issue, opts.IO.ColorScheme())
return printRawIssuePreview(opts.IO.Out, issue)
}
func findIssue(client *http.Client, baseRepoFn func() (ghrepo.Interface, error), selector string, loadComments bool) (*api.Issue, error) {
@ -141,9 +140,9 @@ func findIssue(client *http.Client, baseRepoFn func() (ghrepo.Interface, error),
return issue, err
}
func printRawIssuePreview(out io.Writer, issue *api.Issue, cs *iostreams.ColorScheme) error {
func printRawIssuePreview(out io.Writer, issue *api.Issue) error {
assignees := issueAssigneeList(*issue)
labels := shared.IssueLabelList(*issue, cs)
labels := issueLabelList(issue, nil)
projects := issueProjectList(*issue)
// Print empty strings for empty values so the number of metadata lines is consistent when
@ -193,7 +192,7 @@ func printHumanIssuePreview(opts *ViewOptions, issue *api.Issue) error {
fmt.Fprint(out, cs.Bold("Assignees: "))
fmt.Fprintln(out, assignees)
}
if labels := shared.IssueLabelList(*issue, cs); labels != "" {
if labels := issueLabelList(issue, cs); labels != "" {
fmt.Fprint(out, cs.Bold("Labels: "))
fmt.Fprintln(out, labels)
}
@ -278,3 +277,20 @@ func issueProjectList(issue api.Issue) string {
}
return list
}
func issueLabelList(issue *api.Issue, cs *iostreams.ColorScheme) string {
if len(issue.Labels.Nodes) == 0 {
return ""
}
labelNames := make([]string, len(issue.Labels.Nodes))
for i, label := range issue.Labels.Nodes {
if cs == nil {
labelNames[i] = label.Name
} else {
labelNames[i] = cs.HexToRGB(label.Color, label.Name)
}
}
return strings.Join(labelNames, ", ")
}