configure keybindings, placeholder, and cursor only once

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-06-27 08:46:51 -04:00 committed by Jakub
parent 15634abaf6
commit 08ec326ea4
1 changed files with 10 additions and 6 deletions

16
view.go
View File

@ -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
}