Skip to content

update gh help formatting with example to print issue label colors i.e. in gh issue list #10231

@jatcs

Description

@jatcs

Describe the feature or problem you’d like to solve

I haven't been able to use the --template functions of autocolor or color to colorize a template output.

Particularly, I want to be able to modify the table output of gh issue list and keep the issue labels colorized, without having to manually map hex colors to ANSI strings, particularly because the hex color is already stored in the JSON output i.e. gh issue list --json labels

Example: gh issue list

Image

If I wanted to remove the updated field, I might try:

gh issue list --json number,title,labels --template '{{range .}}{{printf "#%.0f %s" .number .title}}{{if .labels}} {{range $i, $label := .labels}}{{if $i}}, {{end}}{{printf "%s" $label.name}}{{end}}{{end}}{{"\n"}}{{end}}'

Image

Naturally since color and autocolor only support ANSI strings like 'Red', 'Green', etc, adding | color $label.color fails to print the label colors.

Image

Proposed solution

  • Add an example to gh help formatting that shows how a user can create a template to print issue labels with their corresponding colors.

    • Here is an example where hexcolor could be replaced with syntax to handle applying the label color.
gh issue list --json labels --template \
  '{{range .}}{{printf "%s" | hexcolor .color}}{{end}}'
  • This would help users apply their own filters i.e. using --jq, -S, while still viewing an output similar to gh issue list.

Additional context

Here is some information I found about how to apply colors in zsh, but I haven't been able to figure out how to apply this so that I can color my label output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions