mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-427 Use new keyboard implementation for widgets. Closes #427
This commit is contained in:
13
modules/gitlab/keyboard.go
Normal file
13
modules/gitlab/keyboard.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package gitlab
|
||||
|
||||
import "github.com/gdamore/tcell"
|
||||
|
||||
func (widget *Widget) initializeKeyboardControls() {
|
||||
widget.SetKeyboardChar("/", widget.ShowHelp)
|
||||
widget.SetKeyboardChar("h", widget.Prev)
|
||||
widget.SetKeyboardChar("l", widget.Next)
|
||||
widget.SetKeyboardChar("r", widget.Refresh)
|
||||
|
||||
widget.SetKeyboardKey(tcell.KeyLeft, widget.Prev)
|
||||
widget.SetKeyboardKey(tcell.KeyRight, widget.Next)
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package gitlab
|
||||
|
||||
import (
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/wtf"
|
||||
glb "github.com/xanzy/go-gitlab"
|
||||
@@ -21,6 +20,7 @@ const HelpText = `
|
||||
|
||||
type Widget struct {
|
||||
wtf.HelpfulWidget
|
||||
wtf.KeyboardWidget
|
||||
wtf.TextWidget
|
||||
|
||||
GitlabProjects []*GitlabProject
|
||||
@@ -40,8 +40,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
}
|
||||
|
||||
widget := Widget{
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||
KeyboardWidget: wtf.NewKeyboardWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, settings.common, true),
|
||||
|
||||
Idx: 0,
|
||||
|
||||
@@ -52,8 +53,10 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
||||
|
||||
widget.GitlabProjects = widget.buildProjectCollection(settings.projects)
|
||||
|
||||
widget.initializeKeyboardControls()
|
||||
widget.View.SetInputCapture(widget.InputCapture)
|
||||
|
||||
widget.HelpfulWidget.SetView(widget.View)
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@@ -112,31 +115,3 @@ func (widget *Widget) currentGitlabProject() *GitlabProject {
|
||||
|
||||
return widget.GitlabProjects[widget.Idx]
|
||||
}
|
||||
|
||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch string(event.Rune()) {
|
||||
case "/":
|
||||
widget.ShowHelp()
|
||||
return nil
|
||||
case "h":
|
||||
widget.Prev()
|
||||
return nil
|
||||
case "l":
|
||||
widget.Next()
|
||||
return nil
|
||||
case "r":
|
||||
widget.Refresh()
|
||||
return nil
|
||||
}
|
||||
|
||||
switch event.Key() {
|
||||
case tcell.KeyLeft:
|
||||
widget.Prev()
|
||||
return nil
|
||||
case tcell.KeyRight:
|
||||
widget.Next()
|
||||
return nil
|
||||
default:
|
||||
return event
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user