-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gui): add a package called to gui to manage all related to the g…
…ui app
- Loading branch information
1 parent
fc2a916
commit d89aa0d
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package gui | ||
|
||
import ( | ||
"github.com/jroimartin/gocui" | ||
"github.com/olekukonko/tablewriter" | ||
) | ||
|
||
// Layout is called for every screen re-render e.g. when the screen is resized | ||
func Layout(g *gocui.Gui) error { | ||
maxX, maxY := g.Size() | ||
|
||
if v, err := g.SetView("tables", 0, 0, int(0.2*float32(maxX)), maxY-5); err != nil { | ||
if err != gocui.ErrUnknownView { | ||
return err | ||
} | ||
|
||
v.Title = "Tables" | ||
} | ||
|
||
if v, err := g.SetView("query", int(0.2*float32(maxX)), 0, maxX, maxY-40); err != nil { | ||
if err != gocui.ErrUnknownView { | ||
return err | ||
} | ||
|
||
v.Title = "SQL Query" | ||
|
||
v.Editable = true | ||
v.Wrap = true | ||
|
||
if _, err := g.SetCurrentView("query"); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
if v, err := g.SetView("rows", int(0.2*float32(maxX)), maxY-40, maxX, maxY-5); err != nil { | ||
if err != gocui.ErrUnknownView { | ||
return err | ||
} | ||
|
||
// init table | ||
table := tablewriter.NewWriter(v) | ||
table.SetCenterSeparator("|") | ||
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false}) | ||
table.Render() | ||
|
||
v.Title = "Rows" | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Quit is called to end the gui app | ||
func Quit(g *gocui.Gui, v *gocui.View) error { | ||
return gocui.ErrQuit | ||
} |