Skip to content

Commit 83be724

Browse files
committed
Print labels with their colors on lab label list
This takes the label.color hex and converts it to color in HexToRGB in utils, then uses rgbterm lib to convert rgb to terminal color. Signed-off-by: Lucas Zampieri <[email protected]>
1 parent 29804ac commit 83be724

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

cmd/label_list.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ var labelListCmd = &cobra.Command{
5353
description = " - " + label.Description
5454
}
5555

56-
fmt.Printf("%s%s\n", label.Name, description)
56+
// Convert hex color to rgb object
57+
c := HexToRGB(label.Color)
58+
59+
fmt.Printf("\033[48;2;%d;%d;%dm%s\033[0m%s\n", c.R, c.G, c.B, label.Name, description)
5760
}
5861
},
5962
}

cmd/util.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package cmd
44

55
import (
66
"fmt"
7+
"image/color"
78
"os"
89
"os/exec"
910
"strconv"
@@ -719,6 +720,7 @@ func mapLabelsAsLabelOptions(rn string, labelTerms []string) (gitlab.LabelOption
719720

720721
return gitlab.LabelOptions(matches), nil
721722
}
723+
722724
// dumpToken dumps information about a specific Personal Access Token
723725
func dumpToken(tokendata *gitlab.PersonalAccessToken) {
724726
fmt.Println("ID: ", tokendata.ID)
@@ -732,3 +734,9 @@ func dumpToken(tokendata *gitlab.PersonalAccessToken) {
732734
fmt.Println("ExpiresAt: ", time.Time(*tokendata.ExpiresAt).String())
733735
fmt.Println("")
734736
}
737+
738+
// HexToRGB converts hex color to color.RGBA with "#FFFFFF" format
739+
func HexToRGB(hex string) color.RGBA {
740+
values, _ := strconv.ParseUint(string(hex[1:]), 16, 32)
741+
return color.RGBA{R: uint8(values >> 16), G: uint8((values >> 8) & 0xFF), B: uint8(values & 0xFF), A: 255}
742+
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ require (
2828

2929
require (
3030
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
31+
github.com/gookit/color v1.5.4 // indirect
3132
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
3233
github.com/rsteube/carapace-shlex v0.1.1 // indirect
3334
github.com/sagikazarmark/locafero v0.4.0 // indirect
3435
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
3536
github.com/sourcegraph/conc v0.3.0 // indirect
37+
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
3638
go.uber.org/atomic v1.11.0 // indirect
3739
go.uber.org/multierr v1.11.0 // indirect
3840
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,8 @@ github.com/googleapis/gax-go/v2 v2.6.0/go.mod h1:1mjbznJAPHFpesgE5ucqfYEscaz5kMd
597597
github.com/googleapis/gax-go/v2 v2.7.0/go.mod h1:TEop28CZZQ2y+c0VxMUmu1lV+fQx57QpBWsYpwqHJx8=
598598
github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4=
599599
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
600+
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
601+
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
600602
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
601603
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
602604
github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8=
@@ -878,6 +880,8 @@ github.com/xanzy/go-gitlab v0.83.0 h1:37p0MpTPNbsTMKX/JnmJtY8Ch1sFiJzVF342+RvZEG
878880
github.com/xanzy/go-gitlab v0.83.0/go.mod h1:5ryv+MnpZStBH8I/77HuQBsMbBGANtVpLWC15qOjWAw=
879881
github.com/xanzy/go-gitlab v0.95.2 h1:4p0IirHqEp5f0baK/aQqr4TR57IsD+8e4fuyAA1yi88=
880882
github.com/xanzy/go-gitlab v0.95.2/go.mod h1:ETg8tcj4OhrB84UEgeE8dSuV/0h4BBL1uOV/qK0vlyI=
883+
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
884+
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
881885
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
882886
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
883887
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

0 commit comments

Comments
 (0)