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

Add help text for Weather

This commit is contained in:
Chris Cummer 2018-05-03 17:21:59 -07:00
parent 1baa884ce9
commit 6e179de0c4
4 changed files with 39 additions and 6 deletions

View File

@ -85,7 +85,6 @@ func (widget *Widget) showHelp() {
closeFunc := func() { closeFunc := func() {
widget.pages.RemovePage("help") widget.pages.RemovePage("help")
widget.app.SetFocus(widget.View) widget.app.SetFocus(widget.View)
widget.Refresh()
} }
modal := wtf.NewBillboardModal(helpText, closeFunc) modal := wtf.NewBillboardModal(helpText, closeFunc)

View File

@ -220,7 +220,6 @@ func (widget *Widget) showHelp() {
closeFunc := func() { closeFunc := func() {
widget.pages.RemovePage("help") widget.pages.RemovePage("help")
widget.app.SetFocus(widget.View) widget.app.SetFocus(widget.View)
widget.display()
} }
modal := wtf.NewBillboardModal(helpText, closeFunc) modal := wtf.NewBillboardModal(helpText, closeFunc)

View File

@ -7,27 +7,44 @@ import (
owm "github.com/briandowns/openweathermap" owm "github.com/briandowns/openweathermap"
"github.com/gdamore/tcell" "github.com/gdamore/tcell"
"github.com/olebedev/config" "github.com/olebedev/config"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf" "github.com/senorprogrammer/wtf/wtf"
) )
// Config is a pointer to the global config object. // Config is a pointer to the global config object.
var Config *config.Config 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. // Widget is the container for weather data.
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
pages *tview.Pages
APIKey string APIKey string
Data []*owm.CurrentWeatherData Data []*owm.CurrentWeatherData
Idx int Idx int
} }
// NewWidget creates and returns a new instance of the weather Widget. // 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{ widget := Widget{
TextWidget: wtf.NewTextWidget(" Weather ", "weather", true), 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) 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 { func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
switch string(event.Rune()) {
case "h":
widget.showHelp()
return nil
}
switch event.Key() { switch event.Key() {
case tcell.KeyLeft: case tcell.KeyLeft:
widget.Prev() widget.Prev()
@ -207,3 +230,15 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
return event 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)
}

2
wtf.go
View File

@ -196,7 +196,7 @@ func main() {
system.NewWidget(builtat, version), system.NewWidget(builtat, version),
textfile.NewWidget(app, pages), textfile.NewWidget(app, pages),
todo.NewWidget(app, pages), todo.NewWidget(app, pages),
weather.NewWidget(), weather.NewWidget(app, pages),
} }
FocusTracker = wtf.FocusTracker{ FocusTracker = wtf.FocusTracker{