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

@@ -3,15 +3,15 @@ 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.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help widget")
widget.SetKeyboardChar("j", widget.Next, "Select next item")
widget.SetKeyboardChar("k", widget.Prev, "Select previous item")
widget.SetKeyboardChar("o", widget.openStory, "Open story in browser")
widget.SetKeyboardChar("r", widget.Refresh, "Refresh widget")
widget.SetKeyboardChar("c", widget.openComments, "Open comments in browser")
widget.SetKeyboardKey(tcell.KeyDown, widget.Next)
widget.SetKeyboardKey(tcell.KeyEnter, widget.openStory)
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.openStory, "Open story in browser")
widget.SetKeyboardKey(tcell.KeyEsc, widget.Unselect, "Clear selection")
widget.SetKeyboardKey(tcell.KeyUp, widget.Prev, "Select previous item")
}

View File

@@ -9,23 +9,7 @@ import (
"github.com/wtfutil/wtf/wtf"
)
const HelpText = `
Keyboard commands for Hacker News:
/: Show/hide this help window
j: Select the next story in the list
k: Select the previous story in the list
r: Refresh the data
arrow down: Select the next story in the list
arrow up: Select the previous story in the list
return: Open the selected story in a browser
c: Open the comments of the article
`
type Widget struct {
wtf.HelpfulWidget
wtf.KeyboardWidget
wtf.ScrollableWidget
@@ -35,8 +19,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(),
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
}