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:
parent
56158d2e93
commit
540dee04d7
@ -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.GraphWidget
|
wtf.BarGraph
|
||||||
|
|
||||||
// time interval for send http request
|
// time interval for send http request
|
||||||
updateInterval int
|
updateInterval int
|
||||||
@ -26,7 +26,7 @@ type Widget struct {
|
|||||||
// NewWidget Make new instance of widget
|
// NewWidget Make new instance of widget
|
||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
GraphWidget: wtf.NewGraphWidget(" Bar Graph", "bargraph", false),
|
BarGraph: wtf.NewBarGraph(" Bar Graph", "bargraph", false),
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.View.SetWrap(true)
|
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
2
wtf.go
@ -6,12 +6,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/BillKeenan/wtf/bargraph"
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
"github.com/olebedev/config"
|
"github.com/olebedev/config"
|
||||||
"github.com/radovskyb/watcher"
|
"github.com/radovskyb/watcher"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/senorprogrammer/wtf/bamboohr"
|
"github.com/senorprogrammer/wtf/bamboohr"
|
||||||
|
"github.com/senorprogrammer/wtf/bargraph"
|
||||||
"github.com/senorprogrammer/wtf/clocks"
|
"github.com/senorprogrammer/wtf/clocks"
|
||||||
"github.com/senorprogrammer/wtf/cmdrunner"
|
"github.com/senorprogrammer/wtf/cmdrunner"
|
||||||
"github.com/senorprogrammer/wtf/cryptoexchanges/bittrex"
|
"github.com/senorprogrammer/wtf/cryptoexchanges/bittrex"
|
||||||
|
@ -9,7 +9,8 @@ import (
|
|||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GraphWidget struct {
|
//BarGraph lets make graphs
|
||||||
|
type BarGraph struct {
|
||||||
enabled bool
|
enabled bool
|
||||||
focusable bool
|
focusable bool
|
||||||
|
|
||||||
@ -23,9 +24,9 @@ type GraphWidget struct {
|
|||||||
Data [][2]int64
|
Data [][2]int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGraphWidget initialize your fancy new graph
|
// NewBarGraph initialize your fancy new graph
|
||||||
func NewGraphWidget(name string, configKey string, focusable bool) GraphWidget {
|
func NewBarGraph(name string, configKey string, focusable bool) BarGraph {
|
||||||
widget := GraphWidget{
|
widget := BarGraph{
|
||||||
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
|
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
|
||||||
focusable: focusable,
|
focusable: focusable,
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ func NewGraphWidget(name string, configKey string, focusable bool) GraphWidget {
|
|||||||
return widget
|
return widget
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *GraphWidget) BorderColor() string {
|
func (widget *BarGraph) BorderColor() string {
|
||||||
if widget.Focusable() {
|
if widget.Focusable() {
|
||||||
return Config.UString("wtf.colors.border.focusable", "red")
|
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")
|
return Config.UString("wtf.colors.border.normal", "gray")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *GraphWidget) Disabled() bool {
|
func (widget *BarGraph) Disabled() bool {
|
||||||
return !widget.Enabled()
|
return !widget.Enabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *GraphWidget) Enabled() bool {
|
func (widget *BarGraph) Enabled() bool {
|
||||||
return widget.enabled
|
return widget.enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *GraphWidget) Focusable() bool {
|
func (widget *BarGraph) Focusable() bool {
|
||||||
return widget.enabled && widget.focusable
|
return widget.enabled && widget.focusable
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *GraphWidget) RefreshInterval() int {
|
func (widget *BarGraph) RefreshInterval() int {
|
||||||
return widget.RefreshInt
|
return widget.RefreshInt
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *GraphWidget) TextView() *tview.TextView {
|
func (widget *BarGraph) TextView() *tview.TextView {
|
||||||
return widget.View
|
return widget.View
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *GraphWidget) UpdateRefreshedAt() {
|
func (widget *BarGraph) UpdateRefreshedAt() {
|
||||||
widget.RefreshedAt = time.Now()
|
widget.RefreshedAt = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *GraphWidget) addView() {
|
func (widget *BarGraph) addView() {
|
||||||
view := tview.NewTextView()
|
view := tview.NewTextView()
|
||||||
|
|
||||||
view.SetBackgroundColor(ColorFor(Config.UString("wtf.colors.background", "black")))
|
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]
|
// BuildBars will build a string of * to represent your data of [time][value]
|
||||||
// time should be passed as a int64
|
// 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
|
var buffer bytes.Buffer
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user