From 98eb3c9013b526d89b217fdfbfab758b39293baa Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 4 Aug 2019 22:02:14 -0700 Subject: [PATCH] Bring BarGraph constructor up to parity with TextWidget --- view/bargraph.go | 50 +++++++++++++++++++++++---------------------- view/text_widget.go | 10 ++++----- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/view/bargraph.go b/view/bargraph.go index c2f85548..cb44a30d 100644 --- a/view/bargraph.go +++ b/view/bargraph.go @@ -12,18 +12,20 @@ import ( //BarGraph lets make graphs type BarGraph struct { - commonSettings *cfg.Common - enabled bool - focusable bool - key string - maxStars int - name string - quitChan chan bool - refreshing bool - starChar string + app *tview.Application + bordered bool + commonSettings *cfg.Common + enabled bool + focusable bool + key string + maxStars int + name string + quitChan chan bool + refreshing bool + refreshInterval int + starChar string - RefreshInt int - View *tview.TextView + View *tview.TextView } type Bar struct { @@ -33,23 +35,23 @@ type Bar struct { } // NewBarGraph initialize your fancy new graph -func NewBarGraph(app *tview.Application, name string, settings *cfg.Common, focusable bool) BarGraph { +func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common, focusable bool) BarGraph { widget := BarGraph{ - enabled: settings.Enabled, - focusable: focusable, - maxStars: settings.Config.UInt("graphStars", 20), - name: settings.Title, - quitChan: make(chan bool), - starChar: settings.Config.UString("graphIcon", "|"), - commonSettings: settings, + commonSettings: commonSettings, - RefreshInt: settings.RefreshInterval, + app: app, + bordered: commonSettings.Bordered, + enabled: commonSettings.Enabled, + focusable: focusable, + maxStars: commonSettings.Config.UInt("graphStars", 20), + name: commonSettings.Title, + quitChan: make(chan bool), + refreshInterval: commonSettings.RefreshInterval, + starChar: commonSettings.Config.UString("graphIcon", "|"), } widget.View = widget.addView() - widget.View.SetChangedFunc(func() { - app.Draw() - }) + widget.View.SetBorder(widget.bordered) return widget } @@ -105,7 +107,7 @@ func (widget *BarGraph) Refreshing() bool { // RefreshInterval returns how often, in seconds, the widget will return its data func (widget *BarGraph) RefreshInterval() int { - return widget.RefreshInt + return widget.refreshInterval } func (widget *BarGraph) SetFocusChar(char string) { diff --git a/view/text_widget.go b/view/text_widget.go index f71a8a4d..fa106473 100644 --- a/view/text_widget.go +++ b/view/text_widget.go @@ -10,16 +10,16 @@ import ( ) type TextWidget struct { + app *tview.Application bordered bool commonSettings *cfg.Common enabled bool - focusable bool focusChar string + focusable bool name string quitChan chan bool - refreshing bool refreshInterval int - app *tview.Application + refreshing bool View *tview.TextView } @@ -31,12 +31,12 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable app: app, bordered: commonSettings.Bordered, enabled: commonSettings.Enabled, - focusable: focusable, focusChar: commonSettings.FocusChar(), + focusable: focusable, name: commonSettings.Name, quitChan: make(chan bool), - refreshing: false, refreshInterval: commonSettings.RefreshInterval, + refreshing: false, } widget.View = widget.addView()