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

updated with suggestions from @senorprogrammer

This commit is contained in:
Bill 2018-06-06 11:31:52 -07:00
parent 56158d2e93
commit 540dee04d7
3 changed files with 18 additions and 17 deletions

View File

@ -17,7 +17,7 @@ var ok = true
// Widget define wtf widget to register widget later
type Widget struct {
wtf.GraphWidget
wtf.BarGraph
// time interval for send http request
updateInterval int
@ -26,7 +26,7 @@ type Widget struct {
// NewWidget Make new instance of widget
func NewWidget() *Widget {
widget := Widget{
GraphWidget: wtf.NewGraphWidget(" Bar Graph", "bargraph", false),
BarGraph: wtf.NewBarGraph(" Bar Graph", "bargraph", false),
}
widget.View.SetWrap(true)
@ -51,7 +51,7 @@ func MakeGraph(widget *Widget) {
}
widget.GraphWidget.BuildBars(20, "🌟", stats[:])
widget.BarGraph.BuildBars(20, "🌟", stats[:])
}

2
wtf.go
View File

@ -6,12 +6,12 @@ import (
"os"
"time"
"github.com/BillKeenan/wtf/bargraph"
"github.com/gdamore/tcell"
"github.com/olebedev/config"
"github.com/radovskyb/watcher"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/bamboohr"
"github.com/senorprogrammer/wtf/bargraph"
"github.com/senorprogrammer/wtf/clocks"
"github.com/senorprogrammer/wtf/cmdrunner"
"github.com/senorprogrammer/wtf/cryptoexchanges/bittrex"

View File

@ -9,7 +9,8 @@ import (
"github.com/rivo/tview"
)
type GraphWidget struct {
//BarGraph lets make graphs
type BarGraph struct {
enabled bool
focusable bool
@ -23,9 +24,9 @@ type GraphWidget struct {
Data [][2]int64
}
// NewGraphWidget initialize your fancy new graph
func NewGraphWidget(name string, configKey string, focusable bool) GraphWidget {
widget := GraphWidget{
// NewBarGraph initialize your fancy new graph
func NewBarGraph(name string, configKey string, focusable bool) BarGraph {
widget := BarGraph{
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
focusable: focusable,
@ -45,7 +46,7 @@ func NewGraphWidget(name string, configKey string, focusable bool) GraphWidget {
return widget
}
func (widget *GraphWidget) BorderColor() string {
func (widget *BarGraph) BorderColor() string {
if widget.Focusable() {
return Config.UString("wtf.colors.border.focusable", "red")
}
@ -53,33 +54,33 @@ func (widget *GraphWidget) BorderColor() string {
return Config.UString("wtf.colors.border.normal", "gray")
}
func (widget *GraphWidget) Disabled() bool {
func (widget *BarGraph) Disabled() bool {
return !widget.Enabled()
}
func (widget *GraphWidget) Enabled() bool {
func (widget *BarGraph) Enabled() bool {
return widget.enabled
}
func (widget *GraphWidget) Focusable() bool {
func (widget *BarGraph) Focusable() bool {
return widget.enabled && widget.focusable
}
func (widget *GraphWidget) RefreshInterval() int {
func (widget *BarGraph) RefreshInterval() int {
return widget.RefreshInt
}
func (widget *GraphWidget) TextView() *tview.TextView {
func (widget *BarGraph) TextView() *tview.TextView {
return widget.View
}
/* -------------------- Unexported Functions -------------------- */
func (widget *GraphWidget) UpdateRefreshedAt() {
func (widget *BarGraph) UpdateRefreshedAt() {
widget.RefreshedAt = time.Now()
}
func (widget *GraphWidget) addView() {
func (widget *BarGraph) addView() {
view := tview.NewTextView()
view.SetBackgroundColor(ColorFor(Config.UString("wtf.colors.background", "black")))
@ -94,7 +95,7 @@ func (widget *GraphWidget) addView() {
// BuildBars will build a string of * to represent your data of [time][value]
// time should be passed as a int64
func (widget *GraphWidget) BuildBars(maxStars int, starChar string, data [][2]int64) {
func (widget *BarGraph) BuildBars(maxStars int, starChar string, data [][2]int64) {
var buffer bytes.Buffer