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:
parent
1baa884ce9
commit
6e179de0c4
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -7,25 +7,42 @@ 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),
|
||||
|
||||
app: app,
|
||||
pages: pages,
|
||||
|
||||
APIKey: os.Getenv("WTF_OWM_API_KEY"),
|
||||
Idx: 0,
|
||||
}
|
||||
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user