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:
parent
a9c5dc3be8
commit
2d0706c40b
@ -3,17 +3,13 @@ package wtftests
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/olebedev/config"
|
||||
. "github.com/stretchr/testify/assert"
|
||||
. "github.com/wtfutil/wtf/checklist"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
|
||||
/* -------------------- CheckMark -------------------- */
|
||||
|
||||
func TestCheckMark(t *testing.T) {
|
||||
loadConfig()
|
||||
|
||||
item := ChecklistItem{}
|
||||
Equal(t, " ", item.CheckMark())
|
||||
|
||||
@ -24,8 +20,6 @@ func TestCheckMark(t *testing.T) {
|
||||
/* -------------------- Toggle -------------------- */
|
||||
|
||||
func TestToggle(t *testing.T) {
|
||||
loadConfig()
|
||||
|
||||
item := ChecklistItem{}
|
||||
Equal(t, false, item.Checked)
|
||||
|
||||
@ -35,9 +29,3 @@ func TestToggle(t *testing.T) {
|
||||
item.Toggle()
|
||||
Equal(t, false, item.Checked)
|
||||
}
|
||||
|
||||
/* -------------------- helpers -------------------- */
|
||||
|
||||
func loadConfig() {
|
||||
wtf.Config, _ = config.ParseYamlFile("../_sample_configs/simple_config.yml")
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ const HelpText = `
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
app *tview.Application
|
||||
@ -24,18 +25,22 @@ 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(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, false),
|
||||
|
||||
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
|
||||
}
|
||||
@ -63,14 +68,4 @@ func (widget *Widget) display() {
|
||||
func (widget *Widget) unselect() {
|
||||
widget.selected = -1
|
||||
widget.display()
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
// This switch statement could handle alphanumeric keys
|
||||
switch string(event.Rune()) {
|
||||
}
|
||||
|
||||
// This switch statement could handle events like the "enter" key
|
||||
switch event.Key() {
|
||||
}
|
||||
}
|
||||
}
|
1
go.mod
1
go.mod
@ -47,5 +47,6 @@ require (
|
||||
golang.org/x/text v0.3.0
|
||||
google.golang.org/api v0.0.0-20190111181425-455dee39f703
|
||||
google.golang.org/appengine v1.4.0
|
||||
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20190314184232-a8ac0a50d0b5 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.2
|
||||
)
|
||||
|
7
go.sum
7
go.sum
@ -10,11 +10,14 @@ github.com/PagerDuty/go-pagerduty v0.0.0-20180528123509-b4a4067bdbde/go.mod h1:6
|
||||
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/adlio/trello v0.0.0-20181009211147-e4cc07c871d0 h1:mI+BqWX9HJIRw68D6yUBunwIHs6oJkqqwFKEogkHKkk=
|
||||
github.com/adlio/trello v0.0.0-20181009211147-e4cc07c871d0/go.mod h1:VjzhFGdnEJGih1AsIWi/yU6y01yZh0DuEWCNAyOJ1WE=
|
||||
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U=
|
||||
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI=
|
||||
github.com/alecthomas/chroma v0.6.2 h1:aV6n3C/Womqo1zPZ7eyI0viybDslfbgqTUqxMMyCrDM=
|
||||
github.com/alecthomas/chroma v0.6.2/go.mod h1:quT2EpvJNqkuPi6DmBHB+E33FXBgBBPzyH5++Dn1LPc=
|
||||
github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 h1:JHZL0hZKJ1VENNfmXvHbgYlbUOvpzYzvy2aZU5gXVeo=
|
||||
github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0=
|
||||
github.com/alecthomas/kong v0.1.15/go.mod h1:0m2VYms8rH0qbCqVB2gvGHk74bqLIq0HXjCs5bNbNQU=
|
||||
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY=
|
||||
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
|
||||
github.com/andygrunwald/go-gerrit v0.0.0-20190110184452-f48c3d16616f h1:R5XFuvUUbmwDtR2posQv+6vvKfty2+vL7IFsU6/TrNY=
|
||||
github.com/andygrunwald/go-gerrit v0.0.0-20190110184452-f48c3d16616f/go.mod h1:0iuRQp6WJ44ts+iihy5E/WlPqfg5RNeQxOmzRkxCdtk=
|
||||
@ -61,6 +64,7 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
|
||||
github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
@ -82,6 +86,7 @@ github.com/radovskyb/watcher v1.0.5 h1:wqt7gb+HjGacvFoLTKeT44C+XVPxu7bvHvKT1IvZ7
|
||||
github.com/radovskyb/watcher v1.0.5/go.mod h1:78okwvY5wPdzcb1UYnip1pvrZNIVEIh/Cm+ZuvsUYIg=
|
||||
github.com/rivo/tview v0.0.0-20181226202439-36893a669792 h1:3Jm4JCmIZchgwc405ygGCzM5eEiYb9sV3qLHWwz9uxo=
|
||||
github.com/rivo/tview v0.0.0-20181226202439-36893a669792/go.mod h1:J4W+hErFfITUbyFAEXizpmkuxX7ZN56dopxHB4XQhMw=
|
||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM=
|
||||
github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
@ -142,6 +147,8 @@ google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9M
|
||||
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20190314184232-a8ac0a50d0b5 h1:G5L6mi3mG1Ms5pQfIiUJEMNV64fqgQlpxlPf+4phLmw=
|
||||
gopkg.in/jarcoal/httpmock.v1 v1.0.0-20190314184232-a8ac0a50d0b5/go.mod h1:d3R+NllX3X5e0zlG1Rful3uLvsGC/Q3OHut5464DEQw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
4
main.go
4
main.go
@ -63,9 +63,6 @@ func refreshAllWidgets(widgets []wtf.Wtfable) {
|
||||
}
|
||||
}
|
||||
|
||||
func setTerm() {
|
||||
}
|
||||
|
||||
func watchForConfigChanges(app *tview.Application, configFilePath string, grid *tview.Grid, pages *tview.Pages) {
|
||||
watch := watcher.New()
|
||||
absPath, _ := wtf.ExpandHomeDir(configFilePath)
|
||||
@ -121,6 +118,7 @@ func main() {
|
||||
cfg.MigrateOldConfig()
|
||||
cfg.CreateConfigDir()
|
||||
cfg.CreateConfigFile()
|
||||
|
||||
config := cfg.LoadConfigFile(flags.ConfigFilePath())
|
||||
|
||||
if flags.Profile {
|
||||
|
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
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,8 @@ func (widget *HelpfulWidget) ShowHelp() {
|
||||
|
||||
widget.pages.AddPage("help", modal, false, true)
|
||||
widget.app.SetFocus(modal)
|
||||
|
||||
widget.app.QueueUpdate(func() {
|
||||
widget.app.Draw()
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user