Skip to content

Commit

Permalink
Add debug and overlay view. Close #17
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienBreux committed Aug 14, 2017
1 parent fef6f8e commit 0c4e336
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
18 changes: 18 additions & 0 deletions actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@ package main

import "github.com/jroimartin/gocui"

var DEBUG_DISPLAYED bool = false

// Global action: Quit
func actionGlobalQuit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}

// Global action: Toggle debug
func actionGlobalToggleDebug(g *gocui.Gui, v *gocui.View) error {
if !DEBUG_DISPLAYED {
debug(g, "Action: Toggle debug display (show)")
g.SetViewOnTop("debug")
} else {
debug(g, "Action: Toggle debug display (hide)")
g.SetViewOnBottom("debug")
// TODO g.SetCurrentView("pods")
}

DEBUG_DISPLAYED = !DEBUG_DISPLAYED

return nil
}
1 change: 1 addition & 0 deletions keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Key struct {
// Configure globale keys
var globalKeys []Key = []Key{
Key{"", gocui.KeyCtrlC, actionGlobalQuit},
Key{"", gocui.KeyCtrlD, actionGlobalToggleDebug},
}

// Define UI key bindings
Expand Down
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package main

import (
"fmt"
"log"
"time"

"github.com/jroimartin/gocui"
)
Expand Down Expand Up @@ -30,7 +32,19 @@ func main() {
func uiLayout(g *gocui.Gui) error {
maxX, maxY := g.Size()

viewDebug(g, maxX, maxY)
viewOverlay(g, maxX, maxY)
viewTitle(g, maxX, maxY)

return nil
}

func debug(g *gocui.Gui, output interface{}) {
v, err := g.View("debug")
if err == nil {
t := time.Now()
tf := t.Format("2006-01-02 15:04:05")
output = tf + " > " + output.(string)
fmt.Fprintln(v, output)
}
}
38 changes: 37 additions & 1 deletion views.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@ import (
"github.com/jroimartin/gocui"
)

// Define the title bar view
// View: Overlay
func viewOverlay(g *gocui.Gui, lMaxX int, lMaxY int) error {
if v, err := g.SetView("overlay", 0, 0, lMaxX, lMaxY); err != nil {
if err != gocui.ErrUnknownView {
return err
}

// Settings
v.Frame = false
}

return nil
}

// View: Title bar
func viewTitle(g *gocui.Gui, lMaxX int, lMaxY int) error {
if v, err := g.SetView("title", -1, -1, lMaxX, 1); err != nil {
if err != gocui.ErrUnknownView {
Expand All @@ -24,3 +38,25 @@ func viewTitle(g *gocui.Gui, lMaxX int, lMaxY int) error {

return nil
}

// View: Debug
func viewDebug(g *gocui.Gui, lMaxX int, lMaxY int) error {
// Main view
minX := 2
maxX := lMaxX - 4
minY := 2
maxY := lMaxY - 2
if v, err := g.SetView("debug", minX, minY, maxX, maxY); err != nil {
if err != gocui.ErrUnknownView {
return err
}

// Configure view
v.Title = " Debug "
v.Autoscroll = true
g.SetViewOnTop(v.Name())
g.SetCurrentView(v.Name())
}

return nil
}

0 comments on commit 0c4e336

Please sign in to comment.