From 08ec326ea42c7f43efa2d93ea4bf4a55afa6bde2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 27 Jun 2019 08:46:51 -0400 Subject: [PATCH] configure keybindings, placeholder, and cursor only once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- view.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/view.go b/view.go index 4c0fc67..6fc717a 100644 --- a/view.go +++ b/view.go @@ -42,7 +42,16 @@ func (m *ViewManager) Layout(g *gocui.Gui) error { x1, y1 := cfg.BotRight(mx, my) v, err := g.SetView(cfg.Name, x0, y0, x1, y1) - if err != nil && err != gocui.ErrUnknownView { + // Some settings can be set only once + if err == gocui.ErrUnknownView { + cfg.SetKeybindings(g) + if cfg.Cursor { + v.SetCursor(0, 0) + } + if cfg.Placeholder != "" { + fmt.Fprintln(v, cfg.Placeholder) + } + } else if err != nil { log.Panicln(err) } v.Title = cfg.Title @@ -51,17 +60,12 @@ func (m *ViewManager) Layout(g *gocui.Gui) error { v.SelBgColor = cfg.SelBgColor v.Highlight = cfg.Highlight - if cfg.Cursor { - v.SetCursor(0, 0) - } if cfg.Current { g.SetCurrentView(cfg.Name) } if cfg.OnTop { g.SetViewOnTop(cfg.Name) } - fmt.Fprintln(v, cfg.Placeholder) - cfg.SetKeybindings(g) } return nil }