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() {
|
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)
|
||||||
|
@ -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)
|
||||||
|
@ -7,25 +7,42 @@ 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),
|
||||||
|
|
||||||
|
app: app,
|
||||||
|
pages: pages,
|
||||||
|
|
||||||
APIKey: os.Getenv("WTF_OWM_API_KEY"),
|
APIKey: os.Getenv("WTF_OWM_API_KEY"),
|
||||||
Idx: 0,
|
Idx: 0,
|
||||||
}
|
}
|
||||||
@ -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
2
wtf.go
@ -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{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user