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

Merge branch 'master' into configdocs

This commit is contained in:
Chris Cummer 2019-05-24 18:14:34 -07:00 committed by GitHub
commit d2385b962f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 64 deletions

View File

@ -2,6 +2,10 @@
## Unreleased ## Unreleased
### 🐞 Fixed
* Todoist now properly updates list items when Refresh is called
## v0.10.3 ## v0.10.3
* Invalid glog dependency removed, by [@bosr](https://github.com/bosr) * Invalid glog dependency removed, by [@bosr](https://github.com/bosr)

View File

@ -40,22 +40,29 @@ func disableAllWidgets(widgets []wtf.Wtfable) {
} }
func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey { func keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
// These keys are global keys used by the app. Widgets should not implement these keys
switch event.Key() { switch event.Key() {
case tcell.KeyCtrlR: case tcell.KeyCtrlR:
refreshAllWidgets(runningWidgets) refreshAllWidgets(runningWidgets)
return nil
case tcell.KeyTab: case tcell.KeyTab:
focusTracker.Next() focusTracker.Next()
return nil
case tcell.KeyBacktab: case tcell.KeyBacktab:
focusTracker.Prev() focusTracker.Prev()
return nil
case tcell.KeyEsc: case tcell.KeyEsc:
focusTracker.None() focusTracker.None()
return nil
} }
// This function checks to see if any widget has been assigned the pressed key as its
// focus key
if focusTracker.FocusOn(string(event.Rune())) { if focusTracker.FocusOn(string(event.Rune())) {
return nil return nil
} }
// If no specific widget has focus, then allow key presses to fall through to the app // If no specific widget has focus, then allow the key presses to fall through to the app
if !focusTracker.IsFocused { if !focusTracker.IsFocused {
switch string(event.Rune()) { switch string(event.Rune()) {
case "/": case "/":

View File

@ -5,9 +5,9 @@ import "github.com/gdamore/tcell"
func (widget *Widget) initializeKeyboardControls() { func (widget *Widget) initializeKeyboardControls() {
widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt") widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt")
widget.SetKeyboardChar("r", widget.Refresh, "Refresh widget") widget.SetKeyboardChar("r", widget.Refresh, "Refresh widget")
widget.SetKeyboardChar("h", widget.Prev, "Select previous item") widget.SetKeyboardChar("h", widget.PrevSource, "Select previous project")
widget.SetKeyboardChar("l", widget.Next, "Select next item") widget.SetKeyboardChar("l", widget.NextSource, "Select next project")
widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev, "Select previous item") widget.SetKeyboardKey(tcell.KeyLeft, widget.PrevSource, "Select previous project")
widget.SetKeyboardKey(tcell.KeyRight, widget.Next, "Select next item") widget.SetKeyboardKey(tcell.KeyRight, widget.NextSource, "Select next project")
} }

View File

@ -8,10 +8,10 @@ import (
type Widget struct { type Widget struct {
wtf.KeyboardWidget wtf.KeyboardWidget
wtf.MultiSourceWidget
wtf.TextWidget wtf.TextWidget
GitlabProjects []*GitlabProject GitlabProjects []*GitlabProject
Idx int
gitlab *glb.Client gitlab *glb.Client
settings *Settings settings *Settings
@ -26,10 +26,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
} }
widget := Widget{ widget := Widget{
KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common),
TextWidget: wtf.NewTextWidget(app, settings.common, true), MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "repository", "repositories"),
TextWidget: wtf.NewTextWidget(app, settings.common, true),
Idx: 0,
gitlab: gitlab, gitlab: gitlab,
settings: settings, settings: settings,
@ -39,6 +38,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
widget.initializeKeyboardControls() widget.initializeKeyboardControls()
widget.View.SetInputCapture(widget.InputCapture) widget.View.SetInputCapture(widget.InputCapture)
widget.SetDisplayFunction(widget.display)
widget.KeyboardWidget.SetView(widget.View) widget.KeyboardWidget.SetView(widget.View)
@ -55,24 +55,6 @@ func (widget *Widget) Refresh() {
widget.display() widget.display()
} }
func (widget *Widget) Next() {
widget.Idx++
if widget.Idx == len(widget.GitlabProjects) {
widget.Idx = 0
}
widget.display()
}
func (widget *Widget) Prev() {
widget.Idx--
if widget.Idx < 0 {
widget.Idx = len(widget.GitlabProjects) - 1
}
widget.display()
}
func (widget *Widget) HelpText() string { func (widget *Widget) HelpText() string {
return widget.KeyboardWidget.HelpText() return widget.KeyboardWidget.HelpText()
} }

View File

@ -53,14 +53,16 @@ func (widget *Widget) ProjectAt(idx int) *Project {
return widget.projects[idx] return widget.projects[idx]
} }
func (w *Widget) Refresh() { func (widget *Widget) Refresh() {
if w.Disabled() || w.CurrentProject() == nil { if widget.Disabled() || widget.CurrentProject() == nil {
w.SetItemCount(0) widget.SetItemCount(0)
return return
} }
w.SetItemCount(len(w.CurrentProject().tasks)) widget.loadProjects()
w.display()
widget.SetItemCount(len(widget.CurrentProject().tasks))
widget.display()
} }
func (widget *Widget) HelpText() string { func (widget *Widget) HelpText() string {

View File

@ -4,9 +4,10 @@ import "github.com/gdamore/tcell"
func (widget *Widget) initializeKeyboardControls() { func (widget *Widget) initializeKeyboardControls() {
widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt") widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt")
widget.SetKeyboardChar("h", widget.Prev, "Select previous item") widget.SetKeyboardChar("r", widget.Refresh, "Refresh Widget")
widget.SetKeyboardChar("l", widget.Next, "Select next item") 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.KeyLeft, widget.PrevSource, "Select previous city")
widget.SetKeyboardKey(tcell.KeyRight, widget.Next, "Select next item") widget.SetKeyboardKey(tcell.KeyRight, widget.NextSource, "Select next city")
} }

View File

@ -9,29 +9,32 @@ import (
// Widget is the container for weather data. // Widget is the container for weather data.
type Widget struct { type Widget struct {
wtf.KeyboardWidget wtf.KeyboardWidget
wtf.MultiSourceWidget
wtf.TextWidget wtf.TextWidget
// APIKey string // APIKey string
Data []*owm.CurrentWeatherData Data []*owm.CurrentWeatherData
Idx int
pages *tview.Pages
settings *Settings settings *Settings
} }
// NewWidget creates and returns a new instance of the weather Widget // NewWidget creates and returns a new instance of the weather Widget
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common),
TextWidget: wtf.NewTextWidget(app, settings.common, true), MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "cityid", "cityids"),
TextWidget: wtf.NewTextWidget(app, settings.common, true),
Idx: 0,
pages: pages,
settings: settings, settings: settings,
} }
widget.initializeKeyboardControls() widget.initializeKeyboardControls()
widget.View.SetInputCapture(widget.InputCapture) widget.View.SetInputCapture(widget.InputCapture)
widget.SetDisplayFunction(widget.display)
widget.KeyboardWidget.SetView(widget.View) widget.KeyboardWidget.SetView(widget.View)
return &widget return &widget
@ -65,28 +68,6 @@ func (widget *Widget) Refresh() {
widget.display() 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 { func (widget *Widget) HelpText() string {
return widget.KeyboardWidget.HelpText() return widget.KeyboardWidget.HelpText()
} }