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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user