1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Can dismiss help modal from the keyboard

This commit is contained in:
Chris Cummer 2018-05-03 16:08:52 -07:00
parent 8d0a0b81fa
commit 72f9543e75
2 changed files with 28 additions and 3 deletions

View File

@ -218,7 +218,13 @@ func (widget *Widget) persist() {
} }
func (widget *Widget) showHelp() { func (widget *Widget) showHelp() {
modal := wtf.NewBillboardModal(helpText) closeFunc := func() {
widget.pages.RemovePage("help")
widget.app.SetFocus(widget.View)
widget.display()
}
modal := wtf.NewBillboardModal(helpText, closeFunc)
widget.pages.AddPage("help", modal, false, true) widget.pages.AddPage("help", modal, false, true)
widget.app.SetFocus(modal) widget.app.SetFocus(modal)

View File

@ -9,15 +9,34 @@ const offscreen = -1000
const modalWidth = 80 const modalWidth = 80
const modalHeight = 22 const modalHeight = 22
func NewBillboardModal(text string) *tview.Frame { func NewBillboardModal(text string, closeFunc func()) *tview.Frame {
keyboardIntercept := func(event *tcell.EventKey) *tcell.EventKey {
switch string(event.Rune()) {
case "h":
closeFunc()
return nil
}
switch event.Key() {
case tcell.KeyEsc:
closeFunc()
return nil
case tcell.KeyTab:
return nil
default:
return event
}
}
textView := tview.NewTextView() textView := tview.NewTextView()
textView.SetWrap(true) textView.SetWrap(true)
textView.SetText(text) textView.SetText(text)
textView.SetBackgroundColor(tview.Styles.ContrastBackgroundColor) textView.SetBackgroundColor(tview.Styles.ContrastBackgroundColor)
textView.SetInputCapture(keyboardIntercept)
thing := tview.NewFrame(textView) thing := tview.NewFrame(textView)
thing.SetRect(offscreen, offscreen, modalWidth, modalHeight) // First draw it offscreen and then reposition below thing.SetRect(offscreen, offscreen, modalWidth, modalHeight)
drawFunc := func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) { drawFunc := func(screen tcell.Screen, x, y, width, height int) (int, int, int, int) {
w, h := screen.Size() w, h := screen.Size()