From 9537645d0cfdac87addd4c9a5eb0e7df3bac8ee8 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Thu, 9 Aug 2018 19:49:36 +1000 Subject: [PATCH] dynamic width for confirmation panel and better handling of a squashed terminal --- confirmation_panel.go | 2 +- gui.go | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/confirmation_panel.go b/confirmation_panel.go index 2508748f6..20d0ff821 100644 --- a/confirmation_panel.go +++ b/confirmation_panel.go @@ -47,7 +47,7 @@ func getMessageHeight(message string, width int) int { func getConfirmationPanelDimensions(g *gocui.Gui, prompt string) (int, int, int, int) { width, height := g.Size() - panelWidth := 60 + panelWidth := width / 2 panelHeight := getMessageHeight(prompt, panelWidth) return width/2 - panelWidth/2, height/2 - panelHeight/2 - panelHeight%2 - 1, diff --git a/gui.go b/gui.go index c12c233e8..4765423f1 100644 --- a/gui.go +++ b/gui.go @@ -98,6 +98,14 @@ func handleRefresh(g *gocui.Gui, v *gocui.View) error { return refreshSidePanels(g) } +func max(a, b int) int { + if a > b { + return a + } + return b +} + +// layout is called for every screen re-render e.g. when the screen is resized func layout(g *gocui.Gui) error { g.Highlight = true g.SelFgColor = gocui.ColorWhite | gocui.AttrBold @@ -108,14 +116,15 @@ func layout(g *gocui.Gui) error { commitsBranchesBoundary := 3 * height / 5 // height - 10 commitsStashBoundary := height - 5 // height - 5 minimumHeight := 16 + minimumWidth := 10 panelSpacing := 1 if OverlappingEdges { panelSpacing = 0 } - if height < minimumHeight { - v, err := g.SetView("limit", 0, 0, width-1, height-1, 0) + if height < minimumHeight || width < minimumWidth { + v, err := g.SetView("limit", 0, 0, max(width-1, 2), max(height-1, 2), 0) if err != nil { if err != gocui.ErrUnknownView { return err @@ -195,6 +204,14 @@ func layout(g *gocui.Gui) error { v.Frame = false } + // If the confirmation panel is already displayed, just resize the width, + // otherwise continue + if v, err := g.View("confirmation"); err == nil { + _, y := v.Size() + x0, y0, x1, _ := getConfirmationPanelDimensions(g, "") + g.SetView("confirmation", x0, y0, x1, y0+y+1, 0) + } + if v, err := g.SetView("version", width-len(version)-1, optionsTop, width, optionsTop+2, 0); err != nil { if err != gocui.ErrUnknownView { return err