diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/confirmation_panel.go | 14 | ||||
-rw-r--r-- | pkg/gui/menu_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/view_helpers.go | 2 |
3 files changed, 7 insertions, 11 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 { diff --git a/pkg/gui/menu_panel.go b/pkg/gui/menu_panel.go index 8ce60f6be..5da80afa2 100644 --- a/pkg/gui/menu_panel.go +++ b/pkg/gui/menu_panel.go @@ -56,7 +56,7 @@ func (gui *Gui) createMenu(items interface{}, handlePress func(int) error) error return err } - x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, list) + x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(gui.g, false, list) menuView, _ := gui.g.SetView("menu", x0, y0, x1, y1, 0) menuView.Title = strings.Title(gui.Tr.SLocalize("menu")) menuView.FgColor = gocui.ColorWhite diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 75270e388..a88f6ce3d 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -317,7 +317,7 @@ func (gui *Gui) resizePopupPanel(g *gocui.Gui, v *gocui.View) error { // If the confirmation panel is already displayed, just resize the width, // otherwise continue content := v.Buffer() - x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(g, content) + x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(g, v.Wrap, content) vx0, vy0, vx1, vy1 := v.Dimensions() if vx0 == x0 && vy0 == y0 && vx1 == x1 && vy1 == y1 { return nil |