mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-15 02:01:43 +03:00
termui: add colors for labels
This commit is contained in:
parent
95b9bc94ff
commit
d0d9ea56b9
11
bug/label.go
11
bug/label.go
@ -50,6 +50,17 @@ func (l Label) RGBA() color.RGBA {
|
||||
return colors[id]
|
||||
}
|
||||
|
||||
func (l Label) Term256() int {
|
||||
rgba := l.RGBA()
|
||||
red := int(rgba.R) * 6 / 256
|
||||
green := int(rgba.G) * 6 / 256
|
||||
blue := int(rgba.B) * 6 / 256
|
||||
|
||||
color256 := red*36 + green*6 + blue + 16
|
||||
|
||||
return color256
|
||||
}
|
||||
|
||||
func (l Label) Validate() error {
|
||||
str := string(l)
|
||||
|
||||
|
@ -429,13 +429,14 @@ func (sb *showBug) renderSidebar(g *gocui.Gui, sideView *gocui.View) error {
|
||||
|
||||
labelStr := make([]string, len(snap.Labels))
|
||||
for i, l := range snap.Labels {
|
||||
labelStr[i] = string(l)
|
||||
color256 := l.Term256()
|
||||
labelStr[i] = fmt.Sprintf("\x1b[38;5;%dm◼\x1b[0m %s", color256, string(l))
|
||||
}
|
||||
|
||||
labels := strings.Join(labelStr, "\n")
|
||||
labels, lines := text.WrapLeftPadded(labels, maxX, 2)
|
||||
|
||||
content := fmt.Sprintf("%s\n\n%s", colors.Bold("Labels"), labels)
|
||||
content := fmt.Sprintf("%s\n\n%s", colors.Bold(" Labels"), labels)
|
||||
|
||||
v, err := sb.createSideView(g, "sideLabels", x0, y0, maxX, lines+2)
|
||||
if err != nil {
|
||||
|
@ -66,11 +66,12 @@ func Run(cache *cache.RepoCache) error {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func initGui(action func(ui *termUI) error) {
|
||||
g, err := gocui.NewGui(gocui.OutputNormal)
|
||||
g, err := gocui.NewGui(gocui.Output256)
|
||||
|
||||
if err != nil {
|
||||
ui.gError <- err
|
||||
|
Loading…
Reference in New Issue
Block a user