1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-389 Log an exception and terminate if widget config is invalid

If, on startup, a widget's positional configuration is invalid (ie:
cannot be displayed onscreen) then terminate the app and inform about
which widget is erroring
This commit is contained in:
Chris Cummer
2019-04-12 05:25:55 -07:00
parent c9c7e124cc
commit aa313bdaa4
30 changed files with 84 additions and 50 deletions

View File

@@ -9,11 +9,13 @@ import (
//BarGraph lets make graphs
type BarGraph struct {
enabled bool
focusable bool
starChar string
maxStars int
Name string
enabled bool
focusable bool
key string
maxStars int
name string
starChar string
RefreshInt int
View *tview.TextView
@@ -31,9 +33,10 @@ func NewBarGraph(app *tview.Application, name string, configKey string, focusabl
widget := BarGraph{
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
focusable: focusable,
starChar: Config.UString(fmt.Sprintf("wtf.mods.%s.graphIcon", configKey), "|"),
key: configKey,
maxStars: Config.UInt(fmt.Sprintf("wtf.mods.%s.graphStars", configKey), 20),
Name: Config.UString(fmt.Sprintf("wtf.mods.%s.title", configKey), name),
name: Config.UString(fmt.Sprintf("wtf.mods.%s.title", configKey), name),
starChar: Config.UString(fmt.Sprintf("wtf.mods.%s.graphIcon", configKey), "|"),
RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey), 1),
}
@@ -83,6 +86,14 @@ func (widget *BarGraph) IsPositionable() bool {
return widget.Position.IsValid()
}
func (widget *BarGraph) Key() string {
return widget.key
}
func (widget *BarGraph) Name() string {
return widget.name
}
func (widget *BarGraph) RefreshInterval() int {
return widget.RefreshInt
}
@@ -104,7 +115,7 @@ func (widget *BarGraph) addView(app *tview.Application, configKey string) {
view.SetBorder(true)
view.SetBorderColor(ColorFor(widget.BorderColor()))
view.SetDynamicColors(true)
view.SetTitle(widget.Name)
view.SetTitle(widget.Name())
view.SetTitleColor(ColorFor(
Config.UString(
fmt.Sprintf("wtf.mods.%s.colors.title", configKey),

View File

@@ -13,8 +13,9 @@ type TextWidget struct {
enabled bool
focusable bool
focusChar string
key string
name string
Name string
RefreshInt int
View *tview.TextView
@@ -32,7 +33,8 @@ func NewTextWidget(app *tview.Application, name string, configKey string, focusa
enabled: Config.UBool(fmt.Sprintf("wtf.mods.%s.enabled", configKey), false),
focusable: focusable,
focusChar: focusChar,
Name: Config.UString(fmt.Sprintf("wtf.mods.%s.title", configKey), name),
key: configKey,
name: Config.UString(fmt.Sprintf("wtf.mods.%s.title", configKey), name),
RefreshInt: Config.UInt(fmt.Sprintf("wtf.mods.%s.refreshInterval", configKey)),
}
@@ -92,6 +94,14 @@ func (widget *TextWidget) IsPositionable() bool {
return widget.Position.IsValid()
}
func (widget *TextWidget) Key() string {
return widget.key
}
func (widget *TextWidget) Name() string {
return widget.name
}
func (widget *TextWidget) RefreshInterval() int {
return widget.RefreshInt
}
@@ -135,7 +145,7 @@ func (widget *TextWidget) addView(app *tview.Application, configKey string) {
app.Draw()
})
view.SetDynamicColors(true)
view.SetTitle(widget.ContextualTitle(widget.Name))
view.SetTitle(widget.ContextualTitle(widget.name))
view.SetWrap(false)
widget.View = view

View File

@@ -11,6 +11,8 @@ type Wtfable interface {
BorderColor() string
Focusable() bool
FocusChar() string
Key() string
Name() string
SetFocusChar(string)
TextView() *tview.TextView