Skip to content

Commit

Permalink
Flip weather over to a multi-source widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Seanstoppable committed May 24, 2019
1 parent 9a877b5 commit aeb76e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 31 deletions.
9 changes: 5 additions & 4 deletions modules/weatherservices/weather/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import "github.com/gdamore/tcell"

func (widget *Widget) initializeKeyboardControls() {
widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt")
widget.SetKeyboardChar("h", widget.Prev, "Select previous item")
widget.SetKeyboardChar("l", widget.Next, "Select next item")
widget.SetKeyboardChar("r", widget.Refresh, "Refresh Widget")
widget.SetKeyboardChar("h", widget.PrevSource, "Select previous city")
widget.SetKeyboardChar("l", widget.NextSource, "Select next city")

widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev, "Select previous item")
widget.SetKeyboardKey(tcell.KeyRight, widget.Next, "Select next item")
widget.SetKeyboardKey(tcell.KeyLeft, widget.PrevSource, "Select previous city")
widget.SetKeyboardKey(tcell.KeyRight, widget.NextSource, "Select next city")
}
35 changes: 8 additions & 27 deletions modules/weatherservices/weather/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,32 @@ import (
// Widget is the container for weather data.
type Widget struct {
wtf.KeyboardWidget
wtf.MultiSourceWidget
wtf.TextWidget

// APIKey string
Data []*owm.CurrentWeatherData
Idx int

pages *tview.Pages
settings *Settings
}

// NewWidget creates and returns a new instance of the weather Widget
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
widget := Widget{
KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common),
TextWidget: wtf.NewTextWidget(app, settings.common, true),

Idx: 0,
KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common),
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "cityid", "cityids"),
TextWidget: wtf.NewTextWidget(app, settings.common, true),

pages: pages,
settings: settings,
}

widget.initializeKeyboardControls()
widget.View.SetInputCapture(widget.InputCapture)

widget.SetDisplayFunction(widget.display)

widget.KeyboardWidget.SetView(widget.View)

return &widget
Expand Down Expand Up @@ -65,28 +68,6 @@ func (widget *Widget) Refresh() {
widget.display()
}

// Next displays data for the next city data in the list. If the current city is the last
// city, it wraps to the first city.
func (widget *Widget) Next() {
widget.Idx++
if widget.Idx == len(widget.Data) {
widget.Idx = 0
}

widget.display()
}

// Prev displays data for the previous city in the list. If the previous city is the first
// city, it wraps to the last city.
func (widget *Widget) Prev() {
widget.Idx--
if widget.Idx < 0 {
widget.Idx = len(widget.Data) - 1
}

widget.display()
}

func (widget *Widget) HelpText() string {
return widget.KeyboardWidget.HelpText()
}
Expand Down

0 comments on commit aeb76e9

Please sign in to comment.