diff --git a/example/gauge.go b/example/gauge.go index b703358..91bc47b 100644 --- a/example/gauge.go +++ b/example/gauge.go @@ -56,7 +56,18 @@ func main() { g3.Label = "{{percent}}% (100MBs free)" g3.LabelAlign = termui.AlignRight - termui.Render(g0, g1, g2, g3) + g4 := termui.NewGauge() + g4.Percent = 50 + g4.Width = 50 + g4.Height = 3 + g4.Y = 14 + g4.Border.Label = "Gauge" + g4.Label = "Gauge with custom highlighted label" + g4.PercentColor = termui.ColorYellow + g4.BarColor = termui.ColorGreen + g4.PercentColorHighlighted = termui.ColorBlack + + termui.Render(g0, g1, g2, g3, g4) <-termui.EventCh() } diff --git a/example/gauge.png b/example/gauge.png index 5c20e6e..f7db47c 100644 Binary files a/example/gauge.png and b/example/gauge.png differ diff --git a/gauge.go b/gauge.go index b9d7447..c27a65c 100644 --- a/gauge.go +++ b/gauge.go @@ -31,23 +31,27 @@ const ( AlignRight ) +const uint16max = ^uint16(0) + type Gauge struct { Block - Percent int - BarColor Attribute - PercentColor Attribute - Label string - LabelAlign Align + Percent int + BarColor Attribute + PercentColor Attribute + PercentColorHighlighted Attribute + Label string + LabelAlign Align } // NewGauge return a new gauge with current theme. func NewGauge() *Gauge { g := &Gauge{ - Block: *NewBlock(), - PercentColor: theme.GaugePercent, - BarColor: theme.GaugeBar, - Label: "{{percent}}%", - LabelAlign: AlignCenter, + Block: *NewBlock(), + PercentColor: theme.GaugePercent, + BarColor: theme.GaugeBar, + Label: "{{percent}}%", + LabelAlign: AlignCenter, + PercentColorHighlighted: Attribute(uint16max), } g.Width = 12 @@ -104,6 +108,9 @@ func (g *Gauge) Buffer() []Point { p.Bg |= AttrReverse } + if g.PercentColorHighlighted != Attribute(uint16max) { + p.Fg = g.PercentColorHighlighted + } } else { p.Bg = g.Block.BgColor }