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,17 +3,17 @@ 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.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt")
widget.SetKeyboardChar("c", widget.Close, "Close item")
widget.SetKeyboardChar("d", widget.Delete, "Delete item")
widget.SetKeyboardChar("h", widget.PreviousProject, "Select previous project")
widget.SetKeyboardChar("j", widget.Up, "Select previous item")
widget.SetKeyboardChar("k", widget.Down, "Select next item")
widget.SetKeyboardChar("l", widget.NextProject, "Select next project")
widget.SetKeyboardChar("r", widget.Refresh, "Refresh widget")
widget.SetKeyboardKey(tcell.KeyDown, widget.Down)
widget.SetKeyboardKey(tcell.KeyLeft, widget.PreviousProject)
widget.SetKeyboardKey(tcell.KeyRight, widget.NextProject)
widget.SetKeyboardKey(tcell.KeyUp, widget.Up)
widget.SetKeyboardKey(tcell.KeyDown, widget.Down, "Select next item")
widget.SetKeyboardKey(tcell.KeyLeft, widget.PreviousProject, "Select previous project")
widget.SetKeyboardKey(tcell.KeyRight, widget.NextProject, "Select next project")
widget.SetKeyboardKey(tcell.KeyUp, widget.Up, "Select previous item")
}

View File

@@ -7,27 +7,8 @@ import (
"github.com/wtfutil/wtf/wtf"
)
const HelpText = `
Keyboard commands for Todoist:
/: Show/hide this help window
c: Close the selected item
d: Delete the selected item
h: Previous Todoist list
j: Select the next item in the list
k: Select the previous item in the list
l: Next Todoist list
r: Refresh the todo list data
arrow down: Select the next item in the list
arrow left: Previous Todoist list
arrow right: Next Todoist list
arrow up: Select the previous item in the list
`
// A Widget represents a Todoist widget
type Widget struct {
wtf.HelpfulWidget
wtf.KeyboardWidget
wtf.TextWidget
@@ -39,8 +20,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),
TextWidget: wtf.NewTextWidget(app, settings.common, true),
settings: settings,
@@ -52,7 +32,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
}