From d6208b47307b7dd30168ae861b77d4cbbbf76538 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Sat, 31 Aug 2019 10:00:00 -0700 Subject: [PATCH] Add a focusable over-ride setting for widgets that are non-focusable by default For widgets that are non-focusable by default, you can now specify focusable: true in their config to over-ride the default 'false' value. --- cfg/common_settings.go | 2 ++ view/base.go | 4 +++- view/text_widget.go | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cfg/common_settings.go b/cfg/common_settings.go index 947a49e7..742fd496 100644 --- a/cfg/common_settings.go +++ b/cfg/common_settings.go @@ -49,6 +49,7 @@ type Common struct { Bordered bool `help:"Whether or not the module should be displayed with a border." values:"true, false" optional:"true" default:"true"` Enabled bool `help:"Whether or not this module is executed and if its data displayed onscreen." values:"true, false" optional:"true" default:"false"` + Focusable bool `help:"Whether or not this module is focusable." values:"true, false" optional:"true" default:"false"` RefreshInterval int `help:"How often, in seconds, this module will update its data." values:"A positive integer, 0..n." optional:"true"` Title string `help:"The title string to show when displaying this module" optional:"true"` Config *config.Config @@ -83,6 +84,7 @@ func NewCommonSettingsFromModule(name, defaultTitle string, moduleConfig *config Bordered: moduleConfig.UBool("border", true), Enabled: moduleConfig.UBool("enabled", false), + Focusable: moduleConfig.UBool("focusable", false), RefreshInterval: moduleConfig.UInt("refreshInterval", 300), Title: moduleConfig.UString("title", defaultTitle), Config: moduleConfig, diff --git a/view/base.go b/view/base.go index c265e370..80f4f2f6 100644 --- a/view/base.go +++ b/view/base.go @@ -23,7 +23,9 @@ type Base struct { enabledMutex *sync.Mutex } -func NewBase(app *tview.Application, commonSettings *cfg.Common, focusable bool) Base { +func NewBase(app *tview.Application, commonSettings *cfg.Common, defaultFocusable bool) Base { + focusable := commonSettings.Focusable || defaultFocusable + base := Base{ commonSettings: commonSettings, app: app, diff --git a/view/text_widget.go b/view/text_widget.go index 911657cc..8292f0c9 100644 --- a/view/text_widget.go +++ b/view/text_widget.go @@ -13,9 +13,9 @@ type TextWidget struct { } // NewTextWidget creates and returns an instance of TextWidget -func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) TextWidget { +func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, defaultFocusable bool) TextWidget { widget := TextWidget{ - Base: NewBase(app, commonSettings, focusable), + Base: NewBase(app, commonSettings, defaultFocusable), } widget.View = widget.createView(widget.bordered)