1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-15 22:26:40 +02:00

Changed the way how the view height are set

This commit is contained in:
mjarkk 2019-05-05 15:57:35 +02:00
parent e6122122e9
commit 19a6368377

View File

@ -141,7 +141,6 @@ type guiState struct {
DiffEntries []*commands.Commit DiffEntries []*commands.Commit
MenuItemCount int // can't store the actual list because it's of interface{} type MenuItemCount int // can't store the actual list because it's of interface{} type
PreviousView string PreviousView string
SmallUI bool
Platform commands.Platform Platform commands.Platform
Updating bool Updating bool
Panels *panelStates Panels *panelStates
@ -294,9 +293,6 @@ func (gui *Gui) layout(g *gocui.Gui) error {
g.Highlight = true g.Highlight = true
width, height := g.Size() width, height := g.Size()
smallUI := height < 28
gui.State.SmallUI = smallUI
information := gui.Config.GetVersion() information := gui.Config.GetVersion()
if gui.g.Mouse { if gui.g.Mouse {
donate := color.New(color.FgMagenta, color.Underline).Sprint(gui.Tr.SLocalize("Donate")) donate := color.New(color.FgMagenta, color.Underline).Sprint(gui.Tr.SLocalize("Donate"))
@ -318,13 +314,6 @@ func (gui *Gui) layout(g *gocui.Gui) error {
return nil return nil
} }
var statusFilesBoundary int
var filesBranchesBoundary int
var commitsBranchesBoundary int
var commitsStashBoundary int
optionsTop := height - 2
if smallUI {
currView := gui.g.CurrentView() currView := gui.g.CurrentView()
currentCyclebleView := "files" currentCyclebleView := "files"
if currView == nil { if currView == nil {
@ -344,50 +333,34 @@ func (gui *Gui) layout(g *gocui.Gui) error {
} }
} }
usableSpace := height - 7
extraSpace := usableSpace - (usableSpace/3)*3
vHeights := map[string]int{
"status": 3,
"files": (usableSpace / 3) + extraSpace,
"branches": usableSpace / 3,
"commits": usableSpace / 3,
"stash": 3,
"options": 1,
}
if height < 28 {
defaultHeight := 3
extraHeight := 2
if height < 21 { if height < 21 {
statusFilesBoundary = optionsTop - 4 defaultHeight = 1
filesBranchesBoundary = optionsTop - 3 extraHeight = 0
commitsBranchesBoundary = optionsTop - 2
commitsStashBoundary = optionsTop - 1
switch currentCyclebleView {
case "stash":
commitsStashBoundary = 3
fallthrough
case "commits":
commitsBranchesBoundary = 2
fallthrough
case "branches":
filesBranchesBoundary = 1
fallthrough
case "files":
statusFilesBoundary = 0
} }
} else { vHeights = map[string]int{
statusFilesBoundary = optionsTop - 12 "status": defaultHeight,
filesBranchesBoundary = optionsTop - 9 "files": defaultHeight,
commitsBranchesBoundary = optionsTop - 6 "branches": defaultHeight,
commitsStashBoundary = optionsTop - 3 "commits": defaultHeight,
"stash": defaultHeight,
switch currentCyclebleView { "options": defaultHeight,
case "stash":
commitsStashBoundary = 11
fallthrough
case "commits":
commitsBranchesBoundary = 8
fallthrough
case "branches":
filesBranchesBoundary = 5
fallthrough
case "files":
statusFilesBoundary = 2
} }
} vHeights[currentCyclebleView] = height - (defaultHeight * 5) + extraHeight
} else {
statusFilesBoundary = 2
filesBranchesBoundary = 2 * height / 5
commitsBranchesBoundary = 3 * height / 5
commitsStashBoundary = optionsTop - 3
} }
optionsVersionBoundary := width - max(len(utils.Decolorise(information)), 1) optionsVersionBoundary := width - max(len(utils.Decolorise(information)), 1)
@ -407,7 +380,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
_, _ = g.SetViewOnBottom("limit") _, _ = g.SetViewOnBottom("limit")
g.DeleteView("limit") g.DeleteView("limit")
v, err := g.SetView("main", leftSideWidth+panelSpacing, 0, width-1, optionsTop, gocui.LEFT) v, err := g.SetView("main", leftSideWidth+panelSpacing, 0, width-1, height-2, gocui.LEFT)
if err != nil { if err != nil {
if err.Error() != "unknown view" { if err.Error() != "unknown view" {
return err return err
@ -417,7 +390,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
v.FgColor = gocui.ColorWhite v.FgColor = gocui.ColorWhite
} }
if v, err := g.SetView("status", 0, 0, leftSideWidth, statusFilesBoundary, gocui.BOTTOM|gocui.RIGHT); err != nil { if v, err := g.SetView("status", 0, 0, leftSideWidth, vHeights["status"]-1, gocui.BOTTOM|gocui.RIGHT); err != nil {
if err.Error() != "unknown view" { if err.Error() != "unknown view" {
return err return err
} }
@ -425,7 +398,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
v.FgColor = gocui.ColorWhite v.FgColor = gocui.ColorWhite
} }
filesView, err := g.SetView("files", 0, statusFilesBoundary+panelSpacing, leftSideWidth, filesBranchesBoundary, gocui.TOP|gocui.BOTTOM) filesView, err := g.SetViewBeneath("files", "status", vHeights["files"])
if err != nil { if err != nil {
if err.Error() != "unknown view" { if err.Error() != "unknown view" {
return err return err
@ -435,7 +408,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
v.FgColor = gocui.ColorWhite v.FgColor = gocui.ColorWhite
} }
branchesView, err := g.SetView("branches", 0, filesBranchesBoundary+panelSpacing, leftSideWidth, commitsBranchesBoundary, gocui.TOP|gocui.BOTTOM) branchesView, err := g.SetViewBeneath("branches", "files", vHeights["branches"])
if err != nil { if err != nil {
if err.Error() != "unknown view" { if err.Error() != "unknown view" {
return err return err
@ -444,7 +417,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
branchesView.FgColor = gocui.ColorWhite branchesView.FgColor = gocui.ColorWhite
} }
if v, err := g.SetView("commitFiles", 0, commitsBranchesBoundary+panelSpacing, leftSideWidth, commitsStashBoundary, gocui.TOP|gocui.BOTTOM); err != nil { if v, err := g.SetViewBeneath("commitFiles", "branches", vHeights["commits"]); err != nil {
if err.Error() != "unknown view" { if err.Error() != "unknown view" {
return err return err
} }
@ -452,7 +425,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
v.FgColor = gocui.ColorWhite v.FgColor = gocui.ColorWhite
} }
commitsView, err := g.SetView("commits", 0, commitsBranchesBoundary+panelSpacing, leftSideWidth, commitsStashBoundary, gocui.TOP|gocui.BOTTOM) commitsView, err := g.SetViewBeneath("commits", "branches", vHeights["commits"])
if err != nil { if err != nil {
if err.Error() != "unknown view" { if err.Error() != "unknown view" {
return err return err
@ -461,7 +434,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
commitsView.FgColor = gocui.ColorWhite commitsView.FgColor = gocui.ColorWhite
} }
stashView, err := g.SetView("stash", 0, commitsStashBoundary+panelSpacing, leftSideWidth, optionsTop, gocui.TOP|gocui.RIGHT) stashView, err := g.SetViewBeneath("stash", "commits", vHeights["stash"])
if err != nil { if err != nil {
if err.Error() != "unknown view" { if err.Error() != "unknown view" {
return err return err
@ -470,7 +443,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
stashView.FgColor = gocui.ColorWhite stashView.FgColor = gocui.ColorWhite
} }
if v, err := g.SetView("options", appStatusOptionsBoundary-1, optionsTop, optionsVersionBoundary-1, optionsTop+2, 0); err != nil { if v, err := g.SetView("options", appStatusOptionsBoundary-1, height-2, optionsVersionBoundary-1, height, 0); err != nil {
if err.Error() != "unknown view" { if err.Error() != "unknown view" {
return err return err
} }
@ -511,7 +484,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
} }
} }
if appStatusView, err := g.SetView("appStatus", -1, optionsTop, width, optionsTop+2, 0); err != nil { if appStatusView, err := g.SetView("appStatus", -1, height+2, width, height, 0); err != nil {
if err.Error() != "unknown view" { if err.Error() != "unknown view" {
return err return err
} }
@ -523,7 +496,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
} }
} }
if v, err := g.SetView("information", optionsVersionBoundary-1, optionsTop, width, optionsTop+2, 0); err != nil { if v, err := g.SetView("information", optionsVersionBoundary-1, height+2, width, height, 0); err != nil {
if err.Error() != "unknown view" { if err.Error() != "unknown view" {
return err return err
} }