Skip to content

Commit

Permalink
Make it possible to switch panels
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed May 3, 2020
1 parent 3cdfce4 commit 68ad1dc
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
23 changes: 23 additions & 0 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ func (g *Gui) initGrid() {
g.application.SetRoot(g.pages, true)
}

// TODO: Be more clear the relationship between each panel.
func (g *Gui) nextPanel() {
switch g.application.GetFocus().(type) {
case *item.Linters:
g.switchPanel(g.sourceFilesItem)
case *item.SourceFiles:
g.switchPanel(g.resultsItem)
case *item.Results:
g.switchPanel(g.lintersItem)
}
}

func (g *Gui) prevPanel() {
switch g.application.GetFocus().(type) {
case *item.Linters:
g.switchPanel(g.resultsItem)
case *item.SourceFiles:
g.switchPanel(g.lintersItem)
case *item.Results:
g.switchPanel(g.sourceFilesItem)
}
}

// registerPath adds path to golangci-lint runner as an arg.
func (g *Gui) registerPath(node *tview.TreeNode, path string) {
g.runner.AddArgs(path)
Expand Down
12 changes: 11 additions & 1 deletion pkg/gui/item/linters.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package item

import "github.com/rivo/tview"
import (
"github.com/gdamore/tcell"
"github.com/rivo/tview"
)

type Linters struct {
*tview.Table
Expand All @@ -17,3 +20,10 @@ func NewLinters() *Linters {

return l
}

func (s *Linters) SetKeybinds(globalKeybind func(event *tcell.EventKey)) {
s.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
globalKeybind(event)
return event
})
}
8 changes: 8 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ import (
)

func (g *Gui) setKeybind() {
g.lintersItem.SetKeybinds(g.grobalKeybind)
g.sourceFilesItem.SetKeybinds(g.grobalKeybind, g.registerPath, g.unregisterPath)
g.resultsItem.SetKeybinds(g.grobalKeybind, g.openFile)
}

func (g *Gui) grobalKeybind(event *tcell.EventKey) {
switch event.Key() {
case tcell.KeyTab:
g.nextPanel()
case tcell.KeyBacktab:
g.prevPanel()
}

switch event.Rune() {
case 'q':
g.application.Stop()
Expand Down

0 comments on commit 68ad1dc

Please sign in to comment.