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:
@@ -9,20 +9,20 @@ import (
|
||||
)
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar(" ", widget.toggleChecked)
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("j", widget.displayNext)
|
||||
widget.SetKeyboardChar("k", widget.displayPrev)
|
||||
widget.SetKeyboardChar("n", widget.newItem)
|
||||
widget.SetKeyboardChar("o", widget.openFile)
|
||||
widget.SetKeyboardChar(" ", widget.toggleChecked, "Toggle checkmark")
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt")
|
||||
widget.SetKeyboardChar("j", widget.displayNext, "Select next item")
|
||||
widget.SetKeyboardChar("k", widget.displayPrev, "Select previous item")
|
||||
widget.SetKeyboardChar("n", widget.newItem, "Create new item")
|
||||
widget.SetKeyboardChar("o", widget.openFile, "Open file")
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyCtrlD, widget.deleteSelected)
|
||||
widget.SetKeyboardKey(tcell.KeyCtrlJ, widget.demoteSelected)
|
||||
widget.SetKeyboardKey(tcell.KeyCtrlK, widget.promoteSelected)
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.displayNext)
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.editSelected)
|
||||
widget.SetKeyboardKey(tcell.KeyEsc, widget.unselect)
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.displayPrev)
|
||||
widget.SetKeyboardKey(tcell.KeyCtrlD, widget.deleteSelected, "Delete item")
|
||||
widget.SetKeyboardKey(tcell.KeyCtrlJ, widget.demoteSelected, "Demote item")
|
||||
widget.SetKeyboardKey(tcell.KeyCtrlK, widget.promoteSelected, "Promote item")
|
||||
widget.SetKeyboardKey(tcell.KeyDown, widget.displayNext, "Select next item")
|
||||
widget.SetKeyboardKey(tcell.KeyEnter, widget.editSelected, "Edit item")
|
||||
widget.SetKeyboardKey(tcell.KeyEsc, widget.unselect, "Clear selection")
|
||||
widget.SetKeyboardKey(tcell.KeyUp, widget.displayPrev, "Select previous item")
|
||||
}
|
||||
|
||||
func (widget *Widget) deleteSelected() {
|
||||
|
||||
@@ -12,32 +12,12 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const HelpText = `
|
||||
Keyboard commands for Todo:
|
||||
|
||||
/: Show/hide this help window
|
||||
j: Select the next item in the list
|
||||
k: Select the previous item in the list
|
||||
n: Create a new list item
|
||||
o: Open the todo file in the operating system
|
||||
|
||||
arrow down: Select the next item in the list
|
||||
arrow up: Select the previous item in the list
|
||||
|
||||
ctrl-d: Delete the selected item
|
||||
|
||||
esc: Unselect the todo list
|
||||
return: Edit selected item
|
||||
space: Check the selected item on or off
|
||||
`
|
||||
|
||||
const offscreen = -1000
|
||||
const modalWidth = 80
|
||||
const modalHeight = 7
|
||||
|
||||
// A Widget represents a Todo widget
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
@@ -51,8 +31,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),
|
||||
|
||||
app: app,
|
||||
@@ -70,7 +49,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.View.SetRegions(true)
|
||||
widget.View.SetScrollable(true)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user