aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/gizak/termui/gauge.go
diff options
context:
space:
mode:
Diffstat (limited to 'Godeps/_workspace/src/github.com/gizak/termui/gauge.go')
-rw-r--r--Godeps/_workspace/src/github.com/gizak/termui/gauge.go90
1 files changed, 43 insertions, 47 deletions
diff --git a/Godeps/_workspace/src/github.com/gizak/termui/gauge.go b/Godeps/_workspace/src/github.com/gizak/termui/gauge.go
index 986f4f3dc..244d2995e 100644
--- a/Godeps/_workspace/src/github.com/gizak/termui/gauge.go
+++ b/Godeps/_workspace/src/github.com/gizak/termui/gauge.go
@@ -1,4 +1,4 @@
-// Copyright 2015 Zack Guo <gizak@icloud.com>. All rights reserved.
+// Copyright 2016 Zack Guo <gizak@icloud.com>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
@@ -21,33 +21,27 @@ import (
g.PercentColor = termui.ColorBlue
*/
-// Align is the position of the gauge's label.
-type Align int
-
-// All supported positions.
-const (
- AlignLeft Align = iota
- AlignCenter
- AlignRight
-)
+const ColorUndef Attribute = Attribute(^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: ThemeAttr("gauge.percent.fg"),
+ BarColor: ThemeAttr("gauge.bar.bg"),
+ Label: "{{percent}}%",
+ LabelAlign: AlignCenter,
+ PercentColorHighlighted: ColorUndef,
}
g.Width = 12
@@ -56,28 +50,26 @@ func NewGauge() *Gauge {
}
// Buffer implements Bufferer interface.
-func (g *Gauge) Buffer() []Point {
- ps := g.Block.Buffer()
+func (g *Gauge) Buffer() Buffer {
+ buf := g.Block.Buffer()
// plot bar
- w := g.Percent * g.innerWidth / 100
- for i := 0; i < g.innerHeight; i++ {
+ w := g.Percent * g.innerArea.Dx() / 100
+ for i := 0; i < g.innerArea.Dy(); i++ {
for j := 0; j < w; j++ {
- p := Point{}
- p.X = g.innerX + j
- p.Y = g.innerY + i
- p.Ch = ' '
- p.Bg = g.BarColor
- if p.Bg == ColorDefault {
- p.Bg |= AttrReverse
+ c := Cell{}
+ c.Ch = ' '
+ c.Bg = g.BarColor
+ if c.Bg == ColorDefault {
+ c.Bg |= AttrReverse
}
- ps = append(ps, p)
+ buf.Set(g.innerArea.Min.X+j, g.innerArea.Min.Y+i, c)
}
}
// plot percentage
s := strings.Replace(g.Label, "{{percent}}", strconv.Itoa(g.Percent), -1)
- pry := g.innerY + g.innerHeight/2
+ pry := g.innerArea.Min.Y + g.innerArea.Dy()/2
rs := str2runes(s)
var pos int
switch g.LabelAlign {
@@ -85,29 +77,33 @@ func (g *Gauge) Buffer() []Point {
pos = 0
case AlignCenter:
- pos = (g.innerWidth - strWidth(s)) / 2
+ pos = (g.innerArea.Dx() - strWidth(s)) / 2
case AlignRight:
- pos = g.innerWidth - strWidth(s)
+ pos = g.innerArea.Dx() - strWidth(s) - 1
}
+ pos += g.innerArea.Min.X
for i, v := range rs {
- p := Point{}
- p.X = 1 + pos + i
- p.Y = pry
- p.Ch = v
- p.Fg = g.PercentColor
- if w+g.innerX > pos+i {
- p.Bg = g.BarColor
- if p.Bg == ColorDefault {
- p.Bg |= AttrReverse
+ c := Cell{
+ Ch: v,
+ Fg: g.PercentColor,
+ }
+
+ if w+g.innerArea.Min.X > pos+i {
+ c.Bg = g.BarColor
+ if c.Bg == ColorDefault {
+ c.Bg |= AttrReverse
}
+ if g.PercentColorHighlighted != ColorUndef {
+ c.Fg = g.PercentColorHighlighted
+ }
} else {
- p.Bg = g.Block.BgColor
+ c.Bg = g.Block.Bg
}
- ps = append(ps, p)
+ buf.Set(1+pos+i, pry, c)
}
- return g.Block.chopOverflow(ps)
+ return buf
}