Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gauge percentage color fix #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions _test/gaugeTest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main

import (
"log"
"time"
ui "github.com/gizak/termui"
"github.com/gizak/termui/widgets"
)

func main() {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()

colors := make([]ui.Color, 6)
colors[0] = ui.ColorGreen
colors[1] = ui.ColorBlue
colors[2] = ui.ColorMagenta
colors[3] = ui.ColorCyan
colors[4] = ui.ColorWhite
colors[5] = ui.ColorRed

g := widgets.NewGauge()
g.Title = "Gauge"
g.SetRect(0, 12, 50, 15)
g.BarColor = ui.ColorBlue
g.BorderStyle.Fg = ui.ColorWhite
g.TitleStyle.Fg = ui.ColorCyan
g.LabelStyle.Fg = colors[0]

tickerCount := 1
ui.Render(g)
tickerCount++
uiEvents := ui.PollEvents()
ticker := time.NewTicker(50 * time.Millisecond).C
colorCnt := 0
for {
select {
case e := <-uiEvents:
switch e.ID {
case "q", "<C-c>":
return
}
case <-ticker:
ui.Render(g)
g.Percent = tickerCount % 101
if tickerCount % 101 == 0 {
colorCnt++
if colorCnt == 6 {
colorCnt = 0
}
g.LabelStyle.Fg = colors[colorCnt]
}
tickerCount++
}
}

return
}
2 changes: 1 addition & 1 deletion widgets/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (self *Gauge) Draw(buf *Buffer) {
for i, char := range label {
style := self.LabelStyle
if labelXCoordinate+i+1 <= self.Inner.Min.X+barWidth {
style = NewStyle(self.BarColor, ColorClear, ModifierReverse)
style.Bg = self.BarColor
}
buf.SetCell(NewCell(char, style), image.Pt(labelXCoordinate+i, labelYCoordinate))
}
Expand Down