diff --git a/textfile/widget.go b/textfile/widget.go index 4041b0f9..b0762442 100644 --- a/textfile/widget.go +++ b/textfile/widget.go @@ -85,7 +85,6 @@ func (widget *Widget) showHelp() { closeFunc := func() { widget.pages.RemovePage("help") widget.app.SetFocus(widget.View) - widget.Refresh() } modal := wtf.NewBillboardModal(helpText, closeFunc) diff --git a/todo/widget.go b/todo/widget.go index 53fdedeb..ce0e3f45 100644 --- a/todo/widget.go +++ b/todo/widget.go @@ -220,7 +220,6 @@ func (widget *Widget) showHelp() { closeFunc := func() { widget.pages.RemovePage("help") widget.app.SetFocus(widget.View) - widget.display() } modal := wtf.NewBillboardModal(helpText, closeFunc) diff --git a/weather/widget.go b/weather/widget.go index c0608308..b651599e 100644 --- a/weather/widget.go +++ b/weather/widget.go @@ -7,27 +7,44 @@ import ( owm "github.com/briandowns/openweathermap" "github.com/gdamore/tcell" "github.com/olebedev/config" + "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) // Config is a pointer to the global config object. var Config *config.Config +const helpText = ` + Keyboard commands for Weather: + + h: Show/hide this help window + + arrow right: Next weather location + arrow left: Previous weather location +` + // Widget is the container for weather data. type Widget struct { wtf.TextWidget + app *tview.Application + pages *tview.Pages + APIKey string Data []*owm.CurrentWeatherData Idx int } // NewWidget creates and returns a new instance of the weather Widget. -func NewWidget() *Widget { +func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(" Weather ", "weather", true), - APIKey: os.Getenv("WTF_OWM_API_KEY"), - Idx: 0, + + app: app, + pages: pages, + + APIKey: os.Getenv("WTF_OWM_API_KEY"), + Idx: 0, } widget.View.SetInputCapture(widget.keyboardIntercept) @@ -196,6 +213,12 @@ func (widget *Widget) icon(data *owm.CurrentWeatherData) string { } func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { + switch string(event.Rune()) { + case "h": + widget.showHelp() + return nil + } + switch event.Key() { case tcell.KeyLeft: widget.Prev() @@ -207,3 +230,15 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { return event } } + +func (widget *Widget) showHelp() { + closeFunc := func() { + widget.pages.RemovePage("help") + widget.app.SetFocus(widget.View) + } + + modal := wtf.NewBillboardModal(helpText, closeFunc) + + widget.pages.AddPage("help", modal, false, true) + widget.app.SetFocus(modal) +} diff --git a/wtf.go b/wtf.go index 0d6ab348..1ba53b61 100644 --- a/wtf.go +++ b/wtf.go @@ -196,7 +196,7 @@ func main() { system.NewWidget(builtat, version), textfile.NewWidget(app, pages), todo.NewWidget(app, pages), - weather.NewWidget(), + weather.NewWidget(app, pages), } FocusTracker = wtf.FocusTracker{