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:
@@ -6,13 +6,13 @@ import (
|
||||
)
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.Prev)
|
||||
widget.SetKeyboardChar("l", widget.Next)
|
||||
widget.SetKeyboardChar("o", widget.openFile)
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt")
|
||||
widget.SetKeyboardChar("h", widget.Prev, "Select previous item")
|
||||
widget.SetKeyboardChar("l", widget.Next, "Select next item")
|
||||
widget.SetKeyboardChar("o", widget.openFile, "Open item")
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev)
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.Next)
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev, "Select previous item")
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.Next, "Select next item")
|
||||
}
|
||||
|
||||
func (widget *Widget) openFile() {
|
||||
|
||||
@@ -18,20 +18,7 @@ import (
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
)
|
||||
|
||||
const HelpText = `
|
||||
Keyboard commands for Textfile:
|
||||
|
||||
/: Show/hide this help window
|
||||
h: Previous text file
|
||||
l: Next text file
|
||||
o: Open the text file in the operating system
|
||||
|
||||
arrow left: Previous text file
|
||||
arrow right: Next text file
|
||||
`
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.MultiSourceWidget
|
||||
wtf.TextWidget
|
||||
@@ -43,8 +30,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),
|
||||
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "filePath", "filePaths"),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
@@ -62,7 +48,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
widget.View.SetWordWrap(true)
|
||||
widget.View.SetWrap(true)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.KeyboardWidget.SetView(widget.View)
|
||||
|
||||
go widget.watchForFileChanges()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user