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

Have keyboard widget manage its own help

Define help with keys
This means that keys and help are automatically in sync
This means that you can't define keys, but forget help
This unfortunately also means that formatting may not be quite as good
This commit is contained in:
Sean Smith
2019-05-11 11:14:02 -04:00
parent e9e62c2065
commit 7f3daaac59
47 changed files with 269 additions and 641 deletions

View File

@@ -5,17 +5,17 @@ import (
)
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.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help window")
widget.SetKeyboardChar("h", widget.prevProject, "Select previous project")
widget.SetKeyboardChar("l", widget.nextProject, "Select next project")
widget.SetKeyboardChar("j", widget.nextReview, "Select next review")
widget.SetKeyboardChar("k", widget.prevReview, "Select previous review")
widget.SetKeyboardChar("r", widget.Refresh, "Refresh items")
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)
widget.SetKeyboardKey(tcell.KeyLeft, widget.prevProject, "Select previous project")
widget.SetKeyboardKey(tcell.KeyRight, widget.nextProject, "Select next project")
widget.SetKeyboardKey(tcell.KeyDown, widget.nextReview, "Select next review")
widget.SetKeyboardKey(tcell.KeyUp, widget.prevReview, "Select previous review")
widget.SetKeyboardKey(tcell.KeyEnter, widget.openReview, "Open review in browser")
widget.SetKeyboardKey(tcell.KeyEsc, widget.unselect, "Clear selection")
}

View File

@@ -11,26 +11,7 @@ import (
"github.com/wtfutil/wtf/wtf"
)
const HelpText = `
Keyboard commands for Gerrit:
/: Show/hide this help window
h: Show the previous project
l: Show the next project
j: Select the next review in the list
k: Select the previous review in the list
r: Refresh the data
arrow left: Show the previous project
arrow right: Show the next project
arrow down: Select the next review in the list
arrow up: Select the previous review in the list
return: Open the selected review in a browser
`
type Widget struct {
wtf.HelpfulWidget
wtf.KeyboardWidget
wtf.TextWidget
@@ -49,8 +30,7 @@ var (
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
widget := Widget{
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
KeyboardWidget: wtf.NewKeyboardWidget(),
KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common),
TextWidget: wtf.NewTextWidget(app, settings.common, true),
Idx: 0,
@@ -61,7 +41,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
widget.initializeKeyboardControls()
widget.View.SetInputCapture(widget.InputCapture)
widget.HelpfulWidget.SetView(widget.View)
widget.KeyboardWidget.SetView(widget.View)
widget.unselect()