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:
parent
2ba50f2a73
commit
94d63306d4
@ -9,7 +9,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/view"
|
||||||
)
|
)
|
||||||
|
|
||||||
var started = false
|
var started = false
|
||||||
@ -17,7 +17,7 @@ var ok = true
|
|||||||
|
|
||||||
// Widget define wtf widget to register widget later
|
// Widget define wtf widget to register widget later
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
wtf.BarGraph
|
view.BarGraph
|
||||||
|
|
||||||
app *tview.Application
|
app *tview.Application
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ type Widget struct {
|
|||||||
// NewWidget Make new instance of widget
|
// NewWidget Make new instance of widget
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := 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,
|
app: app,
|
||||||
}
|
}
|
||||||
@ -43,13 +43,13 @@ func MakeGraph(widget *Widget) {
|
|||||||
|
|
||||||
//this could come from config
|
//this could come from config
|
||||||
const lineCount = 8
|
const lineCount = 8
|
||||||
var stats [lineCount]wtf.Bar
|
var stats [lineCount]view.Bar
|
||||||
|
|
||||||
barTime := time.Now()
|
barTime := time.Now()
|
||||||
for i := 0; i < lineCount; i++ {
|
for i := 0; i < lineCount; i++ {
|
||||||
barTime = barTime.Add(time.Duration(time.Minute))
|
barTime = barTime.Add(time.Duration(time.Minute))
|
||||||
|
|
||||||
bar := wtf.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,
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
package resourceusage
|
package resourceusage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.cloudfoundry.org/bytefmt"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.cloudfoundry.org/bytefmt"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/shirou/gopsutil/cpu"
|
"github.com/shirou/gopsutil/cpu"
|
||||||
"github.com/shirou/gopsutil/mem"
|
"github.com/shirou/gopsutil/mem"
|
||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/view"
|
||||||
"math"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var started = false
|
var started = false
|
||||||
@ -16,7 +17,7 @@ var ok = true
|
|||||||
|
|
||||||
// Widget define wtf widget to register widget later
|
// Widget define wtf widget to register widget later
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
wtf.BarGraph
|
view.BarGraph
|
||||||
|
|
||||||
app *tview.Application
|
app *tview.Application
|
||||||
settings *Settings
|
settings *Settings
|
||||||
@ -25,7 +26,7 @@ type Widget struct {
|
|||||||
// NewWidget Make new instance of widget
|
// NewWidget Make new instance of widget
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
widget := 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,
|
app: app,
|
||||||
settings: settings,
|
settings: settings,
|
||||||
@ -46,14 +47,14 @@ func MakeGraph(widget *Widget) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var stats = make([]wtf.Bar, len(cpuStats)+2)
|
var stats = make([]view.Bar, len(cpuStats)+2)
|
||||||
|
|
||||||
for i, stat := range cpuStats {
|
for i, stat := range cpuStats {
|
||||||
// Stats sometimes jump outside the 0-100 range, possibly due to timing
|
// Stats sometimes jump outside the 0-100 range, possibly due to timing
|
||||||
stat = math.Min(100, stat)
|
stat = math.Min(100, stat)
|
||||||
stat = math.Max(0, stat)
|
stat = math.Max(0, stat)
|
||||||
|
|
||||||
bar := wtf.Bar{
|
bar := view.Bar{
|
||||||
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)),
|
||||||
@ -76,7 +77,7 @@ func MakeGraph(widget *Widget) {
|
|||||||
usedMemLabel = usedMemLabel[:len(usedMemLabel)-1]
|
usedMemLabel = usedMemLabel[:len(usedMemLabel)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
stats[memIndex] = wtf.Bar{
|
stats[memIndex] = view.Bar{
|
||||||
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),
|
||||||
@ -96,7 +97,7 @@ func MakeGraph(widget *Widget) {
|
|||||||
usedSwapLabel = usedSwapLabel[:len(usedSwapLabel)-1]
|
usedSwapLabel = usedSwapLabel[:len(usedSwapLabel)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
stats[swapIndex] = wtf.Bar{
|
stats[swapIndex] = view.Bar{
|
||||||
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),
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package wtf
|
package view
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/cfg"
|
"github.com/wtfutil/wtf/cfg"
|
||||||
|
"github.com/wtfutil/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
//BarGraph lets make graphs
|
//BarGraph lets make graphs
|
||||||
@ -185,12 +186,12 @@ func BuildStars(data []Bar, maxStars int, starChar string) string {
|
|||||||
func (widget *BarGraph) addView() *tview.TextView {
|
func (widget *BarGraph) addView() *tview.TextView {
|
||||||
view := tview.NewTextView()
|
view := tview.NewTextView()
|
||||||
|
|
||||||
view.SetBackgroundColor(ColorFor(widget.commonSettings.Colors.Background))
|
view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background))
|
||||||
view.SetBorder(true)
|
view.SetBorder(true)
|
||||||
view.SetBorderColor(ColorFor(widget.BorderColor()))
|
view.SetBorderColor(wtf.ColorFor(widget.BorderColor()))
|
||||||
view.SetDynamicColors(true)
|
view.SetDynamicColors(true)
|
||||||
view.SetTitle(widget.Name())
|
view.SetTitle(widget.Name())
|
||||||
view.SetTitleColor(ColorFor(widget.commonSettings.Colors.Title))
|
view.SetTitleColor(wtf.ColorFor(widget.commonSettings.Colors.Title))
|
||||||
view.SetWrap(false)
|
view.SetWrap(false)
|
||||||
|
|
||||||
return view
|
return view
|
@ -1,4 +1,4 @@
|
|||||||
package wtf
|
package view
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
Loading…
x
Reference in New Issue
Block a user