diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-01-15 19:33:42 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-01-17 10:29:52 +1100 |
commit | 695b092c4120d41c15ad969a6ea472e38379ebbd (patch) | |
tree | 658fcc1cfd2170ece17552306fe84a017cf5fb1c /pkg/gui/confirmation_panel.go | |
parent | a38d1a3b689b204f3920dcfc3949bbd7c5c61f44 (diff) |
Directly send wrap argument rather than the view
Diffstat (limited to 'pkg/gui/confirmation_panel.go')
-rw-r--r-- | pkg/gui/confirmation_panel.go | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index ef17ccf67..c3f33d429 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -37,11 +37,11 @@ func (gui *Gui) closeConfirmationPrompt(g *gocui.Gui) error { return g.DeleteView("confirmation") } -func (gui *Gui) getMessageHeight(v *gocui.View, message string, width int) int { +func (gui *Gui) getMessageHeight(wrap bool, message string, width int) int { lines := strings.Split(message, "\n") lineCount := 0 // if we need to wrap, calculate height to fit content within view's width - if v.Wrap { + if wrap { for _, line := range lines { lineCount += len(line)/width + 1 } @@ -51,14 +51,10 @@ func (gui *Gui) getMessageHeight(v *gocui.View, message string, width int) int { return lineCount } -func (gui *Gui) getConfirmationPanelDimensions(g *gocui.Gui, prompt string) (int, int, int, int) { +func (gui *Gui) getConfirmationPanelDimensions(g *gocui.Gui, wrap bool, prompt string) (int, int, int, int) { width, height := g.Size() panelWidth := width / 2 - view, err := gui.g.View("confirmation") - if err != nil { // confirmation panel was deleted so we just return empty values - return 0,0,0,0 - } - panelHeight := gui.getMessageHeight(view, prompt, panelWidth) + panelHeight := gui.getMessageHeight(wrap, prompt, panelWidth) return width/2 - panelWidth/2, height/2 - panelHeight/2 - panelHeight%2 - 1, width/2 + panelWidth/2, @@ -76,7 +72,7 @@ func (gui *Gui) createPromptPanel(g *gocui.Gui, currentView *gocui.View, title s } func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt string) (*gocui.View, error) { - x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, prompt) + x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, true, prompt) confirmationView, err := gui.g.SetView("confirmation", x0, y0, x1, y1, 0) if err != nil { if err != gocui.ErrUnknownView { |