mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Common help code into HelpfulWidget
This commit is contained in:
39
wtf/helpful_widget.go
Normal file
39
wtf/helpful_widget.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package wtf
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
type HelpfulWidget struct {
|
||||
app *tview.Application
|
||||
helpText string
|
||||
pages *tview.Pages
|
||||
view *tview.TextView
|
||||
}
|
||||
|
||||
func NewHelpfulWidget(app *tview.Application, pages *tview.Pages, helpText string) HelpfulWidget {
|
||||
widget := HelpfulWidget{
|
||||
app: app,
|
||||
helpText: helpText,
|
||||
pages: pages,
|
||||
}
|
||||
|
||||
return widget
|
||||
}
|
||||
|
||||
func (widget *HelpfulWidget) SetView(view *tview.TextView) {
|
||||
widget.view = view
|
||||
}
|
||||
|
||||
func (widget *HelpfulWidget) ShowHelp() {
|
||||
closeFunc := func() {
|
||||
widget.pages.RemovePage("help")
|
||||
widget.app.SetFocus(widget.view)
|
||||
}
|
||||
|
||||
modal := NewBillboardModal(widget.helpText, closeFunc)
|
||||
|
||||
widget.pages.AddPage("help", modal, false, true)
|
||||
widget.app.SetFocus(modal)
|
||||
widget.app.Draw()
|
||||
}
|
||||
Reference in New Issue
Block a user