1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Merge branch 'betterbarcolor' of github.com:Seanstoppable/wtf into Seanstoppable-betterbarcolor

This commit is contained in:
Chris Cummer 2019-09-14 13:29:05 -07:00
commit 00acaa2165
4 changed files with 25 additions and 7 deletions

View File

@ -50,8 +50,9 @@ func MakeGraph(widget *Widget) {
barTime = barTime.Add(time.Duration(time.Minute)) barTime = barTime.Add(time.Duration(time.Minute))
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

View File

@ -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[:])

View File

@ -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
@ -75,12 +76,18 @@ func BuildStars(data []Bar, maxStars int, starChar string) string {
label = fmt.Sprint(bar.Percent) label = fmt.Sprint(bar.Percent)
} }
labelColor := bar.LabelColor
if labelColor == "" {
labelColor = "default"
}
//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[default]%s] %s\n",
bar.Label, bar.Label,
strings.Repeat(" ", longestLabel-len(bar.Label)), strings.Repeat(" ", longestLabel-len(bar.Label)),
labelColor,
strings.Repeat(starChar, starCount), strings.Repeat(starChar, starCount),
strings.Repeat(" ", maxStars-starCount), strings.Repeat(" ", maxStars-starCount),
label, label,

View File

@ -10,7 +10,7 @@ import (
func makeData() []Bar { func makeData() []Bar {
//this could come from config //this could come from config
const lineCount = 2 const lineCount = 3
var stats [lineCount]Bar var stats [lineCount]Bar
stats[0] = Bar{ stats[0] = Bar{
@ -19,8 +19,15 @@ func makeData() []Bar {
} }
stats[1] = Bar{ stats[1] = Bar{
Label: "Jul 09, 2018", Label: "Jul 09, 2018",
Percent: 80, Percent: 80,
LabelColor: "red",
}
stats[2] = Bar{
Label: "Jul 09, 2018",
Percent: 80,
LabelColor: "green",
} }
return stats[:] return stats[:]
@ -33,7 +40,7 @@ func TestOutput(t *testing.T) {
result := BuildStars(makeData(), 20, "*") result := BuildStars(makeData(), 20, "*")
Equal(t, Equal(t,
"Jun 27, 2018[[red]****[white] ] 20\nJul 09, 2018[[red]****************[white] ] 80\n", "Jun 27, 2018[[default]****[default] ] 20\nJul 09, 2018[[red]****************[default] ] 80\nJul 09, 2018[[green]****************[default] ] 80\n",
result, result,
) )
} }