Skip to content

Commit

Permalink
Add navi panel
Browse files Browse the repository at this point in the history
  • Loading branch information
nakabonne committed May 6, 2020
1 parent 7110fbf commit 6fe1383
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Gui struct {
sourceFilesItem *item.SourceFiles
resultsItem *item.Results
infoItem *item.Info
naviItem *item.Navi

runner *golangcilint.Runner
editor *editor.Editor
Expand All @@ -41,6 +42,7 @@ func New(logger *logrus.Entry, runner *golangcilint.Runner, command *editor.Edit
sourceFilesItem: item.NewSourceFiles("."),
resultsItem: item.NewResults(),
infoItem: item.NewInfo(runner.GetVersion()), // TODO: Run GetVersion() concurrency
naviItem: item.NewNavi(),
runner: runner,
logger: logger,
editor: command,
Expand All @@ -60,15 +62,18 @@ func (g *Gui) Run() error {
// initGrid sets a grid based layout as a root primitive for the application.
func (g *Gui) initGrid() {
grid := tview.NewGrid().
SetRows(1, 0).
SetRows(1, 0, 1).
SetColumns(30, 40, 0, 0).
SetBorders(true).
AddItem(g.infoItem, 0, 0, 1, 2, 0, 0, false)

// Layout for screens wider than 100 cells.
grid.AddItem(g.lintersItem, 1, 0, 1, 1, 0, 100, true).
AddItem(g.sourceFilesItem, 1, 1, 1, 1, 0, 100, false).
AddItem(g.resultsItem, 0, 2, 2, 2, 0, 100, false)
AddItem(g.resultsItem, 0, 2, 2, 2, 0, 100, false).
AddItem(g.naviItem, 2, 0, 1, 4, 0, 0, false)

g.naviItem.Update(g.lintersItem)

g.pages = tview.NewPages().
AddAndSwitchToPage(mainPageName, grid, true)
Expand Down Expand Up @@ -101,6 +106,7 @@ func (g *Gui) prevPanel() {
// switchPanel switches to focus on the given Primitive.
func (g *Gui) switchPanel(p tview.Primitive) {
g.application.SetFocus(p)
g.naviItem.Update(p)
}

func (g *Gui) switchPage(prev, next string) {
Expand Down
30 changes: 30 additions & 0 deletions pkg/gui/item/navi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package item

import "github.com/rivo/tview"

type Navi struct {
*tview.TextView
}

func NewNavi() *Navi {
n := &Navi{
TextView: tview.NewTextView().SetTextAlign(tview.AlignLeft).SetDynamicColors(true),
}
n.SetTitleAlign(tview.AlignLeft)
return n
}

const (
globalNavi = "[yellow::b]r[white]: run, [yellow::b]j[white]: move down, [yellow]k[white]: move up, [yellow]q[white]: quit"
)

func (n *Navi) Update(p tview.Primitive) {
switch p.(type) {
case *Linters:
n.SetText(globalNavi)
case *SourceFiles:
n.SetText("")
case *Results:
}

}

0 comments on commit 6fe1383

Please sign in to comment.