1
0
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:
Chris Cummer
2018-08-01 15:54:29 -07:00
parent 00abe70309
commit 9154441c32
10 changed files with 90 additions and 173 deletions

39
wtf/helpful_widget.go Normal file
View 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()
}