mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Remove the need for every module to define a widget.ShowHelp keyboard control
This common functionality is moved up to KeyboardWidget. Modules now include widget.InitializeCommonControls() instead.
This commit is contained in:
@@ -31,7 +31,7 @@ type KeyboardWidget struct {
|
||||
|
||||
// NewKeyboardWidget creates and returns a new instance of KeyboardWidget
|
||||
func NewKeyboardWidget(app *tview.Application, pages *tview.Pages, settings *cfg.Common) KeyboardWidget {
|
||||
return KeyboardWidget{
|
||||
keyWidget := KeyboardWidget{
|
||||
app: app,
|
||||
pages: pages,
|
||||
settings: settings,
|
||||
@@ -40,6 +40,8 @@ func NewKeyboardWidget(app *tview.Application, pages *tview.Pages, settings *cfg
|
||||
charHelp: []helpItem{},
|
||||
keyHelp: []helpItem{},
|
||||
}
|
||||
|
||||
return keyWidget
|
||||
}
|
||||
|
||||
// SetKeyboardChar sets a character/function combination that responds to key presses
|
||||
@@ -70,6 +72,12 @@ func (widget *KeyboardWidget) SetKeyboardKey(key tcell.Key, fn func(), helpText
|
||||
}
|
||||
}
|
||||
|
||||
// InitializeCommonControls sets up the keyboard controls that are common to
|
||||
// all widgets that accept keyboard input
|
||||
func (widget *KeyboardWidget) InitializeCommonControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help prompt")
|
||||
}
|
||||
|
||||
// InputCapture is the function passed to tview's SetInputCapture() function
|
||||
// This is done during the main widget's creation process using the following code:
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user