dynamic width for confirmation panel and better handling of a squashed terminal

This commit is contained in:
Jesse Duffield
2018-08-09 19:49:36 +10:00
parent d08e3a55a1
commit 9537645d0c
2 changed files with 20 additions and 3 deletions

View File

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

21
gui.go
View File

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