mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Clean up TextWidget by simplifying the view creation
This commit is contained in:
parent
eef8015158
commit
f60ce6967d
@ -55,9 +55,10 @@ type Common struct {
|
|||||||
Sigils
|
Sigils
|
||||||
|
|
||||||
Enabled bool
|
Enabled bool
|
||||||
FocusChar int
|
|
||||||
RefreshInterval int
|
RefreshInterval int
|
||||||
Title string
|
Title string
|
||||||
|
|
||||||
|
focusChar int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCommonSettingsFromYAML(name, configKey string, ymlConfig *config.Config) *Common {
|
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),
|
Enabled: ymlConfig.UBool(modulePath+".enabled", false),
|
||||||
FocusChar: ymlConfig.UInt(modulePath+".focusChar", -1),
|
|
||||||
RefreshInterval: ymlConfig.UInt(modulePath+".refreshInterval", 300),
|
RefreshInterval: ymlConfig.UInt(modulePath+".refreshInterval", 300),
|
||||||
Title: ymlConfig.UString(modulePath+".title", name),
|
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"))
|
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)
|
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 {
|
func (common *Common) RowColor(idx int) string {
|
||||||
if idx%2 == 0 {
|
if idx%2 == 0 {
|
||||||
return common.Colors.Rows.Even
|
return common.Colors.Rows.Even
|
||||||
|
@ -25,19 +25,12 @@ type TextWidget struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable bool) TextWidget {
|
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{
|
widget := TextWidget{
|
||||||
CommonSettings: commonSettings,
|
CommonSettings: commonSettings,
|
||||||
|
|
||||||
enabled: commonSettings.Enabled,
|
enabled: commonSettings.Enabled,
|
||||||
focusable: focusable,
|
focusable: focusable,
|
||||||
focusChar: focusChar,
|
focusChar: commonSettings.FocusChar(),
|
||||||
key: commonSettings.ConfigKey,
|
key: commonSettings.ConfigKey,
|
||||||
name: commonSettings.Name,
|
name: commonSettings.Name,
|
||||||
refreshInterval: commonSettings.RefreshInterval,
|
refreshInterval: commonSettings.RefreshInterval,
|
||||||
@ -50,7 +43,11 @@ func NewTextWidget(app *tview.Application, commonSettings *cfg.Common, focusable
|
|||||||
commonSettings.Position.Height,
|
commonSettings.Position.Height,
|
||||||
)
|
)
|
||||||
|
|
||||||
widget.addView(app, configKey)
|
widget.View = widget.addView()
|
||||||
|
|
||||||
|
widget.View.SetChangedFunc(func() {
|
||||||
|
app.Draw()
|
||||||
|
})
|
||||||
|
|
||||||
return widget
|
return widget
|
||||||
}
|
}
|
||||||
@ -125,7 +122,7 @@ func (widget *TextWidget) TextView() *tview.TextView {
|
|||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *TextWidget) addView(app *tview.Application, configKey string) {
|
func (widget *TextWidget) addView() *tview.TextView {
|
||||||
view := tview.NewTextView()
|
view := tview.NewTextView()
|
||||||
|
|
||||||
view.SetBackgroundColor(ColorFor(widget.CommonSettings.Colors.Background))
|
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.SetTitle(widget.ContextualTitle(widget.CommonSettings.Title))
|
||||||
view.SetWrap(false)
|
view.SetWrap(false)
|
||||||
|
|
||||||
view.SetChangedFunc(func() {
|
return view
|
||||||
app.Draw()
|
|
||||||
})
|
|
||||||
|
|
||||||
widget.View = view
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user