From c2e240014db69cbd2681d5103ada87e5604dce69 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Wed, 10 Jul 2019 22:30:36 -0700 Subject: [PATCH] Add support for a new 'border' property on widgets Sets whether or not the widget should be drawn with a border (and by extension a title). If 'true', the border is drawn. If 'false', no border is drawn. Defaults. to 'true'. Optional. --- cfg/common_settings.go | 4 +++- wtf/text_widget.go | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cfg/common_settings.go b/cfg/common_settings.go index b2b7ecca..231738b5 100644 --- a/cfg/common_settings.go +++ b/cfg/common_settings.go @@ -47,7 +47,8 @@ type Common struct { PositionSettings `help:"Defines where in the grid this module’s widget will be displayed."` Sigils - Enabled bool `help:"Determines whether or not this module is executed and if its data displayed onscreen." values:"true, false"` + 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"` 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 @@ -80,6 +81,7 @@ func NewCommonSettingsFromModule(name, defaultTitle string, moduleConfig *config PositionSettings: NewPositionSettingsFromYAML(name, moduleConfig), + Bordered: moduleConfig.UBool("border", true), Enabled: moduleConfig.UBool("enabled", false), RefreshInterval: moduleConfig.UInt("refreshInterval", 300), Title: moduleConfig.UString("title", defaultTitle), diff --git a/wtf/text_widget.go b/wtf/text_widget.go index bdb14ec3..835c2a55 100644 --- a/wtf/text_widget.go +++ b/wtf/text_widget.go @@ -9,6 +9,7 @@ import ( ) type TextWidget struct { + bordered bool commonSettings *cfg.Common enabled bool focusable bool @@ -25,6 +26,7 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable commonSettings: commonSettings, app: app, + bordered: commonSettings.Bordered, enabled: commonSettings.Enabled, focusable: focusable, focusChar: commonSettings.FocusChar(), @@ -33,12 +35,18 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable } widget.View = widget.addView() + widget.View.SetBorder(widget.bordered) return widget } /* -------------------- 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