mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-427 Use new keyboard implementation for widgets. Closes #427
This commit is contained in:
21
modules/gerrit/keyboard.go
Normal file
21
modules/gerrit/keyboard.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package gerrit
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.prevProject)
|
||||
widget.SetKeyboardChar("l", widget.nextProject)
|
||||
widget.SetKeyboardChar("j", widget.nextReview)
|
||||
widget.SetKeyboardChar("k", widget.prevReview)
|
||||
widget.SetKeyboardChar("r", widget.Refresh)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.prevProject)
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.nextProject)
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.nextReview)
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.prevReview)
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openReview)
|
||||
widget.SetKeyboardKey(tcell.KeyEsc, widget.unselect)
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"regexp"
|
||||
|
||||
glb "github.com/andygrunwald/go-gerrit"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
@@ -32,6 +31,7 @@ const HelpText = `
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
gerrit *glb.Client
|
||||
@@ -50,8 +50,9 @@ var (
|
||||
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
Idx: 0,
|
||||
|
||||
@@ -59,9 +60,11 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
widget.unselect()
|
||||
|
||||
return &widget
|
||||
@@ -196,49 +199,3 @@ func (widget *Widget) currentGerritProject() *GerritProject {
|
||||
|
||||
return widget.GerritProjects[widget.Idx]
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
return nil
|
||||
case "h":
|
||||
widget.prevProject()
|
||||
return nil
|
||||
case "l":
|
||||
widget.nextProject()
|
||||
return nil
|
||||
case "j":
|
||||
widget.nextReview()
|
||||
return nil
|
||||
case "k":
|
||||
widget.prevReview()
|
||||
return nil
|
||||
case "r":
|
||||
widget.Refresh()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyLeft:
|
||||
widget.prevProject()
|
||||
return nil
|
||||
case tcell.KeyRight:
|
||||
widget.nextProject()
|
||||
return nil
|
||||
case tcell.KeyDown:
|
||||
widget.nextReview()
|
||||
return nil
|
||||
case tcell.KeyUp:
|
||||
widget.prevReview()
|
||||
return nil
|
||||
case tcell.KeyEnter:
|
||||
widget.openReview()
|
||||
return nil
|
||||
case tcell.KeyEsc:
|
||||
widget.unselect()
|
||||
return event
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
14
modules/git/keyboard.go
Normal file
14
modules/git/keyboard.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package git
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.Prev)
|
||||
widget.SetKeyboardChar("l", widget.Next)
|
||||
widget.SetKeyboardChar("p", widget.Pull)
|
||||
widget.SetKeyboardChar("c", widget.Checkout)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev)
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.Next)
|
||||
}
|
||||
@@ -1,13 +1,14 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
|
||||
const HelpText = `
|
||||
@@ -29,6 +30,7 @@ const modalHeight = 7
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.MultiSourceWidget
|
||||
wtf.TextWidget
|
||||
|
||||
@@ -42,6 +44,7 @@ type Widget struct {
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "repository", "repositories"),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
@@ -50,10 +53,12 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.SetDisplayFunction(widget.display)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -244,34 +249,3 @@ func (widget *Widget) Prev() {
|
||||
widget.DisplayFunction()
|
||||
}
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
return nil
|
||||
case "h":
|
||||
widget.Prev()
|
||||
return nil
|
||||
case "l":
|
||||
widget.Next()
|
||||
return nil
|
||||
case "p":
|
||||
widget.Pull()
|
||||
return nil
|
||||
case "c":
|
||||
widget.Checkout()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyLeft:
|
||||
widget.Prev()
|
||||
return nil
|
||||
case tcell.KeyRight:
|
||||
widget.Next()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
17
modules/github/keyboard.go
Normal file
17
modules/github/keyboard.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package github
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.Prev)
|
||||
widget.SetKeyboardChar("l", widget.Next)
|
||||
widget.SetKeyboardChar("o", widget.openRepo)
|
||||
widget.SetKeyboardChar("r", widget.Refresh)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openRepo)
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev)
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.Next)
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package github
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
@@ -22,6 +21,7 @@ const HelpText = `
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
GithubRepos []*GithubRepo
|
||||
@@ -33,8 +33,9 @@ type Widget struct {
|
||||
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
Idx: 0,
|
||||
|
||||
@@ -44,8 +45,10 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.GithubRepos = widget.buildRepoCollection(widget.settings.repositories)
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -112,37 +115,6 @@ func (widget *Widget) currentGithubRepo() *GithubRepo {
|
||||
return widget.GithubRepos[widget.Idx]
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
return nil
|
||||
case "h":
|
||||
widget.Prev()
|
||||
return nil
|
||||
case "l":
|
||||
widget.Next()
|
||||
return nil
|
||||
case "r":
|
||||
widget.Refresh()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyEnter:
|
||||
widget.openRepo()
|
||||
return nil
|
||||
case tcell.KeyLeft:
|
||||
widget.Prev()
|
||||
return nil
|
||||
case tcell.KeyRight:
|
||||
widget.Next()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
func (widget *Widget) openRepo() {
|
||||
repo := widget.currentGithubRepo()
|
||||
|
||||
|
||||
13
modules/gitlab/keyboard.go
Normal file
13
modules/gitlab/keyboard.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package gitlab
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.Prev)
|
||||
widget.SetKeyboardChar("l", widget.Next)
|
||||
widget.SetKeyboardChar("r", widget.Refresh)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev)
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.Next)
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package gitlab
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
glb "github.com/xanzy/go-gitlab"
|
||||
@@ -21,6 +20,7 @@ const HelpText = `
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
GitlabProjects []*GitlabProject
|
||||
@@ -40,8 +40,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
}
|
||||
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
Idx: 0,
|
||||
|
||||
@@ -52,8 +53,10 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.GitlabProjects = widget.buildProjectCollection(settings.projects)
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -112,31 +115,3 @@ func (widget *Widget) currentGitlabProject() *GitlabProject {
|
||||
|
||||
return widget.GitlabProjects[widget.Idx]
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
return nil
|
||||
case "h":
|
||||
widget.Prev()
|
||||
return nil
|
||||
case "l":
|
||||
widget.Next()
|
||||
return nil
|
||||
case "r":
|
||||
widget.Refresh()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyLeft:
|
||||
widget.Prev()
|
||||
return nil
|
||||
case tcell.KeyRight:
|
||||
widget.Next()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
14
modules/gitter/keyboard.go
Normal file
14
modules/gitter/keyboard.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package gitter
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("j", widget.next)
|
||||
widget.SetKeyboardChar("k", widget.prev)
|
||||
widget.SetKeyboardChar("r", widget.Refresh)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.next)
|
||||
widget.SetKeyboardKey(tcell.KeyEsc, widget.unselect)
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.prev)
|
||||
}
|
||||
@@ -2,10 +2,10 @@ package gitter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gdamore/tcell"
|
||||
"strconv"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const HelpText = `
|
||||
@@ -20,8 +20,10 @@ const HelpText = `
|
||||
arrow up: Select the previous message in the list
|
||||
`
|
||||
|
||||
// A Widget represents a Gitter widget
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
app *tview.Application
|
||||
@@ -30,21 +32,26 @@ type Widget struct {
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
// NewWidget creates a new instance of a widget
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
app: app,
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.unselect()
|
||||
|
||||
widget.View.SetScrollable(true)
|
||||
widget.View.SetRegions(true)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -160,33 +167,3 @@ func (widget *Widget) unselect() {
|
||||
widget.selected = -1
|
||||
widget.display()
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
case "j":
|
||||
widget.next()
|
||||
return nil
|
||||
case "k":
|
||||
widget.prev()
|
||||
return nil
|
||||
case "r":
|
||||
widget.Refresh()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyDown:
|
||||
widget.next()
|
||||
return nil
|
||||
case tcell.KeyEsc:
|
||||
widget.unselect()
|
||||
return event
|
||||
case tcell.KeyUp:
|
||||
widget.prev()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
18
modules/hackernews/keyboard.go
Normal file
18
modules/hackernews/keyboard.go
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
package hackernews
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("j", widget.next)
|
||||
widget.SetKeyboardChar("k", widget.prev)
|
||||
widget.SetKeyboardChar("o", widget.openStory)
|
||||
widget.SetKeyboardChar("r", widget.Refresh)
|
||||
widget.SetKeyboardChar("c", widget.openComments)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.next)
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openStory)
|
||||
widget.SetKeyboardKey(tcell.KeyEsc, widget.unselect)
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.prev)
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
@@ -28,6 +27,7 @@ const HelpText = `
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
app *tview.Application
|
||||
@@ -38,19 +38,23 @@ type Widget struct {
|
||||
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
app: app,
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.unselect()
|
||||
|
||||
widget.View.SetScrollable(true)
|
||||
widget.View.SetRegions(true)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -171,39 +175,3 @@ func (widget *Widget) unselect() {
|
||||
widget.selected = -1
|
||||
widget.display()
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
case "j":
|
||||
widget.next()
|
||||
return nil
|
||||
case "k":
|
||||
widget.prev()
|
||||
return nil
|
||||
case "r":
|
||||
widget.Refresh()
|
||||
return nil
|
||||
case "c":
|
||||
widget.openComments()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyDown:
|
||||
widget.next()
|
||||
return nil
|
||||
case tcell.KeyEnter:
|
||||
widget.openStory()
|
||||
return nil
|
||||
case tcell.KeyEsc:
|
||||
widget.unselect()
|
||||
return event
|
||||
case tcell.KeyUp:
|
||||
widget.prev()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
16
modules/jenkins/keyboard.go
Normal file
16
modules/jenkins/keyboard.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package jenkins
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("j", widget.next)
|
||||
widget.SetKeyboardChar("k", widget.prev)
|
||||
widget.SetKeyboardChar("o", widget.openJob)
|
||||
widget.SetKeyboardChar("r", widget.Refresh)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.next)
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openJob)
|
||||
widget.SetKeyboardKey(tcell.KeyEsc, widget.unselect)
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.prev)
|
||||
}
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"regexp"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
const HelpText = `
|
||||
@@ -26,6 +26,7 @@ const HelpText = `
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
app *tview.Application
|
||||
@@ -36,19 +37,23 @@ type Widget struct {
|
||||
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
app: app,
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.unselect()
|
||||
|
||||
widget.View.SetScrollable(true)
|
||||
widget.View.SetRegions(true)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -167,36 +172,3 @@ func (widget *Widget) unselect() {
|
||||
widget.selected = -1
|
||||
widget.display()
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
case "j":
|
||||
widget.next()
|
||||
return nil
|
||||
case "k":
|
||||
widget.prev()
|
||||
return nil
|
||||
case "r":
|
||||
widget.Refresh()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyDown:
|
||||
widget.next()
|
||||
return nil
|
||||
case tcell.KeyEnter:
|
||||
widget.openJob()
|
||||
return nil
|
||||
case tcell.KeyEsc:
|
||||
widget.unselect()
|
||||
return event
|
||||
case tcell.KeyUp:
|
||||
widget.prev()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
27
modules/jira/keyboard.go
Normal file
27
modules/jira/keyboard.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package jira
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("j", widget.selectNext)
|
||||
widget.SetKeyboardChar("k", widget.selectPrev)
|
||||
widget.SetKeyboardChar("o", widget.openItem)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.selectNext)
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openItem)
|
||||
widget.SetKeyboardKey(tcell.KeyEsc, widget.unselect)
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.selectPrev)
|
||||
}
|
||||
|
||||
func (widget *Widget) selectNext() {
|
||||
widget.next()
|
||||
widget.display()
|
||||
}
|
||||
|
||||
func (widget *Widget) selectPrev() {
|
||||
widget.prev()
|
||||
widget.display()
|
||||
}
|
||||
@@ -3,10 +3,10 @@ package jira
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"strconv"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const HelpText = `
|
||||
@@ -24,6 +24,7 @@ const HelpText = `
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
app *tview.Application
|
||||
@@ -34,19 +35,24 @@ type Widget struct {
|
||||
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
app: app,
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.unselect()
|
||||
|
||||
widget.View.SetScrollable(true)
|
||||
widget.View.SetRegions(true)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
@@ -163,44 +169,3 @@ func (widget *Widget) issueTypeColor(issue *Issue) string {
|
||||
return "white"
|
||||
}
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
case "j":
|
||||
// Select the next item down
|
||||
widget.next()
|
||||
widget.display()
|
||||
return nil
|
||||
case "k":
|
||||
// Select the next item up
|
||||
widget.prev()
|
||||
widget.display()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyDown:
|
||||
// Select the next item down
|
||||
widget.next()
|
||||
widget.display()
|
||||
return nil
|
||||
case tcell.KeyEnter:
|
||||
widget.openItem()
|
||||
return nil
|
||||
case tcell.KeyEsc:
|
||||
// Unselect the current row
|
||||
widget.unselect()
|
||||
widget.display()
|
||||
return event
|
||||
case tcell.KeyUp:
|
||||
// Select the next item up
|
||||
widget.prev()
|
||||
widget.display()
|
||||
return nil
|
||||
default:
|
||||
// Pass it along
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
14
modules/mercurial/keyboard.go
Normal file
14
modules/mercurial/keyboard.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package mercurial
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.Prev)
|
||||
widget.SetKeyboardChar("l", widget.Next)
|
||||
widget.SetKeyboardChar("p", widget.Pull)
|
||||
widget.SetKeyboardChar("c", widget.Checkout)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev)
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.Next)
|
||||
}
|
||||
@@ -23,8 +23,10 @@ const offscreen = -1000
|
||||
const modalWidth = 80
|
||||
const modalHeight = 7
|
||||
|
||||
// A Widget represents a Mercurial widget
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.MultiSourceWidget
|
||||
wtf.TextWidget
|
||||
|
||||
@@ -34,9 +36,11 @@ type Widget struct {
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
// NewWidget creates a new instance of a widget
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "repository", "repositories"),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
@@ -47,8 +51,10 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.SetDisplayFunction(widget.display)
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -170,34 +176,3 @@ func (widget *Widget) mercurialRepos(repoPaths []string) []*MercurialRepo {
|
||||
|
||||
return repos
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
return nil
|
||||
case "h":
|
||||
widget.Prev()
|
||||
return nil
|
||||
case "l":
|
||||
widget.Next()
|
||||
return nil
|
||||
case "p":
|
||||
widget.Pull()
|
||||
return nil
|
||||
case "c":
|
||||
widget.Checkout()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyLeft:
|
||||
widget.Prev()
|
||||
return nil
|
||||
case tcell.KeyRight:
|
||||
widget.Next()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
28
modules/nbascore/keyboard.go
Normal file
28
modules/nbascore/keyboard.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package nbascore
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.prev)
|
||||
widget.SetKeyboardChar("l", widget.next)
|
||||
widget.SetKeyboardChar("c", widget.center)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.prev)
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.next)
|
||||
}
|
||||
|
||||
func (widget *Widget) center() {
|
||||
offset = 0
|
||||
widget.Refresh()
|
||||
}
|
||||
|
||||
func (widget *Widget) next() {
|
||||
offset++
|
||||
widget.Refresh()
|
||||
}
|
||||
|
||||
func (widget *Widget) prev() {
|
||||
offset--
|
||||
widget.Refresh()
|
||||
}
|
||||
@@ -3,13 +3,13 @@ package nbascore
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
|
||||
const HelpText = `
|
||||
@@ -19,8 +19,10 @@ const HelpText = `
|
||||
c: Go back to current day
|
||||
`
|
||||
|
||||
// A Widget represents an NBA Score widget
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
app *tview.Application
|
||||
@@ -31,19 +33,24 @@ type Widget struct {
|
||||
|
||||
var offset = 0
|
||||
|
||||
// NewWidget creates a new instance of a widget
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
app: app,
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.View.SetScrollable(true)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
@@ -142,36 +149,3 @@ func (widget *Widget) nbascore() {
|
||||
widget.View.SetText(allGame)
|
||||
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch (string)(event.Rune()) {
|
||||
case "h":
|
||||
offset--
|
||||
widget.Refresh()
|
||||
return nil
|
||||
case "l":
|
||||
offset++
|
||||
widget.Refresh()
|
||||
return nil
|
||||
case "c":
|
||||
offset = 0
|
||||
widget.Refresh()
|
||||
return nil
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyLeft:
|
||||
offset--
|
||||
widget.Refresh()
|
||||
return nil
|
||||
case tcell.KeyRight:
|
||||
offset++
|
||||
widget.Refresh()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
17
modules/rollbar/keyboard.go
Normal file
17
modules/rollbar/keyboard.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package rollbar
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("j", widget.next)
|
||||
widget.SetKeyboardChar("k", widget.prev)
|
||||
widget.SetKeyboardChar("o", widget.openBuild)
|
||||
widget.SetKeyboardChar("r", widget.Refresh)
|
||||
widget.SetKeyboardChar("u", widget.unselect)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.next)
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openBuild)
|
||||
widget.SetKeyboardKey(tcell.KeyEsc, widget.unselect)
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.prev)
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package rollbar
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
@@ -23,8 +22,10 @@ const HelpText = `
|
||||
return: Open the selected item in a browser
|
||||
`
|
||||
|
||||
// A Widget represents a Rollbar widget
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
app *tview.Application
|
||||
@@ -33,19 +34,23 @@ type Widget struct {
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
// NewWidget creates a new instance of a widget
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
app: app,
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.unselect()
|
||||
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -184,40 +189,3 @@ func (widget *Widget) unselect() {
|
||||
widget.selected = -1
|
||||
widget.display()
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
case "j":
|
||||
widget.next()
|
||||
return nil
|
||||
case "k":
|
||||
widget.prev()
|
||||
return nil
|
||||
case "r":
|
||||
widget.Refresh()
|
||||
return nil
|
||||
case "u":
|
||||
widget.unselect()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyDown:
|
||||
widget.next()
|
||||
return nil
|
||||
case tcell.KeyEnter:
|
||||
widget.openBuild()
|
||||
return nil
|
||||
case tcell.KeyEsc:
|
||||
widget.unselect()
|
||||
return event
|
||||
case tcell.KeyUp:
|
||||
widget.prev()
|
||||
widget.display()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
30
modules/spotify/keyboard.go
Normal file
30
modules/spotify/keyboard.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package spotify
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.previous)
|
||||
widget.SetKeyboardChar("l", widget.next)
|
||||
widget.SetKeyboardChar(" ", widget.playPause)
|
||||
}
|
||||
|
||||
func (widget *Widget) previous() {
|
||||
widget.SpotifyClient.Previous()
|
||||
time.Sleep(time.Second * 1)
|
||||
widget.Refresh()
|
||||
}
|
||||
|
||||
func (widget *Widget) next() {
|
||||
widget.SpotifyClient.Next()
|
||||
time.Sleep(time.Second * 1)
|
||||
widget.Refresh()
|
||||
}
|
||||
|
||||
func (widget *Widget) playPause() {
|
||||
widget.SpotifyClient.PlayPause()
|
||||
time.Sleep(time.Second * 1)
|
||||
widget.Refresh()
|
||||
}
|
||||
@@ -2,9 +2,7 @@ package spotify
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/sticreations/spotigopher/spotigopher"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
@@ -17,8 +15,10 @@ const HelpText = `
|
||||
[l] for Next Song
|
||||
`
|
||||
|
||||
// A Widget represents a Spotify widget
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
app *tview.Application
|
||||
@@ -27,11 +27,13 @@ type Widget struct {
|
||||
spotigopher.SpotifyClient
|
||||
}
|
||||
|
||||
// NewWidget creates a new instance of a widget
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
spotifyClient := spotigopher.NewClient()
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
Info: spotigopher.Info{},
|
||||
SpotifyClient: spotifyClient,
|
||||
@@ -42,11 +44,15 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.settings.common.RefreshInterval = 5
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.View.SetInputCapture(widget.captureInput)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetWordWrap(true)
|
||||
widget.View.SetTitle(fmt.Sprint("[green]Spotify[white]"))
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
@@ -72,27 +78,6 @@ func (w *Widget) render() {
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Widget) captureInput(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch (string)(event.Rune()) {
|
||||
case "h":
|
||||
w.SpotifyClient.Previous()
|
||||
time.Sleep(time.Second * 1)
|
||||
w.Refresh()
|
||||
return nil
|
||||
case "l":
|
||||
w.SpotifyClient.Next()
|
||||
time.Sleep(time.Second * 1)
|
||||
w.Refresh()
|
||||
return nil
|
||||
case " ":
|
||||
w.SpotifyClient.PlayPause()
|
||||
time.Sleep(time.Second * 1)
|
||||
w.Refresh()
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *Widget) createOutput() string {
|
||||
output := wtf.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.Width())
|
||||
output += wtf.CenterText(fmt.Sprintf("[green]Title:[white] %v\n ", w.Info.Title), w.Width())
|
||||
|
||||
42
modules/spotifyweb/keyboard.go
Normal file
42
modules/spotifyweb/keyboard.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package spotifyweb
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.selectPrevious)
|
||||
widget.SetKeyboardChar("l", widget.selectNext)
|
||||
widget.SetKeyboardChar(" ", widget.playPause)
|
||||
widget.SetKeyboardChar("s", widget.toggleShuffle)
|
||||
}
|
||||
|
||||
func (widget *Widget) selectPrevious() {
|
||||
widget.client.Previous()
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
widget.Refresh()
|
||||
}
|
||||
|
||||
func (widget *Widget) selectNext() {
|
||||
widget.client.Next()
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
widget.Refresh()
|
||||
}
|
||||
|
||||
func (widget *Widget) playPause() {
|
||||
if widget.playerState.CurrentlyPlaying.Playing {
|
||||
widget.client.Pause()
|
||||
} else {
|
||||
widget.client.Play()
|
||||
}
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
widget.Refresh()
|
||||
}
|
||||
|
||||
func (widget *Widget) toggleShuffle() {
|
||||
widget.playerState.ShuffleState = !widget.playerState.ShuffleState
|
||||
widget.client.Shuffle(widget.playerState.ShuffleState)
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
widget.Refresh()
|
||||
}
|
||||
@@ -4,9 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/logger"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
@@ -45,6 +43,7 @@ type Info struct {
|
||||
// Widget is the struct used by all WTF widgets to transfer to the main widget controller
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
Info
|
||||
@@ -94,8 +93,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
var playerState *spotify.PlayerState
|
||||
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
Info: Info{},
|
||||
|
||||
@@ -141,11 +141,15 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.settings.common.RefreshInterval = 5
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.View.SetInputCapture(widget.captureInput)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetWordWrap(true)
|
||||
widget.View.SetTitle("[green]Spotify Web[white]")
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
@@ -192,40 +196,6 @@ func (w *Widget) render() {
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Widget) captureInput(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch (string)(event.Rune()) {
|
||||
case "/":
|
||||
w.ShowHelp()
|
||||
return nil
|
||||
case "h":
|
||||
w.client.Previous()
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
w.Refresh()
|
||||
return nil
|
||||
case "l":
|
||||
w.client.Next()
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
w.Refresh()
|
||||
return nil
|
||||
case " ":
|
||||
if w.playerState.CurrentlyPlaying.Playing {
|
||||
w.client.Pause()
|
||||
} else {
|
||||
w.client.Play()
|
||||
}
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
w.Refresh()
|
||||
return nil
|
||||
case "s":
|
||||
w.playerState.ShuffleState = !w.playerState.ShuffleState
|
||||
w.client.Shuffle(w.playerState.ShuffleState)
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
w.Refresh()
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *Widget) createOutput() string {
|
||||
output := wtf.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.Width())
|
||||
output += wtf.CenterText(fmt.Sprintf("[green]Title:[white] %v\n", w.Info.Title), w.Width())
|
||||
|
||||
21
modules/textfile/keyboard.go
Normal file
21
modules/textfile/keyboard.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package textfile
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.Prev)
|
||||
widget.SetKeyboardChar("l", widget.Next)
|
||||
widget.SetKeyboardChar("o", widget.openFile)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev)
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.Next)
|
||||
}
|
||||
|
||||
func (widget *Widget) openFile() {
|
||||
src := widget.CurrentSource()
|
||||
wtf.OpenFile(src)
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/alecthomas/chroma/formatters"
|
||||
"github.com/alecthomas/chroma/lexers"
|
||||
"github.com/alecthomas/chroma/styles"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/radovskyb/watcher"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
@@ -32,6 +31,7 @@ const HelpText = `
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.MultiSourceWidget
|
||||
wtf.TextWidget
|
||||
|
||||
@@ -39,9 +39,11 @@ type Widget struct {
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
// NewWidget creates a new instance of a widget
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "filePath", "filePaths"),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
@@ -52,11 +54,14 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
// Don't use a timer for this widget, watch for filesystem changes instead
|
||||
widget.settings.common.RefreshInterval = 0
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.SetDisplayFunction(widget.display)
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetWordWrap(true)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
widget.View.SetWrap(true)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
|
||||
go widget.watchForFileChanges()
|
||||
|
||||
@@ -139,36 +144,6 @@ func (widget *Widget) plainText() string {
|
||||
return string(text)
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
return nil
|
||||
case "h":
|
||||
widget.Prev()
|
||||
return nil
|
||||
case "l":
|
||||
widget.Next()
|
||||
return nil
|
||||
case "o":
|
||||
wtf.OpenFile(widget.CurrentSource())
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyLeft:
|
||||
widget.Prev()
|
||||
return nil
|
||||
case tcell.KeyRight:
|
||||
widget.Next()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
|
||||
return event
|
||||
}
|
||||
|
||||
func (widget *Widget) watchForFileChanges() {
|
||||
watch := watcher.New()
|
||||
watch.FilterOps(watcher.Write)
|
||||
|
||||
@@ -63,9 +63,10 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
}
|
||||
|
||||
widget.init()
|
||||
widget.initializeKeyboardControls()
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.View.SetRegions(true)
|
||||
widget.View.SetScrollable(true)
|
||||
|
||||
|
||||
19
modules/todoist/keyboard.go
Normal file
19
modules/todoist/keyboard.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package todoist
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("c", widget.Close)
|
||||
widget.SetKeyboardChar("d", widget.Delete)
|
||||
widget.SetKeyboardChar("h", widget.PreviousProject)
|
||||
widget.SetKeyboardChar("j", widget.Up)
|
||||
widget.SetKeyboardChar("k", widget.Down)
|
||||
widget.SetKeyboardChar("l", widget.NextProject)
|
||||
widget.SetKeyboardChar("r", widget.Refresh)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.Down)
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.PreviousProject)
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.NextProject)
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.Up)
|
||||
}
|
||||
@@ -25,8 +25,10 @@ const HelpText = `
|
||||
arrow up: Select the previous item in the list
|
||||
`
|
||||
|
||||
// A Widget represents a Todoist widget
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
app *tview.Application
|
||||
@@ -35,10 +37,12 @@ type Widget struct {
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
// NewWidget creates a new instance of a widget
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
app: app,
|
||||
settings: settings,
|
||||
@@ -47,8 +51,10 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.loadAPICredentials()
|
||||
widget.loadProjects()
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -135,44 +141,6 @@ func (w *Widget) Delete() {
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func (w *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
if len(w.projects) == 0 {
|
||||
return event
|
||||
}
|
||||
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
w.ShowHelp()
|
||||
return nil
|
||||
case "r":
|
||||
w.Refresh()
|
||||
return nil
|
||||
case "d":
|
||||
w.Delete()
|
||||
return nil
|
||||
case "c":
|
||||
w.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch w.vimBindings(event) {
|
||||
case tcell.KeyLeft:
|
||||
w.PreviousProject()
|
||||
return nil
|
||||
case tcell.KeyRight:
|
||||
w.NextProject()
|
||||
return nil
|
||||
case tcell.KeyUp:
|
||||
w.Up()
|
||||
return nil
|
||||
case tcell.KeyDown:
|
||||
w.Down()
|
||||
return nil
|
||||
}
|
||||
|
||||
return event
|
||||
}
|
||||
|
||||
func (widget *Widget) loadAPICredentials() {
|
||||
todoist.Token = widget.settings.apiKey
|
||||
}
|
||||
|
||||
16
modules/travisci/keyboard.go
Normal file
16
modules/travisci/keyboard.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package travisci
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("j", widget.next)
|
||||
widget.SetKeyboardChar("k", widget.prev)
|
||||
widget.SetKeyboardChar("o", widget.openBuild)
|
||||
widget.SetKeyboardChar("r", widget.Refresh)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.next)
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openBuild)
|
||||
widget.SetKeyboardKey(tcell.KeyEsc, widget.unselect)
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.prev)
|
||||
}
|
||||
@@ -2,10 +2,10 @@ package travisci
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gdamore/tcell"
|
||||
"strings"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const HelpText = `
|
||||
@@ -24,6 +24,7 @@ const HelpText = `
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
app *tview.Application
|
||||
@@ -34,17 +35,20 @@ type Widget struct {
|
||||
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
app: app,
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.unselect()
|
||||
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -167,37 +171,3 @@ func (widget *Widget) unselect() {
|
||||
widget.selected = -1
|
||||
widget.display()
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
case "j":
|
||||
widget.next()
|
||||
return nil
|
||||
case "k":
|
||||
widget.prev()
|
||||
return nil
|
||||
case "r":
|
||||
widget.Refresh()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyDown:
|
||||
widget.next()
|
||||
return nil
|
||||
case tcell.KeyEnter:
|
||||
widget.openBuild()
|
||||
return nil
|
||||
case tcell.KeyEsc:
|
||||
widget.unselect()
|
||||
return event
|
||||
case tcell.KeyUp:
|
||||
widget.prev()
|
||||
widget.display()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
22
modules/twitter/keyboard.go
Normal file
22
modules/twitter/keyboard.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package twitter
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.Prev)
|
||||
widget.SetKeyboardChar("l", widget.Next)
|
||||
widget.SetKeyboardChar("o", widget.openFile)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openFile)
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev)
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.Next)
|
||||
}
|
||||
|
||||
func (widget *Widget) openFile() {
|
||||
src := widget.currentSourceURI()
|
||||
wtf.OpenFile(src)
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"regexp"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
@@ -25,6 +24,7 @@ const HelpText = `
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.MultiSourceWidget
|
||||
wtf.TextWidget
|
||||
|
||||
@@ -38,6 +38,7 @@ type Widget struct {
|
||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "screenName", "screenNames"),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
@@ -46,7 +47,8 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.SetDisplayFunction(widget.display)
|
||||
|
||||
@@ -55,7 +57,8 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.View.SetBorderPadding(1, 1, 1, 1)
|
||||
widget.View.SetWrap(true)
|
||||
widget.View.SetWordWrap(true)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -143,36 +146,8 @@ func (widget *Widget) format(tweet Tweet) string {
|
||||
|
||||
return fmt.Sprintf("%s\n[grey]%s[white]\n\n", body, attribution)
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
return nil
|
||||
case "h":
|
||||
widget.Prev()
|
||||
return nil
|
||||
case "l":
|
||||
widget.Next()
|
||||
return nil
|
||||
case "o":
|
||||
wtf.OpenFile(widget.currentSourceURI())
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyLeft:
|
||||
widget.Prev()
|
||||
return nil
|
||||
case tcell.KeyRight:
|
||||
widget.Next()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
func (widget *Widget) currentSourceURI() string {
|
||||
|
||||
src := "https://twitter.com/" + widget.CurrentSource()
|
||||
return src
|
||||
}
|
||||
|
||||
12
modules/weatherservices/weather/keyboard.go
Normal file
12
modules/weatherservices/weather/keyboard.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package weather
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.Prev)
|
||||
widget.SetKeyboardChar("l", widget.Next)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev)
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.Next)
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package weather
|
||||
|
||||
import (
|
||||
owm "github.com/briandowns/openweathermap"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
@@ -21,6 +20,7 @@ const HelpText = `
|
||||
// Widget is the container for weather data.
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
// APIKey string
|
||||
@@ -31,11 +31,12 @@ type Widget struct {
|
||||
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 {
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
Idx: 0,
|
||||
|
||||
@@ -43,8 +44,10 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -144,28 +147,3 @@ func (widget *Widget) currentWeather(cityCode int) (*owm.CurrentWeatherData, err
|
||||
|
||||
return weather, nil
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
return nil
|
||||
case "h":
|
||||
widget.Prev()
|
||||
return nil
|
||||
case "l":
|
||||
widget.Next()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyLeft:
|
||||
widget.Prev()
|
||||
return nil
|
||||
case tcell.KeyRight:
|
||||
widget.Next()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
24
modules/zendesk/keyboard.go
Normal file
24
modules/zendesk/keyboard.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package zendesk
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("j", widget.selectNext)
|
||||
widget.SetKeyboardChar("k", widget.selectPrev)
|
||||
widget.SetKeyboardChar("o", widget.openTicket)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.selectNext)
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.selectPrev)
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openTicket)
|
||||
widget.SetKeyboardKey(tcell.KeyEsc, widget.unselect)
|
||||
}
|
||||
|
||||
func (widget *Widget) selectNext() {
|
||||
widget.next()
|
||||
widget.display()
|
||||
}
|
||||
|
||||
func (widget *Widget) selectPrev() {
|
||||
widget.prev()
|
||||
widget.display()
|
||||
}
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
|
||||
// A Widget represents a Zendesk widget
|
||||
type Widget struct {
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
app *tview.Application
|
||||
@@ -18,20 +19,24 @@ type Widget struct {
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
// NewWidget creates a new instance of a widget
|
||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
app: app,
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
ticketArray, err := widget.newTickets()
|
||||
ticketArray.Count = len(ticketArray.Tickets)
|
||||
@@ -108,49 +113,11 @@ func (widget *Widget) openTicket() {
|
||||
sel := widget.selected
|
||||
if sel >= 0 && widget.result != nil && sel < len(widget.result.Tickets) {
|
||||
issue := &widget.result.Tickets[widget.selected]
|
||||
ticketUrl := fmt.Sprintf("https://%s.zendesk.com/agent/tickets/%d", widget.settings.subdomain, issue.Id)
|
||||
wtf.OpenFile(ticketUrl)
|
||||
ticketURL := fmt.Sprintf("https://%s.zendesk.com/agent/tickets/%d", widget.settings.subdomain, issue.Id)
|
||||
wtf.OpenFile(ticketURL)
|
||||
}
|
||||
}
|
||||
|
||||
func (widget *Widget) unselect() {
|
||||
widget.selected = -1
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "j":
|
||||
// Select the next item down
|
||||
widget.next()
|
||||
widget.display()
|
||||
return nil
|
||||
case "k":
|
||||
// Select the next item up
|
||||
widget.prev()
|
||||
widget.display()
|
||||
return nil
|
||||
}
|
||||
switch event.Key() {
|
||||
case tcell.KeyDown:
|
||||
// Select the next item down
|
||||
widget.next()
|
||||
widget.display()
|
||||
return nil
|
||||
case tcell.KeyUp:
|
||||
// Select the next item up
|
||||
widget.prev()
|
||||
widget.display()
|
||||
return nil
|
||||
case tcell.KeyEnter:
|
||||
widget.openTicket()
|
||||
return nil
|
||||
case tcell.KeyEsc:
|
||||
// Unselect the current row
|
||||
widget.unselect()
|
||||
widget.display()
|
||||
return event
|
||||
default:
|
||||
// Pass it along
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user