Skip to content

Commit

Permalink
feat(gui): add a view called structure in the exact position of the r…
Browse files Browse the repository at this point in the history
…ows view, but hidden at the beggining

46
  • Loading branch information
danvergara committed Jun 10, 2021
1 parent 5ea7f64 commit 5a032a4
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions pkg/gui/layout.go
Expand Up @@ -47,6 +47,16 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
}

if v, err := gui.g.SetView("structure", int(0.2*float32(maxX)), int(0.25*float32(maxY)), maxX-1, int(0.95*float32(maxY))); err != nil {
if err != gocui.ErrUnknownView {
return err
}

v.Title = "Structure"

fmt.Fprintln(v, "Please select a table!")
}

if v, err := gui.g.SetView("rows", int(0.2*float32(maxX)), int(0.25*float32(maxY)), maxX-1, int(0.95*float32(maxY))); err != nil {
if err != gocui.ErrUnknownView {
return err
Expand All @@ -60,6 +70,29 @@ func (gui *Gui) layout(g *gocui.Gui) error {
return nil
}

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

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

return err
}

_, err := g.SetCurrentView("view")

return err
}

func nextView(from, to string) func(g *gocui.Gui, v *gocui.View) error {
return func(g *gocui.Gui, v *gocui.View) error {
if v == nil || v.Name() == from {
Expand All @@ -78,6 +111,34 @@ func nextView(from, to string) func(g *gocui.Gui, v *gocui.View) error {
}
}

func setViewOnTop(g *gocui.Gui, v *gocui.View) error {
if v == nil || v.Name() == "rows" {
return switchView(g, "structure")
}

if v == nil || v.Name() == "structure" {
return switchView(g, "rows")
}

return nil
}

func switchView(g *gocui.Gui, v string) error {
if _, err := g.SetViewOnTop(v); err != nil {
return err
}

if _, err := g.SetCurrentView(v); err != nil {
return err
}

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

return nil
}

func cursorUp(g *gocui.Gui, v *gocui.View) error {
if v != nil {
ox, oy := v.Origin()
Expand Down

0 comments on commit 5a032a4

Please sign in to comment.