From 71c4d860e35fd683c31106494cc1befcdb29ebe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 27 Jun 2019 01:36:07 -0400 Subject: [PATCH] add Enabled attribute for ViewController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- main.go | 21 ++++++++------------- view.go | 10 +++++++++- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index ba7d80e..5472092 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,10 @@ package main import ( - "github.com/jroimartin/gocui" "log" "os" + + "github.com/jroimartin/gocui" ) type rcpResp map[string]interface{} @@ -33,6 +34,7 @@ func main() { Name: "main", Title: "Peers", Placeholder: "Loading peers...", + Enabled: true, Cursor: true, Highlight: true, Current: true, @@ -40,12 +42,8 @@ func main() { SelBgColor: gocui.ColorGreen, State: peers, // corner positions - TopLeft: func(mx, my int) (int, int) { - return 0, 0 - }, - BotRight: func(mx, my int) (int, int) { - return mx - 1, my / 2 - }, + TopLeft: func(mx, my int) (int, int) { return 0, 0 }, + BotRight: func(mx, my int) (int, int) { return mx - 1, my / 2 }, } // bindings defined separately so handlers can reference mainView mainView.Keybindings = []Binding{ @@ -59,14 +57,11 @@ func main() { Name: "info", Title: "Details", Placeholder: "Loading details...", + Enabled: true, Wrap: true, // corner positions - TopLeft: func(mx, my int) (int, int) { - return 0, my/2 + 1 - }, - BotRight: func(mx, my int) (int, int) { - return mx - 1, my - 1 - }, + TopLeft: func(mx, my int) (int, int) { return 0, my/2 + 1 }, + BotRight: func(mx, my int) (int, int) { return mx - 1, my - 1 }, } views := []*ViewController{mainView, infoView} diff --git a/view.go b/view.go index 154bda5..a0f9ed2 100644 --- a/view.go +++ b/view.go @@ -10,10 +10,12 @@ type ViewController struct { Name string Title string Placeholder string + Enabled bool Wrap bool Cursor bool Current bool Highlight bool + OnTop bool TopLeft func(int, int) (int, int) BotRight func(int, int) (int, int) SelBgColor gocui.Attribute @@ -32,6 +34,9 @@ func (m *ViewManager) Layout(g *gocui.Gui) error { mx, my := g.Size() for _, cfg := range m.views { + if !cfg.Enabled { + continue + } x0, y0 := cfg.TopLeft(mx, my) x1, y1 := cfg.BotRight(mx, my) @@ -49,7 +54,10 @@ func (m *ViewManager) Layout(g *gocui.Gui) error { v.SetCursor(0, 0) } if cfg.Current { - g.SetCurrentView("main") + g.SetCurrentView(cfg.Name) + } + if cfg.OnTop { + g.SetViewOnTop(cfg.Name) } fmt.Fprintln(v, cfg.Placeholder) cfg.SetKeybindings(g)