From 90f150df3db143a20cccca89ea5a380a911d0b6a Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Thu, 14 Feb 2019 22:30:14 -0500 Subject: [PATCH] Add default unknown widget Let people know if they are doing something wrong --- main.go | 2 ++ unknown/widget.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 unknown/widget.go diff --git a/main.go b/main.go index 3dcc2612..c2337ad9 100644 --- a/main.go +++ b/main.go @@ -57,6 +57,7 @@ import ( "github.com/wtfutil/wtf/travisci" "github.com/wtfutil/wtf/trello" "github.com/wtfutil/wtf/twitter" + "github.com/wtfutil/wtf/unknown" "github.com/wtfutil/wtf/victorops" "github.com/wtfutil/wtf/weatherservices/prettyweather" "github.com/wtfutil/wtf/weatherservices/weather" @@ -259,6 +260,7 @@ func addWidget(app *tview.Application, pages *tview.Pages, widgetName string) { case "zendesk": widgets = append(widgets, zendesk.NewWidget(app)) default: + widgets = append(widgets, unknown.NewWidget(app, widgetName)) } } diff --git a/unknown/widget.go b/unknown/widget.go new file mode 100644 index 00000000..76ffe6b1 --- /dev/null +++ b/unknown/widget.go @@ -0,0 +1,31 @@ +package unknown + +import ( + "fmt" + + "github.com/rivo/tview" + "github.com/wtfutil/wtf/wtf" +) + +type Widget struct { + wtf.TextWidget +} + +func NewWidget(app *tview.Application, name string) *Widget { + widget := Widget{ + TextWidget: wtf.NewTextWidget(app, name, name, false), + } + + return &widget +} + +/* -------------------- Exported Functions -------------------- */ + +func (widget *Widget) Refresh() { + + widget.View.SetTitle(widget.ContextualTitle(fmt.Sprintf("%s", widget.Name))) + widget.View.Clear() + + content := fmt.Sprintf("Widget %s does not exist", widget.Name) + widget.View.SetText(content) +}