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:
@@ -3,15 +3,15 @@ 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.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt")
|
||||
widget.SetKeyboardChar("j", widget.Next, "Select next item")
|
||||
widget.SetKeyboardChar("k", widget.Prev, "Select previous item")
|
||||
widget.SetKeyboardChar("o", widget.openBuild, "Open item in browser")
|
||||
widget.SetKeyboardChar("r", widget.Refresh, "Refresh widget")
|
||||
widget.SetKeyboardChar("u", widget.Unselect, "Clear selection")
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.Next)
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openBuild)
|
||||
widget.SetKeyboardKey(tcell.KeyEsc, widget.Unselect)
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.Prev)
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.Next, "Select next item")
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.openBuild, "Open item in browser")
|
||||
widget.SetKeyboardKey(tcell.KeyEsc, widget.Unselect, "Clear selection")
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.Prev, "Select previous item")
|
||||
}
|
||||
|
||||
@@ -7,24 +7,8 @@ import (
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
|
||||
const HelpText = `
|
||||
Keyboard commands for Rollbar:
|
||||
|
||||
/: Show/hide this help window
|
||||
j: Select the next item in the list
|
||||
k: Select the previous item in the list
|
||||
r: Refresh the data
|
||||
u: unselect the current item(removes item being perma highlighted)
|
||||
|
||||
arrow down: Select the next item in the list
|
||||
arrow up: Select the previous item in the list
|
||||
|
||||
return: Open the selected item in a browser
|
||||
`
|
||||
|
||||
// A Widget represents a Rollbar widget
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.ScrollableWidget
|
||||
|
||||
@@ -35,8 +19,7 @@ type Widget struct {
|
||||
// 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(),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common),
|
||||
ScrollableWidget: wtf.NewScrollableWidget(app, settings.common, true),
|
||||
|
||||
settings: settings,
|
||||
@@ -46,7 +29,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)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user