Skip to content

Commit

Permalink
feat(gui): improve the navigation including the rows panel
Browse files Browse the repository at this point in the history
  • Loading branch information
danvergara committed May 3, 2021
1 parent 2b64c3a commit 809292e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pkg/gui/database_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ func (gui *Gui) runQuery() func(g *gocui.Gui, v *gocui.View) error {

// Setup the table.
table := tablewriter.NewWriter(ov)
table.SetCenterSeparator("|")
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: true})
table.SetHeader(columnNames)
// Add Bulk Data.
table.AppendBulk(resultSet)
Expand Down
36 changes: 36 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,42 @@ func (gui *Gui) keybindings() error {
return err
}

if err := gui.g.SetKeybinding("tables", gocui.KeyCtrlK, gocui.ModNone, cursorUp); err != nil {
return err
}

if err := gui.g.SetKeybinding("tables", gocui.KeyArrowUp, gocui.ModNone, cursorUp); err != nil {
return err
}

if err := gui.g.SetKeybinding("tables", gocui.KeyCtrlJ, gocui.ModNone, cursorDown); err != nil {
return err
}

if err := gui.g.SetKeybinding("tables", gocui.KeyArrowDown, gocui.ModNone, cursorDown); err != nil {
return err
}

if err := gui.g.SetKeybinding("tables", gocui.KeyEnter, gocui.ModNone, gui.selectTable); err != nil {
return err
}

if err := gui.g.SetKeybinding("query", gocui.KeyCtrlJ, gocui.ModNone, setRowsView); err != nil {
return err
}

if err := gui.g.SetKeybinding("rows", gocui.KeyCtrlK, gocui.ModNone, setQueryViewFromRows); err != nil {
return err
}

if err := gui.g.SetKeybinding("rows", gocui.KeyArrowUp, gocui.ModNone, cursorUp); err != nil {
return err
}

if err := gui.g.SetKeybinding("rows", gocui.KeyArrowDown, gocui.ModNone, cursorDown); err != nil {
return err
}

if err := gui.g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
return err
}
Expand Down
29 changes: 29 additions & 0 deletions pkg/gui/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,35 @@ func setTablesView(g *gocui.Gui, v *gocui.View) error {
return err
}

func setRowsView(g *gocui.Gui, v *gocui.View) error {
if v == nil || v.Name() == "query" {
_, err := g.SetCurrentView("rows")

g.Highlight = true
g.Cursor = true
g.SelFgColor = gocui.ColorGreen

return err
}

_, err := g.SetCurrentView("query")
return err
}

func setQueryViewFromRows(g *gocui.Gui, v *gocui.View) error {
if v == nil || v.Name() == "rows" {
_, err := g.SetCurrentView("query")
return err
}

g.Highlight = true
g.Cursor = true
g.SelFgColor = gocui.ColorGreen

_, err := g.SetCurrentView("rows")
return err
}

// quit is called to end the gui app.
func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
Expand Down

0 comments on commit 809292e

Please sign in to comment.