mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Improve bargraph view so bar colors are configurable
Inspired by #624 Update the view object so that widget developers can configure bar color
This commit is contained in:
parent
8cf50fe92c
commit
56975bc80a
@ -52,6 +52,7 @@ func MakeGraph(widget *Widget) {
|
|||||||
bar := view.Bar{
|
bar := view.Bar{
|
||||||
Label: barTime.Format("15:04"),
|
Label: barTime.Format("15:04"),
|
||||||
Percent: rand.Intn(100-5) + 5,
|
Percent: rand.Intn(100-5) + 5,
|
||||||
|
LabelColor: "red",
|
||||||
}
|
}
|
||||||
|
|
||||||
stats[i] = bar
|
stats[i] = bar
|
||||||
|
@ -58,6 +58,7 @@ func MakeGraph(widget *Widget) {
|
|||||||
Label: fmt.Sprint(i),
|
Label: fmt.Sprint(i),
|
||||||
Percent: int(stat),
|
Percent: int(stat),
|
||||||
ValueLabel: fmt.Sprintf("%d%%", int(stat)),
|
ValueLabel: fmt.Sprintf("%d%%", int(stat)),
|
||||||
|
LabelColor: "red",
|
||||||
}
|
}
|
||||||
|
|
||||||
stats[i] = bar
|
stats[i] = bar
|
||||||
@ -81,6 +82,7 @@ func MakeGraph(widget *Widget) {
|
|||||||
Label: "Mem",
|
Label: "Mem",
|
||||||
Percent: int(memInfo.UsedPercent),
|
Percent: int(memInfo.UsedPercent),
|
||||||
ValueLabel: fmt.Sprintf("%s/%s", usedMemLabel, totalMemLabel),
|
ValueLabel: fmt.Sprintf("%s/%s", usedMemLabel, totalMemLabel),
|
||||||
|
LabelColor: "green",
|
||||||
}
|
}
|
||||||
|
|
||||||
swapIndex := len(cpuStats) + 1
|
swapIndex := len(cpuStats) + 1
|
||||||
@ -101,6 +103,7 @@ func MakeGraph(widget *Widget) {
|
|||||||
Label: "Swp",
|
Label: "Swp",
|
||||||
Percent: int(swapPercent * 100),
|
Percent: int(swapPercent * 100),
|
||||||
ValueLabel: fmt.Sprintf("%s/%s", usedSwapLabel, totalSwapLabel),
|
ValueLabel: fmt.Sprintf("%s/%s", usedSwapLabel, totalSwapLabel),
|
||||||
|
LabelColor: "yellow",
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.BarGraph.BuildBars(stats[:])
|
widget.BarGraph.BuildBars(stats[:])
|
||||||
|
@ -24,6 +24,7 @@ type Bar struct {
|
|||||||
Label string
|
Label string
|
||||||
Percent int
|
Percent int
|
||||||
ValueLabel string
|
ValueLabel string
|
||||||
|
LabelColor string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBarGraph creates and returns an instance of BarGraph
|
// NewBarGraph creates and returns an instance of BarGraph
|
||||||
@ -78,9 +79,10 @@ func BuildStars(data []Bar, maxStars int, starChar string) string {
|
|||||||
//write the line
|
//write the line
|
||||||
buffer.WriteString(
|
buffer.WriteString(
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"%s%s[[red]%s[white]%s] %s\n",
|
"%s%s[[%s]%s[white]%s] %s\n",
|
||||||
bar.Label,
|
bar.Label,
|
||||||
strings.Repeat(" ", longestLabel-len(bar.Label)),
|
strings.Repeat(" ", longestLabel-len(bar.Label)),
|
||||||
|
bar.LabelColor,
|
||||||
strings.Repeat(starChar, starCount),
|
strings.Repeat(starChar, starCount),
|
||||||
strings.Repeat(" ", maxStars-starCount),
|
strings.Repeat(" ", maxStars-starCount),
|
||||||
label,
|
label,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user