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
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user