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:
parent
c9c7e124cc
commit
aa313bdaa4
@ -52,7 +52,7 @@ func (widget *Widget) Refresh() {
|
||||
return
|
||||
}
|
||||
|
||||
widget.View.SetTitle(widget.Name)
|
||||
widget.View.SetTitle(widget.Name())
|
||||
|
||||
logLines := widget.tailFile()
|
||||
widget.View.SetText(widget.contentFrom(logLines))
|
||||
|
19
main.go
19
main.go
@ -151,6 +151,8 @@ func watchForConfigChanges(app *tview.Application, configFilePath string, grid *
|
||||
loadConfigFile(absPath)
|
||||
|
||||
widgets := makeWidgets(app, pages)
|
||||
validateWidgets(widgets)
|
||||
|
||||
initializeFocusTracker(app, widgets)
|
||||
|
||||
display := wtf.NewDisplay(widgets)
|
||||
@ -284,10 +286,7 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) []wtf.Wtfable {
|
||||
for mod := range mods {
|
||||
if enabled := Config.UBool("wtf.mods."+mod+".enabled", false); enabled {
|
||||
widget := makeWidget(app, pages, mod)
|
||||
|
||||
if widget.IsPositionable() {
|
||||
widgets = append(widgets, widget)
|
||||
}
|
||||
widgets = append(widgets, widget)
|
||||
}
|
||||
}
|
||||
|
||||
@ -298,6 +297,16 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) []wtf.Wtfable {
|
||||
return widgets
|
||||
}
|
||||
|
||||
// Check that all the loaded widgets are valid for display
|
||||
func validateWidgets(widgets []wtf.Wtfable) {
|
||||
for _, widget := range widgets {
|
||||
if widget.Enabled() && !widget.IsPositionable() {
|
||||
errStr := fmt.Sprintf("Widget config has invalid values: %s", widget.Key())
|
||||
log.Fatalln(errStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------- Main -------------------- */
|
||||
|
||||
func main() {
|
||||
@ -322,6 +331,8 @@ func main() {
|
||||
pages := tview.NewPages()
|
||||
|
||||
widgets := makeWidgets(app, pages)
|
||||
validateWidgets(widgets)
|
||||
|
||||
initializeFocusTracker(app, widgets)
|
||||
|
||||
display := wtf.NewDisplay(widgets)
|
||||
|
@ -40,7 +40,7 @@ func (widget *Widget) Refresh() {
|
||||
wtf.Now().Format(wtf.DateFormat),
|
||||
)
|
||||
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name))
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name()))
|
||||
|
||||
widget.View.SetText(widget.contentFrom(todayItems))
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func (widget *Widget) Refresh() {
|
||||
|
||||
builds, err := widget.Client.BuildsFor()
|
||||
|
||||
widget.View.SetTitle(fmt.Sprintf("%s - Builds", widget.Name))
|
||||
widget.View.SetTitle(fmt.Sprintf("%s - Builds", widget.Name()))
|
||||
|
||||
var content string
|
||||
if err != nil {
|
||||
|
@ -25,7 +25,7 @@ func NewWidget(app *tview.Application) *Widget {
|
||||
func (widget *Widget) Refresh() {
|
||||
monitors, monitorErr := Monitors()
|
||||
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name)))
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name())))
|
||||
widget.View.Clear()
|
||||
|
||||
var content string
|
||||
|
@ -32,7 +32,7 @@ func (widget *Widget) display() {
|
||||
widget.mutex.Lock()
|
||||
defer widget.mutex.Unlock()
|
||||
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name))
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name()))
|
||||
widget.View.SetText(widget.contentFrom(widget.calEvents))
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ func (widget *Widget) display() {
|
||||
return
|
||||
}
|
||||
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s- %s", widget.Name, widget.title(project))))
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s- %s", widget.Name(), widget.title(project))))
|
||||
|
||||
str := wtf.SigilStr(len(widget.GerritProjects), widget.Idx, widget.View) + "\n"
|
||||
str = str + " [red]Stats[white]\n"
|
||||
|
@ -94,7 +94,7 @@ func (widget *Widget) Refresh() {
|
||||
gerrit, err := glb.NewClient(gerritUrl, httpClient)
|
||||
if err != nil {
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetTitle(widget.Name)
|
||||
widget.View.SetTitle(widget.Name())
|
||||
widget.View.SetText(err.Error())
|
||||
return
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ func (widget *Widget) display() {
|
||||
return
|
||||
}
|
||||
|
||||
title := fmt.Sprintf("%s - [green]%s[white]", widget.Name, repoData.Repository)
|
||||
title := fmt.Sprintf("%s - [green]%s[white]", widget.Name(), repoData.Repository)
|
||||
widget.View.SetTitle(widget.ContextualTitle(title))
|
||||
|
||||
str := wtf.SigilStr(len(widget.GitRepos), widget.Idx, widget.View) + "\n"
|
||||
|
@ -14,7 +14,7 @@ func (widget *Widget) display() {
|
||||
return
|
||||
}
|
||||
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.Name, widget.title(repo))))
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.Name(), widget.title(repo))))
|
||||
|
||||
str := wtf.SigilStr(len(widget.GithubRepos), widget.Idx, widget.View) + "\n"
|
||||
str = str + " [red]Stats[white]\n"
|
||||
|
@ -14,7 +14,7 @@ func (widget *Widget) display() {
|
||||
return
|
||||
}
|
||||
|
||||
widget.View.SetTitle(fmt.Sprintf("%s- %s", widget.Name, widget.title(project)))
|
||||
widget.View.SetTitle(fmt.Sprintf("%s- %s", widget.Name(), widget.title(project)))
|
||||
|
||||
str := wtf.SigilStr(len(widget.GitlabProjects), widget.Idx, widget.View) + "\n"
|
||||
str = str + " [red]Stats[white]\n"
|
||||
|
@ -54,7 +54,7 @@ func (widget *Widget) Refresh() {
|
||||
room, err := GetRoom(wtf.Config.UString("wtf.mods.gitter.roomUri", "wtfutil/Lobby"))
|
||||
if err != nil {
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetTitle(widget.Name)
|
||||
widget.View.SetTitle(widget.Name())
|
||||
widget.View.SetText(err.Error())
|
||||
return
|
||||
}
|
||||
@ -67,7 +67,7 @@ func (widget *Widget) Refresh() {
|
||||
|
||||
if err != nil {
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetTitle(widget.Name)
|
||||
widget.View.SetTitle(widget.Name())
|
||||
widget.View.SetText(err.Error())
|
||||
} else {
|
||||
widget.messages = messages
|
||||
@ -86,7 +86,7 @@ func (widget *Widget) display() {
|
||||
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.Clear()
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.Name, wtf.Config.UString("wtf.mods.gitter.roomUri", "wtfutil/Lobby"))))
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.Name(), wtf.Config.UString("wtf.mods.gitter.roomUri", "wtfutil/Lobby"))))
|
||||
widget.View.SetText(widget.contentFrom(widget.messages))
|
||||
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ func (widget *Widget) Refresh() {
|
||||
|
||||
if err != nil {
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetTitle(widget.Name)
|
||||
widget.View.SetTitle(widget.Name())
|
||||
widget.View.SetText(err.Error())
|
||||
} else {
|
||||
var stories []Story
|
||||
@ -94,7 +94,7 @@ func (widget *Widget) display() {
|
||||
widget.View.SetWrap(false)
|
||||
|
||||
widget.View.Clear()
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %sstories", widget.Name, wtf.Config.UString("wtf.mods.hackernews.storyType", "top"))))
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %sstories", widget.Name(), wtf.Config.UString("wtf.mods.hackernews.storyType", "top"))))
|
||||
widget.View.SetText(widget.contentFrom(widget.stories))
|
||||
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ func (widget *Widget) Refresh() {
|
||||
|
||||
if err != nil {
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name))
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name()))
|
||||
widget.View.SetText(err.Error())
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ func (widget *Widget) display() {
|
||||
widget.View.SetWrap(false)
|
||||
|
||||
widget.View.Clear()
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s: [red]%s", widget.Name, widget.view.Name)))
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s: [red]%s", widget.Name(), widget.view.Name)))
|
||||
widget.View.SetText(widget.contentFrom(widget.view))
|
||||
widget.View.Highlight(strconv.Itoa(widget.selected)).ScrollToHighlight()
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ func (widget *Widget) Refresh() {
|
||||
if err != nil {
|
||||
widget.result = nil
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetTitle(widget.Name)
|
||||
widget.View.SetTitle(widget.Name())
|
||||
widget.View.SetText(err.Error())
|
||||
} else {
|
||||
widget.result = searchResult
|
||||
@ -74,7 +74,7 @@ func (widget *Widget) display() {
|
||||
}
|
||||
widget.View.SetWrap(false)
|
||||
|
||||
str := fmt.Sprintf("%s- [green]%s[white]", widget.Name, wtf.Config.UString("wtf.mods.jira.project"))
|
||||
str := fmt.Sprintf("%s- [green]%s[white]", widget.Name(), wtf.Config.UString("wtf.mods.jira.project"))
|
||||
|
||||
widget.View.Clear()
|
||||
widget.View.SetTitle(widget.ContextualTitle(str))
|
||||
|
@ -15,7 +15,7 @@ func (widget *Widget) display() {
|
||||
return
|
||||
}
|
||||
|
||||
title := fmt.Sprintf("%s - [green]%s[white]", widget.Name, repoData.Repository)
|
||||
title := fmt.Sprintf("%s - [green]%s[white]", widget.Name(), repoData.Repository)
|
||||
widget.View.SetTitle(widget.ContextualTitle(title))
|
||||
|
||||
str := wtf.SigilStr(len(widget.Data), widget.Idx, widget.View) + "\n"
|
||||
|
@ -47,7 +47,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||
func (widget *Widget) Refresh() {
|
||||
widget.nbascore()
|
||||
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name))
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name()))
|
||||
}
|
||||
|
||||
func (widget *Widget) nbascore() {
|
||||
|
@ -34,7 +34,7 @@ func (widget *Widget) Refresh() {
|
||||
appName = app.Name
|
||||
}
|
||||
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - [green]%s[white]", widget.Name, appName)))
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - [green]%s[white]", widget.Name(), appName)))
|
||||
widget.View.Clear()
|
||||
|
||||
var content string
|
||||
|
@ -27,7 +27,7 @@ func (widget *Widget) Refresh() {
|
||||
wtf.Config.UString("wtf.mods.opsgenie.scheduleIdentifierType"),
|
||||
getSchedules(),
|
||||
)
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name))
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name()))
|
||||
|
||||
var content string
|
||||
if err != nil {
|
||||
|
@ -38,7 +38,7 @@ func (widget *Widget) Refresh() {
|
||||
incidents, err2 = GetIncidents()
|
||||
}
|
||||
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name)))
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name())))
|
||||
widget.View.Clear()
|
||||
|
||||
var content string
|
||||
|
@ -55,7 +55,7 @@ func (widget *Widget) Refresh() {
|
||||
|
||||
if err != nil {
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetTitle(widget.Name)
|
||||
widget.View.SetTitle(widget.Name())
|
||||
widget.View.SetText(err.Error())
|
||||
} else {
|
||||
widget.items = &items.Results
|
||||
@ -73,7 +73,7 @@ func (widget *Widget) display() {
|
||||
|
||||
widget.View.SetWrap(false)
|
||||
projectName := wtf.Config.UString("wtf.mods.rollbar.projectName", "Items")
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.Name, projectName)))
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - %s", widget.Name(), projectName)))
|
||||
widget.View.SetText(widget.contentFrom(widget.items))
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ func (widget *Widget) Refresh() {
|
||||
widget.load()
|
||||
widget.display()
|
||||
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name))
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name()))
|
||||
}
|
||||
|
||||
func (widget *Widget) SetList(newList checklist.Checklist) {
|
||||
|
@ -55,7 +55,7 @@ func (widget *Widget) Refresh() {
|
||||
|
||||
if err != nil {
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetTitle(widget.Name)
|
||||
widget.View.SetTitle(widget.Name())
|
||||
widget.View.SetText(err.Error())
|
||||
} else {
|
||||
widget.builds = builds
|
||||
@ -73,7 +73,7 @@ func (widget *Widget) display() {
|
||||
|
||||
widget.View.SetWrap(false)
|
||||
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - Builds", widget.Name)))
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s - Builds", widget.Name())))
|
||||
widget.View.SetText(widget.contentFrom(widget.builds))
|
||||
}
|
||||
|
||||
|
@ -35,14 +35,14 @@ func (widget *Widget) Refresh() {
|
||||
var content string
|
||||
if err != nil {
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetTitle(widget.Name)
|
||||
widget.View.SetTitle(widget.Name())
|
||||
content = err.Error()
|
||||
} else {
|
||||
widget.View.SetWrap(false)
|
||||
widget.View.SetTitle(
|
||||
fmt.Sprintf(
|
||||
"[white]%s: [green]%s ",
|
||||
widget.Name,
|
||||
widget.Name(),
|
||||
wtf.Config.UString("wtf.mods.trello.board"),
|
||||
),
|
||||
)
|
||||
|
@ -23,9 +23,9 @@ func NewWidget(app *tview.Application, name string) *Widget {
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name)))
|
||||
widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name())))
|
||||
widget.View.Clear()
|
||||
|
||||
content := fmt.Sprintf("Widget %s does not exist", widget.Name)
|
||||
content := fmt.Sprintf("Widget %s does not exist", widget.Name())
|
||||
widget.View.SetText(content)
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func (widget *Widget) Refresh() {
|
||||
}
|
||||
|
||||
teams, err := Fetch()
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name))
|
||||
widget.View.SetTitle(widget.ContextualTitle(widget.Name()))
|
||||
|
||||
if err != nil {
|
||||
widget.View.SetWrap(true)
|
||||
|
@ -43,7 +43,7 @@ func (widget *Widget) Refresh() {
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) display() {
|
||||
widget.View.SetTitle(fmt.Sprintf("%s (%d)", widget.Name, widget.result.Count))
|
||||
widget.View.SetTitle(fmt.Sprintf("%s (%d)", widget.Name(), widget.result.Count))
|
||||
widget.View.SetText(widget.textContent(widget.result.Tickets))
|
||||
}
|
||||
|
||||
|
@ -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),
|
||||
|
@ -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
|
||||
|
@ -11,6 +11,8 @@ type Wtfable interface {
|
||||
BorderColor() string
|
||||
Focusable() bool
|
||||
FocusChar() string
|
||||
Key() string
|
||||
Name() string
|
||||
SetFocusChar(string)
|
||||
TextView() *tview.TextView
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user