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

Move Bargraph functionality into /view

This commit is contained in:
Chris Cummer 2019-08-04 21:21:16 -07:00
parent 2ba50f2a73
commit 94d63306d4
4 changed files with 22 additions and 20 deletions

View File

@ -9,7 +9,7 @@ import (
"math/rand"
"time"
"github.com/wtfutil/wtf/wtf"
"github.com/wtfutil/wtf/view"
)
var started = false
@ -17,7 +17,7 @@ var ok = true
// Widget define wtf widget to register widget later
type Widget struct {
wtf.BarGraph
view.BarGraph
app *tview.Application
}
@ -25,7 +25,7 @@ type Widget struct {
// NewWidget Make new instance of widget
func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{
BarGraph: wtf.NewBarGraph(app, "Sample Bar Graph", settings.common, false),
BarGraph: view.NewBarGraph(app, "Sample Bar Graph", settings.common, false),
app: app,
}
@ -43,13 +43,13 @@ func MakeGraph(widget *Widget) {
//this could come from config
const lineCount = 8
var stats [lineCount]wtf.Bar
var stats [lineCount]view.Bar
barTime := time.Now()
for i := 0; i < lineCount; i++ {
barTime = barTime.Add(time.Duration(time.Minute))
bar := wtf.Bar{
bar := view.Bar{
Label: barTime.Format("15:04"),
Percent: rand.Intn(100-5) + 5,
}

View File

@ -1,14 +1,15 @@
package resourceusage
import (
"code.cloudfoundry.org/bytefmt"
"fmt"
"math"
"time"
"code.cloudfoundry.org/bytefmt"
"github.com/rivo/tview"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/mem"
"github.com/wtfutil/wtf/wtf"
"math"
"time"
"github.com/wtfutil/wtf/view"
)
var started = false
@ -16,7 +17,7 @@ var ok = true
// Widget define wtf widget to register widget later
type Widget struct {
wtf.BarGraph
view.BarGraph
app *tview.Application
settings *Settings
@ -25,7 +26,7 @@ type Widget struct {
// NewWidget Make new instance of widget
func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{
BarGraph: wtf.NewBarGraph(app, settings.common.Name, settings.common, false),
BarGraph: view.NewBarGraph(app, settings.common.Name, settings.common, false),
app: app,
settings: settings,
@ -46,14 +47,14 @@ func MakeGraph(widget *Widget) {
return
}
var stats = make([]wtf.Bar, len(cpuStats)+2)
var stats = make([]view.Bar, len(cpuStats)+2)
for i, stat := range cpuStats {
// Stats sometimes jump outside the 0-100 range, possibly due to timing
stat = math.Min(100, stat)
stat = math.Max(0, stat)
bar := wtf.Bar{
bar := view.Bar{
Label: fmt.Sprint(i),
Percent: int(stat),
ValueLabel: fmt.Sprintf("%d%%", int(stat)),
@ -76,7 +77,7 @@ func MakeGraph(widget *Widget) {
usedMemLabel = usedMemLabel[:len(usedMemLabel)-1]
}
stats[memIndex] = wtf.Bar{
stats[memIndex] = view.Bar{
Label: "Mem",
Percent: int(memInfo.UsedPercent),
ValueLabel: fmt.Sprintf("%s/%s", usedMemLabel, totalMemLabel),
@ -96,7 +97,7 @@ func MakeGraph(widget *Widget) {
usedSwapLabel = usedSwapLabel[:len(usedSwapLabel)-1]
}
stats[swapIndex] = wtf.Bar{
stats[swapIndex] = view.Bar{
Label: "Swp",
Percent: int(swapPercent * 100),
ValueLabel: fmt.Sprintf("%s/%s", usedSwapLabel, totalSwapLabel),

View File

@ -1,4 +1,4 @@
package wtf
package view
import (
"bytes"
@ -7,6 +7,7 @@ import (
"github.com/rivo/tview"
"github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/wtf"
)
//BarGraph lets make graphs
@ -185,12 +186,12 @@ func BuildStars(data []Bar, maxStars int, starChar string) string {
func (widget *BarGraph) addView() *tview.TextView {
view := tview.NewTextView()
view.SetBackgroundColor(ColorFor(widget.commonSettings.Colors.Background))
view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background))
view.SetBorder(true)
view.SetBorderColor(ColorFor(widget.BorderColor()))
view.SetBorderColor(wtf.ColorFor(widget.BorderColor()))
view.SetDynamicColors(true)
view.SetTitle(widget.Name())
view.SetTitleColor(ColorFor(widget.commonSettings.Colors.Title))
view.SetTitleColor(wtf.ColorFor(widget.commonSettings.Colors.Title))
view.SetWrap(false)
return view

View File

@ -1,4 +1,4 @@
package wtf
package view
import (
"testing"