From 2ba50f2a735a02e0da5256591f61ffae6eef19d1 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 4 Aug 2019 21:12:14 -0700 Subject: [PATCH 1/9] Move WidgetMaker functionality into /app --- {maker => app}/widget_maker.go | 2 +- app/wtf_app.go | 3 +-- help/help.go | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) rename {maker => app}/widget_maker.go (99%) diff --git a/maker/widget_maker.go b/app/widget_maker.go similarity index 99% rename from maker/widget_maker.go rename to app/widget_maker.go index cb11cba5..cdde17cd 100644 --- a/maker/widget_maker.go +++ b/app/widget_maker.go @@ -1,4 +1,4 @@ -package maker +package app import ( "github.com/olebedev/config" diff --git a/app/wtf_app.go b/app/wtf_app.go index ecbe8dff..3dbb8e37 100644 --- a/app/wtf_app.go +++ b/app/wtf_app.go @@ -9,7 +9,6 @@ import ( "github.com/radovskyb/watcher" "github.com/rivo/tview" "github.com/wtfutil/wtf/cfg" - "github.com/wtfutil/wtf/maker" "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/wtf" ) @@ -39,7 +38,7 @@ func NewWtfApp(app *tview.Application, config *config.Config, configFilePath str } wtfApp.app.SetInputCapture(wtfApp.keyboardIntercept) - wtfApp.widgets = maker.MakeWidgets(wtfApp.app, wtfApp.pages, wtfApp.config) + wtfApp.widgets = MakeWidgets(wtfApp.app, wtfApp.pages, wtfApp.config) wtfApp.display = NewDisplay(wtfApp.widgets, wtfApp.config) wtfApp.focusTracker = NewFocusTracker(wtfApp.app, wtfApp.widgets, wtfApp.config) wtfApp.validator = NewModuleValidator() diff --git a/help/help.go b/help/help.go index d753f5bd..ccc1cbb9 100644 --- a/help/help.go +++ b/help/help.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/olebedev/config" - "github.com/wtfutil/wtf/maker" + "github.com/wtfutil/wtf/app" "github.com/wtfutil/wtf/utils" ) @@ -18,7 +18,7 @@ func Display(moduleName string, config *config.Config) { } func helpFor(moduleName string, config *config.Config) string { - widget := maker.MakeWidget(nil, nil, moduleName, config) + widget := app.MakeWidget(nil, nil, moduleName, config) result := "" result += utils.StripColorTags(widget.HelpText()) From 94d63306d4c536af4e4bfe2b11b5d6208c4855f9 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 4 Aug 2019 21:21:16 -0700 Subject: [PATCH 2/9] Move Bargraph functionality into /view --- modules/bargraph/widget.go | 10 +++++----- modules/resourceusage/widget.go | 21 +++++++++++---------- {wtf => view}/bargraph.go | 9 +++++---- {wtf => view}/bargraph_test.go | 2 +- 4 files changed, 22 insertions(+), 20 deletions(-) rename {wtf => view}/bargraph.go (94%) rename {wtf => view}/bargraph_test.go (97%) diff --git a/modules/bargraph/widget.go b/modules/bargraph/widget.go index cb9d4bc8..42e98c72 100644 --- a/modules/bargraph/widget.go +++ b/modules/bargraph/widget.go @@ -9,7 +9,7 @@ import ( "math/rand" "time" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) var started = false @@ -17,7 +17,7 @@ var ok = true // Widget define wtf widget to register widget later type Widget struct { - wtf.BarGraph + view.BarGraph app *tview.Application } @@ -25,7 +25,7 @@ type Widget struct { // NewWidget Make new instance of widget func NewWidget(app *tview.Application, settings *Settings) *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, } @@ -43,13 +43,13 @@ func MakeGraph(widget *Widget) { //this could come from config const lineCount = 8 - var stats [lineCount]wtf.Bar + var stats [lineCount]view.Bar barTime := time.Now() for i := 0; i < lineCount; i++ { barTime = barTime.Add(time.Duration(time.Minute)) - bar := wtf.Bar{ + bar := view.Bar{ Label: barTime.Format("15:04"), Percent: rand.Intn(100-5) + 5, } diff --git a/modules/resourceusage/widget.go b/modules/resourceusage/widget.go index dd676297..bfdf55d9 100644 --- a/modules/resourceusage/widget.go +++ b/modules/resourceusage/widget.go @@ -1,14 +1,15 @@ package resourceusage import ( - "code.cloudfoundry.org/bytefmt" "fmt" + "math" + "time" + + "code.cloudfoundry.org/bytefmt" "github.com/rivo/tview" "github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/mem" - "github.com/wtfutil/wtf/wtf" - "math" - "time" + "github.com/wtfutil/wtf/view" ) var started = false @@ -16,7 +17,7 @@ var ok = true // Widget define wtf widget to register widget later type Widget struct { - wtf.BarGraph + view.BarGraph app *tview.Application settings *Settings @@ -25,7 +26,7 @@ type Widget struct { // NewWidget Make new instance of widget func NewWidget(app *tview.Application, settings *Settings) *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, settings: settings, @@ -46,14 +47,14 @@ func MakeGraph(widget *Widget) { return } - var stats = make([]wtf.Bar, len(cpuStats)+2) + var stats = make([]view.Bar, len(cpuStats)+2) for i, stat := range cpuStats { // Stats sometimes jump outside the 0-100 range, possibly due to timing stat = math.Min(100, stat) stat = math.Max(0, stat) - bar := wtf.Bar{ + bar := view.Bar{ Label: fmt.Sprint(i), Percent: int(stat), ValueLabel: fmt.Sprintf("%d%%", int(stat)), @@ -76,7 +77,7 @@ func MakeGraph(widget *Widget) { usedMemLabel = usedMemLabel[:len(usedMemLabel)-1] } - stats[memIndex] = wtf.Bar{ + stats[memIndex] = view.Bar{ Label: "Mem", Percent: int(memInfo.UsedPercent), ValueLabel: fmt.Sprintf("%s/%s", usedMemLabel, totalMemLabel), @@ -96,7 +97,7 @@ func MakeGraph(widget *Widget) { usedSwapLabel = usedSwapLabel[:len(usedSwapLabel)-1] } - stats[swapIndex] = wtf.Bar{ + stats[swapIndex] = view.Bar{ Label: "Swp", Percent: int(swapPercent * 100), ValueLabel: fmt.Sprintf("%s/%s", usedSwapLabel, totalSwapLabel), diff --git a/wtf/bargraph.go b/view/bargraph.go similarity index 94% rename from wtf/bargraph.go rename to view/bargraph.go index ac827524..c2f85548 100644 --- a/wtf/bargraph.go +++ b/view/bargraph.go @@ -1,4 +1,4 @@ -package wtf +package view import ( "bytes" @@ -7,6 +7,7 @@ import ( "github.com/rivo/tview" "github.com/wtfutil/wtf/cfg" + "github.com/wtfutil/wtf/wtf" ) //BarGraph lets make graphs @@ -185,12 +186,12 @@ func BuildStars(data []Bar, maxStars int, starChar string) string { func (widget *BarGraph) addView() *tview.TextView { view := tview.NewTextView() - view.SetBackgroundColor(ColorFor(widget.commonSettings.Colors.Background)) + view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background)) view.SetBorder(true) - view.SetBorderColor(ColorFor(widget.BorderColor())) + view.SetBorderColor(wtf.ColorFor(widget.BorderColor())) view.SetDynamicColors(true) view.SetTitle(widget.Name()) - view.SetTitleColor(ColorFor(widget.commonSettings.Colors.Title)) + view.SetTitleColor(wtf.ColorFor(widget.commonSettings.Colors.Title)) view.SetWrap(false) return view diff --git a/wtf/bargraph_test.go b/view/bargraph_test.go similarity index 97% rename from wtf/bargraph_test.go rename to view/bargraph_test.go index 6801c286..13f13adc 100644 --- a/wtf/bargraph_test.go +++ b/view/bargraph_test.go @@ -1,4 +1,4 @@ -package wtf +package view import ( "testing" From dbc047516d79399f0575e23d4bb0d09d66a3410e Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 4 Aug 2019 21:42:40 -0700 Subject: [PATCH 3/9] Move all components responsible for module composition into /view --- modules/bamboohr/widget.go | 5 +++-- modules/circleci/widget.go | 6 +++--- modules/clocks/widget.go | 6 +++--- modules/cmdrunner/widget.go | 5 +++-- modules/cryptoexchanges/bittrex/widget.go | 6 +++--- modules/cryptoexchanges/blockfolio/widget.go | 6 +++--- modules/cryptoexchanges/cryptolive/widget.go | 6 +++--- modules/datadog/widget.go | 9 +++++---- modules/feedreader/widget.go | 9 +++++---- modules/gcal/widget.go | 6 +++--- modules/gerrit/widget.go | 9 +++++---- modules/git/widget.go | 13 +++++++------ modules/github/widget.go | 14 +++++++------- modules/gitlab/widget.go | 14 +++++++------- modules/gitter/widget.go | 9 +++++---- modules/googleanalytics/widget.go | 6 +++--- modules/gspreadsheets/widget.go | 5 +++-- modules/hackernews/widget.go | 9 +++++---- modules/hibp/widget.go | 6 +++--- modules/ipaddresses/ipapi/widget.go | 6 +++--- modules/ipaddresses/ipinfo/widget.go | 6 +++--- modules/jenkins/widget.go | 9 +++++---- modules/jira/widget.go | 9 +++++---- modules/logger/widget.go | 6 +++--- modules/mercurial/widget.go | 13 +++++++------ modules/nbascore/widget.go | 9 +++++---- modules/newrelic/widget.go | 5 +++-- modules/opsgenie/widget.go | 5 +++-- modules/pagerduty/widget.go | 5 +++-- modules/power/widget.go | 6 +++--- modules/rollbar/widget.go | 9 +++++---- modules/security/widget.go | 6 +++--- modules/spotify/widget.go | 9 +++++---- modules/spotifyweb/widget.go | 9 +++++---- modules/status/widget.go | 6 +++--- modules/system/widget.go | 5 +++-- modules/textfile/widget.go | 14 +++++++------- modules/todo/widget.go | 17 ++++++++++------- modules/todoist/widget.go | 14 +++++++------- modules/transmission/widget.go | 10 +++++----- modules/travisci/widget.go | 9 +++++---- modules/trello/widget.go | 6 +++--- modules/twitter/widget.go | 13 +++++++------ modules/unknown/widget.go | 6 +++--- modules/victorops/widget.go | 6 +++--- modules/weatherservices/prettyweather/widget.go | 5 +++-- modules/weatherservices/weather/widget.go | 13 +++++++------ modules/zendesk/widget.go | 9 +++++---- {wtf => view}/keyboard_widget.go | 5 +++-- {wtf => view}/keyboard_widget_test.go | 2 +- {wtf => view}/multisource_widget.go | 5 +++-- {wtf => view}/scrollable.go | 3 +-- {wtf => view}/text_widget.go | 11 ++++++----- {wtf => view}/text_widget_test.go | 2 +- 54 files changed, 226 insertions(+), 196 deletions(-) rename {wtf => view}/keyboard_widget.go (96%) rename {wtf => view}/keyboard_widget_test.go (99%) rename {wtf => view}/multisource_widget.go (97%) rename {wtf => view}/scrollable.go (99%) rename {wtf => view}/text_widget.go (91%) rename {wtf => view}/text_widget_test.go (99%) diff --git a/modules/bamboohr/widget.go b/modules/bamboohr/widget.go index 5e3d5a2c..8dd16ee9 100644 --- a/modules/bamboohr/widget.go +++ b/modules/bamboohr/widget.go @@ -5,20 +5,21 @@ import ( "time" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) const APIURI = "https://api.bamboohr.com/api/gateway.php" type Widget struct { - wtf.TextWidget + view.TextWidget settings *Settings } func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/circleci/widget.go b/modules/circleci/widget.go index 920b2845..e10a216f 100644 --- a/modules/circleci/widget.go +++ b/modules/circleci/widget.go @@ -4,11 +4,11 @@ import ( "fmt" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) type Widget struct { - wtf.TextWidget + view.TextWidget *Client settings *Settings @@ -16,7 +16,7 @@ type Widget struct { func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), Client: NewClient(settings.apiKey), settings: settings, diff --git a/modules/clocks/widget.go b/modules/clocks/widget.go index bcabe565..b22f9d7e 100644 --- a/modules/clocks/widget.go +++ b/modules/clocks/widget.go @@ -5,11 +5,11 @@ import ( "time" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) type Widget struct { - wtf.TextWidget + view.TextWidget app *tview.Application clockColl ClockCollection @@ -20,7 +20,7 @@ type Widget struct { func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), app: app, settings: settings, diff --git a/modules/cmdrunner/widget.go b/modules/cmdrunner/widget.go index 523815b5..4f2aca20 100644 --- a/modules/cmdrunner/widget.go +++ b/modules/cmdrunner/widget.go @@ -6,11 +6,12 @@ import ( "strings" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) type Widget struct { - wtf.TextWidget + view.TextWidget args []string cmd string @@ -20,7 +21,7 @@ type Widget struct { // NewWidget creates a new instance of the widget func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), args: settings.args, cmd: settings.cmd, diff --git a/modules/cryptoexchanges/bittrex/widget.go b/modules/cryptoexchanges/bittrex/widget.go index a0e0345a..8850241e 100644 --- a/modules/cryptoexchanges/bittrex/widget.go +++ b/modules/cryptoexchanges/bittrex/widget.go @@ -8,7 +8,7 @@ import ( "net/http" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) var ok = true @@ -18,7 +18,7 @@ const baseURL = "https://bittrex.com/api/v1.1/public/getmarketsummary" // Widget define wtf widget to register widget later type Widget struct { - wtf.TextWidget + view.TextWidget settings *Settings summaryList @@ -27,7 +27,7 @@ type Widget struct { // NewWidget Make new instance of widget func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, summaryList: summaryList{}, diff --git a/modules/cryptoexchanges/blockfolio/widget.go b/modules/cryptoexchanges/blockfolio/widget.go index 1d7db72d..a4079607 100644 --- a/modules/cryptoexchanges/blockfolio/widget.go +++ b/modules/cryptoexchanges/blockfolio/widget.go @@ -8,11 +8,11 @@ import ( "net/http" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) type Widget struct { - wtf.TextWidget + view.TextWidget device_token string settings *Settings @@ -20,7 +20,7 @@ type Widget struct { func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), device_token: settings.deviceToken, settings: settings, diff --git a/modules/cryptoexchanges/cryptolive/widget.go b/modules/cryptoexchanges/cryptolive/widget.go index f6c67d96..5cc01e6a 100644 --- a/modules/cryptoexchanges/cryptolive/widget.go +++ b/modules/cryptoexchanges/cryptolive/widget.go @@ -7,12 +7,12 @@ import ( "github.com/rivo/tview" "github.com/wtfutil/wtf/modules/cryptoexchanges/cryptolive/price" "github.com/wtfutil/wtf/modules/cryptoexchanges/cryptolive/toplist" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) // Widget define wtf widget to register widget later type Widget struct { - wtf.TextWidget + view.TextWidget priceWidget *price.Widget toplistWidget *toplist.Widget @@ -22,7 +22,7 @@ type Widget struct { // NewWidget Make new instance of widget func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), priceWidget: price.NewWidget(settings.priceSettings), toplistWidget: toplist.NewWidget(settings.toplistSettings), diff --git a/modules/datadog/widget.go b/modules/datadog/widget.go index e163585f..d14ae877 100644 --- a/modules/datadog/widget.go +++ b/modules/datadog/widget.go @@ -4,13 +4,14 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" datadog "github.com/zorkian/go-datadog-api" ) type Widget struct { - wtf.KeyboardWidget - wtf.ScrollableWidget + view.KeyboardWidget + view.ScrollableWidget monitors []datadog.Monitor settings *Settings @@ -18,8 +19,8 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + ScrollableWidget: view.NewScrollableWidget(app, settings.common, true), settings: settings, } diff --git a/modules/feedreader/widget.go b/modules/feedreader/widget.go index 678c8566..f3b20ba9 100644 --- a/modules/feedreader/widget.go +++ b/modules/feedreader/widget.go @@ -7,6 +7,7 @@ import ( "github.com/mmcdole/gofeed" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) @@ -22,8 +23,8 @@ type FeedItem struct { // Widget is the container for RSS and Atom data type Widget struct { - wtf.KeyboardWidget - wtf.ScrollableWidget + view.KeyboardWidget + view.ScrollableWidget stories []*FeedItem parser *gofeed.Parser @@ -33,8 +34,8 @@ type Widget struct { // NewWidget creates a new instance of a widget func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := &Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + ScrollableWidget: view.NewScrollableWidget(app, settings.common, true), parser: gofeed.NewParser(), settings: settings, diff --git a/modules/gcal/widget.go b/modules/gcal/widget.go index 964fc4e3..9efaaa84 100644 --- a/modules/gcal/widget.go +++ b/modules/gcal/widget.go @@ -2,11 +2,11 @@ package gcal import ( "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) type Widget struct { - wtf.TextWidget + view.TextWidget app *tview.Application calEvents []*CalEvent @@ -15,7 +15,7 @@ type Widget struct { func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, true), + TextWidget: view.NewTextWidget(app, settings.common, true), app: app, settings: settings, diff --git a/modules/gerrit/widget.go b/modules/gerrit/widget.go index b310a2b5..bb9c0f36 100644 --- a/modules/gerrit/widget.go +++ b/modules/gerrit/widget.go @@ -8,12 +8,13 @@ import ( glb "github.com/andygrunwald/go-gerrit" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) type Widget struct { - wtf.KeyboardWidget - wtf.TextWidget + view.KeyboardWidget + view.TextWidget gerrit *glb.Client @@ -30,8 +31,8 @@ var ( func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - TextWidget: wtf.NewTextWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + TextWidget: view.NewTextWidget(app, settings.common, true), Idx: 0, diff --git a/modules/git/widget.go b/modules/git/widget.go index 31163c8f..de80781f 100644 --- a/modules/git/widget.go +++ b/modules/git/widget.go @@ -8,6 +8,7 @@ import ( "github.com/gdamore/tcell" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) @@ -16,9 +17,9 @@ const modalWidth = 80 const modalHeight = 7 type Widget struct { - wtf.KeyboardWidget - wtf.MultiSourceWidget - wtf.TextWidget + view.KeyboardWidget + view.MultiSourceWidget + view.TextWidget GitRepos []*GitRepo @@ -29,9 +30,9 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "repository", "repositories"), - TextWidget: wtf.NewTextWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + MultiSourceWidget: view.NewMultiSourceWidget(settings.common, "repository", "repositories"), + TextWidget: view.NewTextWidget(app, settings.common, true), app: app, pages: pages, diff --git a/modules/github/widget.go b/modules/github/widget.go index ad4d3ed3..8e3003fb 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -4,13 +4,13 @@ import ( "strings" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) type Widget struct { - wtf.MultiSourceWidget - wtf.KeyboardWidget - wtf.TextWidget + view.MultiSourceWidget + view.KeyboardWidget + view.TextWidget GithubRepos []*GithubRepo @@ -19,9 +19,9 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "repository", "repositories"), - TextWidget: wtf.NewTextWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + MultiSourceWidget: view.NewMultiSourceWidget(settings.common, "repository", "repositories"), + TextWidget: view.NewTextWidget(app, settings.common, true), settings: settings, } diff --git a/modules/gitlab/widget.go b/modules/gitlab/widget.go index bad0b118..e735ff33 100644 --- a/modules/gitlab/widget.go +++ b/modules/gitlab/widget.go @@ -2,14 +2,14 @@ package gitlab import ( "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" glb "github.com/xanzy/go-gitlab" ) type Widget struct { - wtf.KeyboardWidget - wtf.MultiSourceWidget - wtf.TextWidget + view.KeyboardWidget + view.MultiSourceWidget + view.TextWidget GitlabProjects []*GitlabProject @@ -26,9 +26,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * } widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "repository", "repositories"), - TextWidget: wtf.NewTextWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + MultiSourceWidget: view.NewMultiSourceWidget(settings.common, "repository", "repositories"), + TextWidget: view.NewTextWidget(app, settings.common, true), gitlab: gitlab, settings: settings, diff --git a/modules/gitter/widget.go b/modules/gitter/widget.go index 79c55682..12c0fb26 100644 --- a/modules/gitter/widget.go +++ b/modules/gitter/widget.go @@ -4,13 +4,14 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) // A Widget represents a Gitter widget type Widget struct { - wtf.KeyboardWidget - wtf.ScrollableWidget + view.KeyboardWidget + view.ScrollableWidget messages []Message settings *Settings @@ -19,8 +20,8 @@ type Widget struct { // NewWidget creates a new instance of a widget func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + ScrollableWidget: view.NewScrollableWidget(app, settings.common, true), settings: settings, } diff --git a/modules/googleanalytics/widget.go b/modules/googleanalytics/widget.go index af808d47..d74dbc0c 100644 --- a/modules/googleanalytics/widget.go +++ b/modules/googleanalytics/widget.go @@ -2,18 +2,18 @@ package googleanalytics import ( "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) type Widget struct { - wtf.TextWidget + view.TextWidget settings *Settings } func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/gspreadsheets/widget.go b/modules/gspreadsheets/widget.go index 2224cc51..0cbb34d4 100644 --- a/modules/gspreadsheets/widget.go +++ b/modules/gspreadsheets/widget.go @@ -4,19 +4,20 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" sheets "google.golang.org/api/sheets/v4" ) type Widget struct { - wtf.TextWidget + view.TextWidget settings *Settings } func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/hackernews/widget.go b/modules/hackernews/widget.go index 2a31e8ce..6274e339 100644 --- a/modules/hackernews/widget.go +++ b/modules/hackernews/widget.go @@ -6,12 +6,13 @@ import ( "strings" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) type Widget struct { - wtf.KeyboardWidget - wtf.ScrollableWidget + view.KeyboardWidget + view.ScrollableWidget stories []Story settings *Settings @@ -19,8 +20,8 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := &Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + ScrollableWidget: view.NewScrollableWidget(app, settings.common, true), settings: settings, } diff --git a/modules/hibp/widget.go b/modules/hibp/widget.go index f6ff7488..8a7ee1f9 100644 --- a/modules/hibp/widget.go +++ b/modules/hibp/widget.go @@ -4,12 +4,12 @@ import ( "fmt" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) // Widget is the container for hibp data type Widget struct { - wtf.TextWidget + view.TextWidget accounts []string settings *Settings @@ -18,7 +18,7 @@ type Widget struct { // NewWidget creates a new instance of a widget func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := &Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/ipaddresses/ipapi/widget.go b/modules/ipaddresses/ipapi/widget.go index eb530e37..158adc1f 100644 --- a/modules/ipaddresses/ipapi/widget.go +++ b/modules/ipaddresses/ipapi/widget.go @@ -9,12 +9,12 @@ import ( "text/template" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) // Widget widget struct type Widget struct { - wtf.TextWidget + view.TextWidget result string settings *Settings @@ -38,7 +38,7 @@ type ipinfo struct { // NewWidget constructor func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/ipaddresses/ipinfo/widget.go b/modules/ipaddresses/ipinfo/widget.go index 0cc2a494..8f09f919 100644 --- a/modules/ipaddresses/ipinfo/widget.go +++ b/modules/ipaddresses/ipinfo/widget.go @@ -8,11 +8,11 @@ import ( "text/template" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) type Widget struct { - wtf.TextWidget + view.TextWidget result string settings *Settings @@ -31,7 +31,7 @@ type ipinfo struct { func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/jenkins/widget.go b/modules/jenkins/widget.go index f6ca5298..a4579e5b 100644 --- a/modules/jenkins/widget.go +++ b/modules/jenkins/widget.go @@ -5,12 +5,13 @@ import ( "regexp" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) type Widget struct { - wtf.KeyboardWidget - wtf.ScrollableWidget + view.KeyboardWidget + view.ScrollableWidget settings *Settings view *View @@ -18,8 +19,8 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + ScrollableWidget: view.NewScrollableWidget(app, settings.common, true), settings: settings, } diff --git a/modules/jira/widget.go b/modules/jira/widget.go index 77054475..7ffbb52d 100644 --- a/modules/jira/widget.go +++ b/modules/jira/widget.go @@ -4,12 +4,13 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) type Widget struct { - wtf.KeyboardWidget - wtf.ScrollableWidget + view.KeyboardWidget + view.ScrollableWidget result *SearchResult settings *Settings @@ -17,8 +18,8 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + ScrollableWidget: view.NewScrollableWidget(app, settings.common, true), settings: settings, } diff --git a/modules/logger/widget.go b/modules/logger/widget.go index b67b2e16..049bd31e 100644 --- a/modules/logger/widget.go +++ b/modules/logger/widget.go @@ -7,13 +7,13 @@ import ( "github.com/rivo/tview" log "github.com/wtfutil/wtf/logger" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) const maxBufferSize int64 = 1024 type Widget struct { - wtf.TextWidget + view.TextWidget app *tview.Application filePath string @@ -22,7 +22,7 @@ type Widget struct { func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, true), + TextWidget: view.NewTextWidget(app, settings.common, true), app: app, filePath: log.LogFilePath(), diff --git a/modules/mercurial/widget.go b/modules/mercurial/widget.go index aeae8feb..42b993ba 100644 --- a/modules/mercurial/widget.go +++ b/modules/mercurial/widget.go @@ -3,6 +3,7 @@ package mercurial import ( "github.com/gdamore/tcell" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) @@ -12,9 +13,9 @@ const modalHeight = 7 // A Widget represents a Mercurial widget type Widget struct { - wtf.KeyboardWidget - wtf.MultiSourceWidget - wtf.TextWidget + view.KeyboardWidget + view.MultiSourceWidget + view.TextWidget app *tview.Application Data []*MercurialRepo @@ -25,9 +26,9 @@ type Widget struct { // NewWidget creates a new instance of a widget func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "repository", "repositories"), - TextWidget: wtf.NewTextWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + MultiSourceWidget: view.NewMultiSourceWidget(settings.common, "repository", "repositories"), + TextWidget: view.NewTextWidget(app, settings.common, true), app: app, pages: pages, diff --git a/modules/nbascore/widget.go b/modules/nbascore/widget.go index c13ddb8e..ff764806 100644 --- a/modules/nbascore/widget.go +++ b/modules/nbascore/widget.go @@ -9,13 +9,14 @@ import ( "time" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) // A Widget represents an NBA Score widget type Widget struct { - wtf.KeyboardWidget - wtf.TextWidget + view.KeyboardWidget + view.TextWidget language string result string @@ -27,8 +28,8 @@ var offset = 0 // NewWidget creates a new instance of a widget func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - TextWidget: wtf.NewTextWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + TextWidget: view.NewTextWidget(app, settings.common, true), settings: settings, } diff --git a/modules/newrelic/widget.go b/modules/newrelic/widget.go index 90de8b5a..6d0e974e 100644 --- a/modules/newrelic/widget.go +++ b/modules/newrelic/widget.go @@ -4,12 +4,13 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" nr "github.com/yfronto/newrelic" ) type Widget struct { - wtf.TextWidget + view.TextWidget client *Client settings *Settings @@ -17,7 +18,7 @@ type Widget struct { func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/opsgenie/widget.go b/modules/opsgenie/widget.go index 69f1c23b..70075673 100644 --- a/modules/opsgenie/widget.go +++ b/modules/opsgenie/widget.go @@ -5,18 +5,19 @@ import ( "strings" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) type Widget struct { - wtf.TextWidget + view.TextWidget settings *Settings } func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/pagerduty/widget.go b/modules/pagerduty/widget.go index 47d0ebec..fbf0b314 100644 --- a/modules/pagerduty/widget.go +++ b/modules/pagerduty/widget.go @@ -6,18 +6,19 @@ import ( "github.com/PagerDuty/go-pagerduty" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) type Widget struct { - wtf.TextWidget + view.TextWidget settings *Settings } func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/power/widget.go b/modules/power/widget.go index 394c0d48..3254ab65 100644 --- a/modules/power/widget.go +++ b/modules/power/widget.go @@ -4,11 +4,11 @@ import ( "fmt" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) type Widget struct { - wtf.TextWidget + view.TextWidget Battery *Battery @@ -17,7 +17,7 @@ type Widget struct { func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), Battery: NewBattery(), diff --git a/modules/rollbar/widget.go b/modules/rollbar/widget.go index 727f1c47..1d58f940 100644 --- a/modules/rollbar/widget.go +++ b/modules/rollbar/widget.go @@ -4,13 +4,14 @@ import ( "fmt" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) // A Widget represents a Rollbar widget type Widget struct { - wtf.KeyboardWidget - wtf.ScrollableWidget + view.KeyboardWidget + view.ScrollableWidget items *Result settings *Settings @@ -19,8 +20,8 @@ type Widget struct { // NewWidget creates a new instance of a widget func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + ScrollableWidget: view.NewScrollableWidget(app, settings.common, true), settings: settings, } diff --git a/modules/security/widget.go b/modules/security/widget.go index 8dbaa873..0ae6ac9c 100644 --- a/modules/security/widget.go +++ b/modules/security/widget.go @@ -5,18 +5,18 @@ import ( "strings" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) type Widget struct { - wtf.TextWidget + view.TextWidget settings *Settings } func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/spotify/widget.go b/modules/spotify/widget.go index 10caeccd..a81fc3d4 100644 --- a/modules/spotify/widget.go +++ b/modules/spotify/widget.go @@ -5,13 +5,14 @@ import ( "github.com/rivo/tview" "github.com/sticreations/spotigopher/spotigopher" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) // A Widget represents a Spotify widget type Widget struct { - wtf.KeyboardWidget - wtf.TextWidget + view.KeyboardWidget + view.TextWidget client spotigopher.SpotifyClient settings *Settings @@ -21,8 +22,8 @@ type Widget struct { // NewWidget creates a new instance of a widget func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - TextWidget: wtf.NewTextWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + TextWidget: view.NewTextWidget(app, settings.common, true), Info: spotigopher.Info{}, client: spotigopher.NewClient(), diff --git a/modules/spotifyweb/widget.go b/modules/spotifyweb/widget.go index 5b1027ce..cbbf416c 100644 --- a/modules/spotifyweb/widget.go +++ b/modules/spotifyweb/widget.go @@ -7,6 +7,7 @@ import ( "os" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" "github.com/zmb3/spotify" ) @@ -22,8 +23,8 @@ type Info struct { // Widget is the struct used by all WTF widgets to transfer to the main widget controller type Widget struct { - wtf.KeyboardWidget - wtf.TextWidget + view.KeyboardWidget + view.TextWidget Info @@ -68,8 +69,8 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * var playerState *spotify.PlayerState widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - TextWidget: wtf.NewTextWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + TextWidget: view.NewTextWidget(app, settings.common, true), Info: Info{}, diff --git a/modules/status/widget.go b/modules/status/widget.go index 24614897..69981beb 100644 --- a/modules/status/widget.go +++ b/modules/status/widget.go @@ -2,11 +2,11 @@ package status import ( "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) type Widget struct { - wtf.TextWidget + view.TextWidget CurrentIcon int @@ -15,7 +15,7 @@ type Widget struct { func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), CurrentIcon: 0, diff --git a/modules/system/widget.go b/modules/system/widget.go index ac9b2263..b12ce398 100644 --- a/modules/system/widget.go +++ b/modules/system/widget.go @@ -5,11 +5,12 @@ import ( "time" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) type Widget struct { - wtf.TextWidget + view.TextWidget Date string Version string @@ -20,7 +21,7 @@ type Widget struct { func NewWidget(app *tview.Application, date, version string, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), Date: date, diff --git a/modules/textfile/widget.go b/modules/textfile/widget.go index 39e33c0d..9e68d96b 100644 --- a/modules/textfile/widget.go +++ b/modules/textfile/widget.go @@ -14,7 +14,7 @@ import ( "github.com/radovskyb/watcher" "github.com/rivo/tview" "github.com/wtfutil/wtf/utils" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) const ( @@ -22,9 +22,9 @@ const ( ) type Widget struct { - wtf.KeyboardWidget - wtf.MultiSourceWidget - wtf.TextWidget + view.KeyboardWidget + view.MultiSourceWidget + view.TextWidget settings *Settings } @@ -32,9 +32,9 @@ type Widget struct { // NewWidget creates a new instance of a widget func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "filePath", "filePaths"), - TextWidget: wtf.NewTextWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + MultiSourceWidget: view.NewMultiSourceWidget(settings.common, "filePath", "filePaths"), + TextWidget: view.NewTextWidget(app, settings.common, true), settings: settings, } diff --git a/modules/todo/widget.go b/modules/todo/widget.go index 638b2001..70b73a91 100644 --- a/modules/todo/widget.go +++ b/modules/todo/widget.go @@ -8,18 +8,21 @@ import ( "github.com/rivo/tview" "github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/checklist" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" "gopkg.in/yaml.v2" ) -const offscreen = -1000 -const modalWidth = 80 -const modalHeight = 7 +const ( + offscreen = -1000 + modalWidth = 80 + modalHeight = 7 +) // A Widget represents a Todo widget type Widget struct { - wtf.KeyboardWidget - wtf.TextWidget + view.KeyboardWidget + view.TextWidget app *tview.Application settings *Settings @@ -31,8 +34,8 @@ type Widget struct { // NewWidget creates a new instance of a widget func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - TextWidget: wtf.NewTextWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + TextWidget: view.NewTextWidget(app, settings.common, true), app: app, settings: settings, diff --git a/modules/todoist/widget.go b/modules/todoist/widget.go index 9778eac7..8a93369f 100644 --- a/modules/todoist/widget.go +++ b/modules/todoist/widget.go @@ -3,14 +3,14 @@ package todoist import ( "github.com/darkSasori/todoist" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) // A Widget represents a Todoist widget type Widget struct { - wtf.KeyboardWidget - wtf.MultiSourceWidget - wtf.ScrollableWidget + view.KeyboardWidget + view.MultiSourceWidget + view.ScrollableWidget projects []*Project settings *Settings @@ -19,9 +19,9 @@ type Widget struct { // NewWidget creates a new instance of a widget func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "project", "projects"), - ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + MultiSourceWidget: view.NewMultiSourceWidget(settings.common, "project", "projects"), + ScrollableWidget: view.NewScrollableWidget(app, settings.common, true), settings: settings, } diff --git a/modules/transmission/widget.go b/modules/transmission/widget.go index b8d76df2..e6c457cd 100644 --- a/modules/transmission/widget.go +++ b/modules/transmission/widget.go @@ -5,13 +5,13 @@ import ( "github.com/hekmon/transmissionrpc" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) // Widget is the container for transmission data type Widget struct { - wtf.KeyboardWidget - wtf.ScrollableWidget + view.KeyboardWidget + view.ScrollableWidget client *transmissionrpc.Client settings *Settings @@ -21,8 +21,8 @@ type Widget struct { // NewWidget creates a new instance of a widget func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + ScrollableWidget: view.NewScrollableWidget(app, settings.common, true), settings: settings, } diff --git a/modules/travisci/widget.go b/modules/travisci/widget.go index f145b48b..a5e5d582 100644 --- a/modules/travisci/widget.go +++ b/modules/travisci/widget.go @@ -5,12 +5,13 @@ import ( "strings" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) type Widget struct { - wtf.KeyboardWidget - wtf.ScrollableWidget + view.KeyboardWidget + view.ScrollableWidget builds *Builds settings *Settings @@ -18,8 +19,8 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + ScrollableWidget: view.NewScrollableWidget(app, settings.common, true), settings: settings, } diff --git a/modules/trello/widget.go b/modules/trello/widget.go index 5e29b33f..5dcb217c 100644 --- a/modules/trello/widget.go +++ b/modules/trello/widget.go @@ -5,18 +5,18 @@ import ( "github.com/adlio/trello" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) type Widget struct { - wtf.TextWidget + view.TextWidget settings *Settings } func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/twitter/widget.go b/modules/twitter/widget.go index b26ae210..f023a6a8 100644 --- a/modules/twitter/widget.go +++ b/modules/twitter/widget.go @@ -7,13 +7,14 @@ import ( "github.com/dustin/go-humanize" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) type Widget struct { - wtf.KeyboardWidget - wtf.MultiSourceWidget - wtf.TextWidget + view.KeyboardWidget + view.MultiSourceWidget + view.TextWidget client *Client idx int @@ -23,9 +24,9 @@ type Widget struct { func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "screenName", "screenNames"), - TextWidget: wtf.NewTextWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + MultiSourceWidget: view.NewMultiSourceWidget(settings.common, "screenName", "screenNames"), + TextWidget: view.NewTextWidget(app, settings.common, true), idx: 0, settings: settings, diff --git a/modules/unknown/widget.go b/modules/unknown/widget.go index 77090b3a..2e53475f 100644 --- a/modules/unknown/widget.go +++ b/modules/unknown/widget.go @@ -4,18 +4,18 @@ import ( "fmt" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) type Widget struct { - wtf.TextWidget + view.TextWidget settings *Settings } func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/victorops/widget.go b/modules/victorops/widget.go index 924102fa..a1ad09a5 100644 --- a/modules/victorops/widget.go +++ b/modules/victorops/widget.go @@ -4,12 +4,12 @@ import ( "fmt" "github.com/rivo/tview" - "github.com/wtfutil/wtf/wtf" + "github.com/wtfutil/wtf/view" ) // Widget contains text info type Widget struct { - wtf.TextWidget + view.TextWidget teams []OnCallTeam settings *Settings @@ -18,7 +18,7 @@ type Widget struct { // NewWidget creates a new widget func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, true), + TextWidget: view.NewTextWidget(app, settings.common, true), } widget.View.SetScrollable(true) diff --git a/modules/weatherservices/prettyweather/widget.go b/modules/weatherservices/prettyweather/widget.go index 8645ba60..f98a7791 100644 --- a/modules/weatherservices/prettyweather/widget.go +++ b/modules/weatherservices/prettyweather/widget.go @@ -6,11 +6,12 @@ import ( "strings" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) type Widget struct { - wtf.TextWidget + view.TextWidget result string settings *Settings @@ -18,7 +19,7 @@ type Widget struct { func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(app, settings.common, false), + TextWidget: view.NewTextWidget(app, settings.common, false), settings: settings, } diff --git a/modules/weatherservices/weather/widget.go b/modules/weatherservices/weather/widget.go index 4f4ba669..5fa52ff6 100644 --- a/modules/weatherservices/weather/widget.go +++ b/modules/weatherservices/weather/widget.go @@ -3,14 +3,15 @@ package weather import ( owm "github.com/briandowns/openweathermap" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) // Widget is the container for weather data. type Widget struct { - wtf.KeyboardWidget - wtf.MultiSourceWidget - wtf.TextWidget + view.KeyboardWidget + view.MultiSourceWidget + view.TextWidget // APIKey string Data []*owm.CurrentWeatherData @@ -22,9 +23,9 @@ type Widget struct { // NewWidget creates and returns a new instance of the weather Widget func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "cityid", "cityids"), - TextWidget: wtf.NewTextWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + MultiSourceWidget: view.NewMultiSourceWidget(settings.common, "cityid", "cityids"), + TextWidget: view.NewTextWidget(app, settings.common, true), pages: pages, settings: settings, diff --git a/modules/zendesk/widget.go b/modules/zendesk/widget.go index f8702539..3b1f4cdc 100644 --- a/modules/zendesk/widget.go +++ b/modules/zendesk/widget.go @@ -5,13 +5,14 @@ import ( "log" "github.com/rivo/tview" + "github.com/wtfutil/wtf/view" "github.com/wtfutil/wtf/wtf" ) // A Widget represents a Zendesk widget type Widget struct { - wtf.KeyboardWidget - wtf.ScrollableWidget + view.KeyboardWidget + view.ScrollableWidget result *TicketArray settings *Settings @@ -20,8 +21,8 @@ type Widget struct { // NewWidget creates a new instance of a widget func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { widget := Widget{ - KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), - ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true), + KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common), + ScrollableWidget: view.NewScrollableWidget(app, settings.common, true), settings: settings, } diff --git a/wtf/keyboard_widget.go b/view/keyboard_widget.go similarity index 96% rename from wtf/keyboard_widget.go rename to view/keyboard_widget.go index 4e09e0ab..d48c69fd 100644 --- a/wtf/keyboard_widget.go +++ b/view/keyboard_widget.go @@ -1,4 +1,4 @@ -package wtf +package view import ( "fmt" @@ -7,6 +7,7 @@ import ( "github.com/gdamore/tcell" "github.com/rivo/tview" "github.com/wtfutil/wtf/cfg" + "github.com/wtfutil/wtf/wtf" ) type helpItem struct { @@ -120,7 +121,7 @@ func (widget *KeyboardWidget) ShowHelp() { widget.app.SetFocus(widget.view) } - modal := NewBillboardModal(widget.HelpText(), closeFunc) + modal := wtf.NewBillboardModal(widget.HelpText(), closeFunc) widget.pages.AddPage("help", modal, false, true) widget.app.SetFocus(modal) diff --git a/wtf/keyboard_widget_test.go b/view/keyboard_widget_test.go similarity index 99% rename from wtf/keyboard_widget_test.go rename to view/keyboard_widget_test.go index 1eade042..c1540850 100644 --- a/wtf/keyboard_widget_test.go +++ b/view/keyboard_widget_test.go @@ -1,4 +1,4 @@ -package wtf +package view import ( "testing" diff --git a/wtf/multisource_widget.go b/view/multisource_widget.go similarity index 97% rename from wtf/multisource_widget.go rename to view/multisource_widget.go index 8bfa8cbd..f3f818e7 100644 --- a/wtf/multisource_widget.go +++ b/view/multisource_widget.go @@ -1,7 +1,8 @@ -package wtf +package view import ( "github.com/wtfutil/wtf/cfg" + "github.com/wtfutil/wtf/wtf" ) // MultiSourceWidget is a widget that supports displaying data from multiple sources @@ -89,7 +90,7 @@ func (widget *MultiSourceWidget) loadSources() { single := widget.moduleConfig.Config.UString(widget.singular, "") multiple := widget.moduleConfig.Config.UList(widget.plural, empty) - asStrs := ToStrs(multiple) + asStrs := wtf.ToStrs(multiple) if single != "" { asStrs = append(asStrs, single) diff --git a/wtf/scrollable.go b/view/scrollable.go similarity index 99% rename from wtf/scrollable.go rename to view/scrollable.go index 22d84fd6..38744344 100644 --- a/wtf/scrollable.go +++ b/view/scrollable.go @@ -1,4 +1,4 @@ -package wtf +package view import ( "strconv" @@ -16,7 +16,6 @@ type ScrollableWidget struct { } func NewScrollableWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) ScrollableWidget { - widget := ScrollableWidget{ TextWidget: NewTextWidget(app, commonSettings, focusable), } diff --git a/wtf/text_widget.go b/view/text_widget.go similarity index 91% rename from wtf/text_widget.go rename to view/text_widget.go index eb851918..f71a8a4d 100644 --- a/wtf/text_widget.go +++ b/view/text_widget.go @@ -1,4 +1,4 @@ -package wtf +package view import ( "fmt" @@ -6,6 +6,7 @@ import ( "github.com/rivo/tview" "github.com/wtfutil/wtf/cfg" "github.com/wtfutil/wtf/utils" + "github.com/wtfutil/wtf/wtf" ) type TextWidget struct { @@ -148,10 +149,10 @@ func (widget *TextWidget) Redraw(title, text string, wrap bool) { func (widget *TextWidget) addView() *tview.TextView { view := tview.NewTextView() - view.SetBackgroundColor(ColorFor(widget.commonSettings.Colors.Background)) - view.SetBorderColor(ColorFor(widget.BorderColor())) - view.SetTextColor(ColorFor(widget.commonSettings.Colors.Text)) - view.SetTitleColor(ColorFor(widget.commonSettings.Colors.Title)) + view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background)) + view.SetBorderColor(wtf.ColorFor(widget.BorderColor())) + view.SetTextColor(wtf.ColorFor(widget.commonSettings.Colors.Text)) + view.SetTitleColor(wtf.ColorFor(widget.commonSettings.Colors.Title)) view.SetBorder(true) view.SetDynamicColors(true) diff --git a/wtf/text_widget_test.go b/view/text_widget_test.go similarity index 99% rename from wtf/text_widget_test.go rename to view/text_widget_test.go index 4e2baa64..18a6b909 100644 --- a/wtf/text_widget_test.go +++ b/view/text_widget_test.go @@ -1,4 +1,4 @@ -package wtf +package view import ( "testing" From 98eb3c9013b526d89b217fdfbfab758b39293baa Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 4 Aug 2019 22:02:14 -0700 Subject: [PATCH 4/9] 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() From 275ea37a0113cca3b484b2bf29007ddd2714ae26 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 4 Aug 2019 22:10:00 -0700 Subject: [PATCH 5/9] 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() From b6b695290cee1e1e5966ab7ff32607627784de68 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 4 Aug 2019 23:00:09 -0700 Subject: [PATCH 6/9] Extract common funcitons from BarGraph and TextWidget into Base --- view/bargraph.go | 82 +--------------------------------- view/base.go | 106 +++++++++++++++++++++++++++++++++++++++++++- view/text_widget.go | 100 +---------------------------------------- 3 files changed, 108 insertions(+), 180 deletions(-) diff --git a/view/bargraph.go b/view/bargraph.go index 5b3854b4..afde39cb 100644 --- a/view/bargraph.go +++ b/view/bargraph.go @@ -28,16 +28,7 @@ type Bar struct { // NewBarGraph initialize your fancy new graph func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common, focusable bool) BarGraph { widget := BarGraph{ - Base: Base{ - app: app, - bordered: commonSettings.Bordered, - commonSettings: commonSettings, - enabled: commonSettings.Enabled, - focusable: focusable, - name: commonSettings.Title, - quitChan: make(chan bool), - refreshInterval: commonSettings.RefreshInterval, - }, + Base: NewBase(app, commonSettings, focusable), maxStars: commonSettings.Config.UInt("graphStars", 20), starChar: commonSettings.Config.UString("graphIcon", "|"), @@ -49,81 +40,12 @@ func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common return widget } -func (widget *BarGraph) BorderColor() string { - if widget.Focusable() { - return widget.commonSettings.Colors.BorderFocusable - } - - return widget.commonSettings.Colors.BorderNormal -} - -func (widget *BarGraph) CommonSettings() *cfg.Common { - return widget.commonSettings -} - -func (widget *BarGraph) Disable() { - widget.enabled = false -} - -func (widget *BarGraph) Disabled() bool { - return !widget.Enabled() -} - -func (widget *BarGraph) Enabled() bool { - return widget.enabled -} - -func (widget *BarGraph) Focusable() bool { - return widget.enabled && widget.focusable -} - -func (widget *BarGraph) FocusChar() string { - return "" -} - -func (widget *BarGraph) Key() string { - return widget.key -} - -func (widget *BarGraph) Name() string { - return widget.name -} - -func (widget *BarGraph) QuitChan() chan bool { - return widget.quitChan -} - -// Refreshing returns TRUE if the widget is currently refreshing its data, FALSE if it is not -func (widget *BarGraph) Refreshing() bool { - return widget.refreshing -} - -// RefreshInterval returns how often, in seconds, the widget will return its data -func (widget *BarGraph) RefreshInterval() int { - return widget.refreshInterval -} - -func (widget *BarGraph) SetFocusChar(char string) { - return -} - -func (widget *BarGraph) Stop() { - widget.enabled = false - widget.quitChan <- true -} +/* -------------------- Exported Functions -------------------- */ func (widget *BarGraph) TextView() *tview.TextView { return widget.View } -func (widget *BarGraph) HelpText() string { - return "No help available for this widget" -} - -func (widget *BarGraph) ConfigText() string { - return "" -} - // BuildBars will build a string of * to represent your data of [time][value] // time should be passed as a int64 func (widget *BarGraph) BuildBars(data []Bar) { diff --git a/view/base.go b/view/base.go index 49377d5f..ec64b7fb 100644 --- a/view/base.go +++ b/view/base.go @@ -1,8 +1,11 @@ package view import ( + "fmt" + "github.com/rivo/tview" "github.com/wtfutil/wtf/cfg" + "github.com/wtfutil/wtf/utils" ) type Base struct { @@ -12,9 +15,110 @@ type Base struct { enabled bool focusChar string focusable bool - key string name string quitChan chan bool refreshing bool refreshInterval int } + +func NewBase(app *tview.Application, commonSettings *cfg.Common, focusable bool) Base { + 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, + } + return base +} + +/* -------------------- Exported Functions -------------------- */ + +// Bordered returns whether or not this widget should be drawn with a border +func (base *Base) Bordered() bool { + return base.bordered +} + +func (base *Base) BorderColor() string { + if base.Focusable() { + return base.commonSettings.Colors.BorderFocusable + } + + return base.commonSettings.Colors.BorderNormal +} + +func (base *Base) CommonSettings() *cfg.Common { + return base.commonSettings +} + +func (base *Base) ConfigText() string { + return utils.HelpFromInterface(cfg.Common{}) +} + +func (base *Base) ContextualTitle(defaultStr string) string { + if base.FocusChar() == "" { + return fmt.Sprintf(" %s ", defaultStr) + } + + return fmt.Sprintf(" %s [darkgray::u]%s[::-][green] ", defaultStr, base.FocusChar()) +} + +func (base *Base) Disable() { + base.enabled = false +} + +func (base *Base) Disabled() bool { + return !base.enabled +} + +func (base *Base) Enabled() bool { + return base.enabled +} + +func (base *Base) Focusable() bool { + return base.enabled && base.focusable +} + +func (base *Base) FocusChar() string { + return base.focusChar +} + +func (base *Base) HelpText() string { + return fmt.Sprintf("\n There is no help available for widget %s", base.commonSettings.Module.Type) +} + +func (base *Base) Name() string { + return base.name +} + +func (base *Base) QuitChan() chan bool { + return base.quitChan +} + +// Refreshing returns TRUE if the base is currently refreshing its data, FALSE if it is not +func (base *Base) Refreshing() bool { + return base.refreshing +} + +// RefreshInterval returns how often, in seconds, the base will return its data +func (base *Base) RefreshInterval() int { + return base.refreshInterval +} + +func (base *Base) SetFocusChar(char string) { + base.focusChar = char +} + +func (base *Base) Stop() { + base.enabled = false + base.quitChan <- true +} + +func (base *Base) String() string { + return base.name +} diff --git a/view/text_widget.go b/view/text_widget.go index f6142b1f..1654c179 100644 --- a/view/text_widget.go +++ b/view/text_widget.go @@ -1,11 +1,8 @@ package view import ( - "fmt" - "github.com/rivo/tview" "github.com/wtfutil/wtf/cfg" - "github.com/wtfutil/wtf/utils" "github.com/wtfutil/wtf/wtf" ) @@ -16,18 +13,7 @@ type TextWidget struct { func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) TextWidget { widget := TextWidget{ - 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, - }, + Base: NewBase(app, commonSettings, focusable), } widget.View = widget.addView() @@ -38,90 +24,6 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable /* -------------------- Exported Functions -------------------- */ -// Bordered returns whether or not this widget should be drawn with a border -func (widget *TextWidget) Bordered() bool { - return widget.bordered -} - -func (widget *TextWidget) BorderColor() string { - if widget.Focusable() { - return widget.commonSettings.Colors.BorderFocusable - } - - return widget.commonSettings.Colors.BorderNormal -} - -func (widget *TextWidget) CommonSettings() *cfg.Common { - return widget.commonSettings -} - -func (widget *TextWidget) ConfigText() string { - return utils.HelpFromInterface(cfg.Common{}) -} - -func (widget *TextWidget) ContextualTitle(defaultStr string) string { - if widget.FocusChar() == "" { - return fmt.Sprintf(" %s ", defaultStr) - } - - return fmt.Sprintf(" %s [darkgray::u]%s[::-][green] ", defaultStr, widget.FocusChar()) -} - -func (widget *TextWidget) Disable() { - widget.enabled = false -} - -func (widget *TextWidget) Disabled() bool { - return !widget.Enabled() -} - -func (widget *TextWidget) Enabled() bool { - return widget.enabled -} - -func (widget *TextWidget) Focusable() bool { - return widget.enabled && widget.focusable -} - -func (widget *TextWidget) FocusChar() string { - return widget.focusChar -} - -func (widget *TextWidget) HelpText() string { - return fmt.Sprintf("\n There is no help available for widget %s", widget.commonSettings.Module.Type) -} - -func (widget *TextWidget) QuitChan() chan bool { - return widget.quitChan -} - -func (widget *TextWidget) Name() string { - return widget.name -} - -// Refreshing returns TRUE if the widget is currently refreshing its data, FALSE if it is not -func (widget *TextWidget) Refreshing() bool { - return widget.refreshing -} - -// RefreshInterval returns how often, in seconds, the widget will return its data -func (widget *TextWidget) RefreshInterval() int { - return widget.refreshInterval -} - -func (widget *TextWidget) SetFocusChar(char string) { - widget.focusChar = char -} - -func (widget *TextWidget) Stop() { - widget.enabled = false - widget.quitChan <- true -} - -func (widget *TextWidget) String() string { - return widget.name -} - func (widget *TextWidget) TextView() *tview.TextView { return widget.View } From 787d1a3ba9466f858e33fdd901b2e11234b68caa Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 4 Aug 2019 23:14:44 -0700 Subject: [PATCH 7/9] BarGraph supports customizable titles in config --- view/bargraph.go | 17 ++++++++--------- view/text_widget.go | 10 ++++------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/view/bargraph.go b/view/bargraph.go index afde39cb..1b79f153 100644 --- a/view/bargraph.go +++ b/view/bargraph.go @@ -34,18 +34,13 @@ func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common starChar: commonSettings.Config.UString("graphIcon", "|"), } - widget.View = widget.addView() - widget.View.SetBorder(widget.bordered) + widget.View = widget.addView(widget.bordered) return widget } /* -------------------- Exported Functions -------------------- */ -func (widget *BarGraph) TextView() *tview.TextView { - return widget.View -} - // BuildBars will build a string of * to represent your data of [time][value] // time should be passed as a int64 func (widget *BarGraph) BuildBars(data []Bar) { @@ -98,16 +93,20 @@ func BuildStars(data []Bar, maxStars int, starChar string) string { return buffer.String() } +func (widget *BarGraph) TextView() *tview.TextView { + return widget.View +} + /* -------------------- Unexported Functions -------------------- */ -func (widget *BarGraph) addView() *tview.TextView { +func (widget *BarGraph) addView(bordered bool) *tview.TextView { view := tview.NewTextView() view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background)) - view.SetBorder(true) + view.SetBorder(bordered) view.SetBorderColor(wtf.ColorFor(widget.BorderColor())) view.SetDynamicColors(true) - view.SetTitle(widget.Name()) + view.SetTitle(widget.ContextualTitle(widget.CommonSettings().Title)) view.SetTitleColor(wtf.ColorFor(widget.commonSettings.Colors.Title)) view.SetWrap(false) diff --git a/view/text_widget.go b/view/text_widget.go index 1654c179..ee2bf140 100644 --- a/view/text_widget.go +++ b/view/text_widget.go @@ -16,8 +16,7 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable Base: NewBase(app, commonSettings, focusable), } - widget.View = widget.addView() - widget.View.SetBorder(widget.bordered) + widget.View = widget.addView(widget.bordered) return widget } @@ -39,16 +38,15 @@ func (widget *TextWidget) Redraw(title, text string, wrap bool) { /* -------------------- Unexported Functions -------------------- */ -func (widget *TextWidget) addView() *tview.TextView { +func (widget *TextWidget) addView(bordered bool) *tview.TextView { view := tview.NewTextView() view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background)) + view.SetBorder(bordered) view.SetBorderColor(wtf.ColorFor(widget.BorderColor())) + view.SetDynamicColors(true) view.SetTextColor(wtf.ColorFor(widget.commonSettings.Colors.Text)) view.SetTitleColor(wtf.ColorFor(widget.commonSettings.Colors.Title)) - - view.SetBorder(true) - view.SetDynamicColors(true) view.SetWrap(false) return view From d372e1029f11ae0c60022499d17f13db22b45d02 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 4 Aug 2019 23:21:46 -0700 Subject: [PATCH 8/9] Rename addView() to createView() --- view/bargraph.go | 12 +++++------- view/text_widget.go | 6 ++++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/view/bargraph.go b/view/bargraph.go index 1b79f153..74507317 100644 --- a/view/bargraph.go +++ b/view/bargraph.go @@ -10,7 +10,7 @@ import ( "github.com/wtfutil/wtf/wtf" ) -//BarGraph lets make graphs +//BarGraph defines the data required to make a bar graph type BarGraph struct { maxStars int starChar string @@ -19,13 +19,14 @@ type BarGraph struct { View *tview.TextView } +// Bar defines a single row in the bar graph type Bar struct { Label string Percent int ValueLabel string } -// NewBarGraph initialize your fancy new graph +// NewBarGraph creates and returns an instance of BarGraph func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common, focusable bool) BarGraph { widget := BarGraph{ Base: NewBase(app, commonSettings, focusable), @@ -34,7 +35,7 @@ func NewBarGraph(app *tview.Application, name string, commonSettings *cfg.Common starChar: commonSettings.Config.UString("graphIcon", "|"), } - widget.View = widget.addView(widget.bordered) + widget.View = widget.createView(widget.bordered) return widget } @@ -56,11 +57,9 @@ func BuildStars(data []Bar, maxStars int, starChar string) string { //just getting min and max values for _, bar := range data { - if len(bar.Label) > longestLabel { longestLabel = len(bar.Label) } - } // each number = how many stars? @@ -68,7 +67,6 @@ func BuildStars(data []Bar, maxStars int, starChar string) string { //build the stars for _, bar := range data { - //how many stars for this one? var starCount = int(float64(bar.Percent) * starRatio) @@ -99,7 +97,7 @@ func (widget *BarGraph) TextView() *tview.TextView { /* -------------------- Unexported Functions -------------------- */ -func (widget *BarGraph) addView(bordered bool) *tview.TextView { +func (widget *BarGraph) createView(bordered bool) *tview.TextView { view := tview.NewTextView() view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background)) diff --git a/view/text_widget.go b/view/text_widget.go index ee2bf140..4f691f1c 100644 --- a/view/text_widget.go +++ b/view/text_widget.go @@ -6,17 +6,19 @@ import ( "github.com/wtfutil/wtf/wtf" ) +// TextWidget defines the data necessary to make a text widget type TextWidget struct { Base View *tview.TextView } +// NewTextWidget creates and returns an instance of TextWidget func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) TextWidget { widget := TextWidget{ Base: NewBase(app, commonSettings, focusable), } - widget.View = widget.addView(widget.bordered) + widget.View = widget.createView(widget.bordered) return widget } @@ -38,7 +40,7 @@ func (widget *TextWidget) Redraw(title, text string, wrap bool) { /* -------------------- Unexported Functions -------------------- */ -func (widget *TextWidget) addView(bordered bool) *tview.TextView { +func (widget *TextWidget) createView(bordered bool) *tview.TextView { view := tview.NewTextView() view.SetBackgroundColor(wtf.ColorFor(widget.commonSettings.Colors.Background)) From 06a785d7703768803c7ccfc51ec536535f149351 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sun, 4 Aug 2019 23:23:54 -0700 Subject: [PATCH 9/9] Rename --- view/{scrollable.go => scrollable_widget.go} | 2 ++ 1 file changed, 2 insertions(+) rename view/{scrollable.go => scrollable_widget.go} (96%) diff --git a/view/scrollable.go b/view/scrollable_widget.go similarity index 96% rename from view/scrollable.go rename to view/scrollable_widget.go index 38744344..0bf588ab 100644 --- a/view/scrollable.go +++ b/view/scrollable_widget.go @@ -27,6 +27,8 @@ func NewScrollableWidget(app *tview.Application, commonSettings *cfg.Common, foc return widget } +/* -------------------- Exported Functions -------------------- */ + func (widget *ScrollableWidget) SetRenderFunction(displayFunc func()) { widget.RenderFunction = displayFunc }