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

View File

@@ -19,26 +19,24 @@ const HelpText = `
`
type Widget struct {
wtf.HelpfulWidget
wtf.TextWidget
app *tview.Application
pages *tview.Pages
GithubRepos []*GithubRepo
Idx int
}
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget("GitHub", "github", true),
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget("GitHub", "github", true),
app: app,
Idx: 0,
pages: pages,
Idx: 0,
}
widget.GithubRepos = widget.buildRepoCollection(wtf.Config.UMap("wtf.mods.github.repositories"))
widget.HelpfulWidget.SetView(widget.View)
widget.View.SetInputCapture(widget.keyboardIntercept)
return &widget
@@ -101,7 +99,7 @@ func (widget *Widget) currentGithubRepo() *GithubRepo {
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
switch string(event.Rune()) {
case "/":
widget.showHelp()
widget.ShowHelp()
return nil
case "h":
widget.Prev()
@@ -125,16 +123,3 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
return event
}
}
func (widget *Widget) showHelp() {
closeFunc := func() {
widget.pages.RemovePage("help")
widget.app.SetFocus(widget.View)
}
modal := wtf.NewBillboardModal(HelpText, closeFunc)
widget.pages.AddPage("help", modal, false, true)
widget.app.SetFocus(modal)
widget.app.Draw()
}