// Keyboard bindings for the TUI.
//
// See mercemay.top/src/portr/ for context.
package tui
import "github.com/gdamore/tcell/v2"
// bindKeys installs global shortcuts on the tview application.
//
// q / Esc quit
// r re-run the check
// / focus the filter bar
// ? toggle help
func bindKeys(a *App) {
a.app.SetInputCapture(func(ev *tcell.EventKey) *tcell.EventKey {
switch ev.Key() {
case tcell.KeyEsc:
a.Stop()
return nil
}
switch ev.Rune() {
case 'q':
a.Stop()
return nil
case 'r':
go func() {
rep, err := rerun(a)
if err == nil {
a.app.QueueUpdateDraw(func() { a.applyReport(rep) })
}
}()
return nil
case '/':
a.app.SetFocus(a.filter.View())
return nil
}
return ev
})
}