From 275ea37a0113cca3b484b2bf29007ddd2714ae26 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 4 Aug 2019 22:10:00 -0700 Subject: [PATCH] Extract common attributes from BarGraph and TextWidget into Base --- view/bargraph.go | 37 +++++++++++++++---------------------- view/base.go | 20 ++++++++++++++++++++ view/text_widget.go | 35 +++++++++++++---------------------- 3 files changed, 48 insertions(+), 44 deletions(-) create mode 100644 view/base.go diff --git a/view/bargraph.go b/view/bargraph.go index cb44a30d..5b3854b4 100644 --- a/view/bargraph.go +++ b/view/bargraph.go @@ -12,19 +12,10 @@ import ( //BarGraph lets make graphs type BarGraph struct { - 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 + maxStars int + starChar string + Base View *tview.TextView } @@ -37,17 +28,19 @@ type Bar struct { // NewBarGraph initialize your fancy new graph func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common, focusable bool) BarGraph { widget := BarGraph{ - commonSettings: commonSettings, + Base: Base{ + app: app, + bordered: commonSettings.Bordered, + commonSettings: commonSettings, + enabled: commonSettings.Enabled, + focusable: focusable, + name: commonSettings.Title, + quitChan: make(chan bool), + refreshInterval: commonSettings.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", "|"), + maxStars: commonSettings.Config.UInt("graphStars", 20), + starChar: commonSettings.Config.UString("graphIcon", "|"), } widget.View = widget.addView() diff --git a/view/base.go b/view/base.go new file mode 100644 index 00000000..49377d5f --- /dev/null +++ b/view/base.go @@ -0,0 +1,20 @@ +package view + +import ( + "github.com/rivo/tview" + "github.com/wtfutil/wtf/cfg" +) + +type Base struct { + app *tview.Application + bordered bool + commonSettings *cfg.Common + enabled bool + focusChar string + focusable bool + key string + name string + quitChan chan bool + refreshing bool + refreshInterval int +} diff --git a/view/text_widget.go b/view/text_widget.go index fa106473..f6142b1f 100644 --- a/view/text_widget.go +++ b/view/text_widget.go @@ -10,33 +10,24 @@ import ( ) type TextWidget struct { - app *tview.Application - bordered bool - commonSettings *cfg.Common - enabled bool - focusChar string - focusable bool - name string - quitChan chan bool - refreshInterval int - refreshing bool - + Base View *tview.TextView } func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) TextWidget { widget := TextWidget{ - commonSettings: commonSettings, - - app: app, - bordered: commonSettings.Bordered, - enabled: commonSettings.Enabled, - focusChar: commonSettings.FocusChar(), - focusable: focusable, - name: commonSettings.Name, - quitChan: make(chan bool), - refreshInterval: commonSettings.RefreshInterval, - refreshing: false, + Base: Base{ + commonSettings: commonSettings, + app: app, + bordered: commonSettings.Bordered, + enabled: commonSettings.Enabled, + focusChar: commonSettings.FocusChar(), + focusable: focusable, + name: commonSettings.Name, + quitChan: make(chan bool), + refreshInterval: commonSettings.RefreshInterval, + refreshing: false, + }, } widget.View = widget.addView()