diff --git a/cfg/common_settings.go b/cfg/common_settings.go index e51e8bd5..31feeb0a 100644 --- a/cfg/common_settings.go +++ b/cfg/common_settings.go @@ -55,9 +55,10 @@ type Common struct { Sigils Enabled bool - FocusChar int RefreshInterval int Title string + + focusChar int } func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config) *Common { @@ -93,9 +94,10 @@ func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config) }, Enabled: ymlConfig.UBool(modulePath+".enabled", false), - FocusChar: ymlConfig.UInt(modulePath+".focusChar", -1), RefreshInterval: ymlConfig.UInt(modulePath+".refreshInterval", 300), Title: ymlConfig.UString(modulePath+".title", name), + + focusChar: ymlConfig.UInt(modulePath+".focusChar", -1), } common.Colors.Rows.Even = ymlConfig.UString(modulePath+".colors.rows.even", ymlConfig.UString(colorsPath+".rows.even", "white")) @@ -118,6 +120,15 @@ func (common *Common) DefaultRowColor() string { return fmt.Sprintf("%s:%s", common.Colors.Foreground, common.Colors.Background) } +func (common *Common) FocusChar() string { + focusChar := string('0' + common.focusChar) + if common.focusChar == -1 { + focusChar = "" + } + + return focusChar +} + func (common *Common) RowColor(idx int) string { if idx%2 == 0 { return common.Colors.Rows.Even diff --git a/wtf/text_widget.go b/wtf/text_widget.go index 845c4645..81c9ba6f 100644 --- a/wtf/text_widget.go +++ b/wtf/text_widget.go @@ -25,19 +25,12 @@ type TextWidget struct { } func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) TextWidget { - configKey := commonSettings.ConfigKey - - focusChar := string('0' + commonSettings.FocusChar) - if commonSettings.FocusChar == -1 { - focusChar = "" - } - widget := TextWidget{ CommonSettings: commonSettings, enabled: commonSettings.Enabled, focusable: focusable, - focusChar: focusChar, + focusChar: commonSettings.FocusChar(), key: commonSettings.ConfigKey, name: commonSettings.Name, refreshInterval: commonSettings.RefreshInterval, @@ -50,7 +43,11 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable commonSettings.Position.Height, ) - widget.addView(app, configKey) + widget.View = widget.addView() + + widget.View.SetChangedFunc(func() { + app.Draw() + }) return widget } @@ -125,7 +122,7 @@ func (widget *TextWidget) TextView() *tview.TextView { /* -------------------- Unexported Functions -------------------- */ -func (widget *TextWidget) addView(app *tview.Application, configKey string) { +func (widget *TextWidget) addView() *tview.TextView { view := tview.NewTextView() view.SetBackgroundColor(ColorFor(widget.CommonSettings.Colors.Background)) @@ -138,9 +135,5 @@ func (widget *TextWidget) addView(app *tview.Application, configKey string) { view.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title)) view.SetWrap(false) - view.SetChangedFunc(func() { - app.Draw() - }) - - widget.View = view + return view }