From f8b484f638e813537b9b968cf65d378b900fbcee Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Wed, 12 Sep 2018 18:23:25 +1000 Subject: [PATCH] don't use newlines at the end of panel buffers --- pkg/gui/branches_panel.go | 4 +++- pkg/gui/commits_panel.go | 31 +++++++++++++++++++------------ pkg/gui/files_panel.go | 16 ++++++++-------- pkg/gui/stash_panel.go | 12 +++++++++--- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 26c3c5618..d164003e5 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -152,9 +152,11 @@ func (gui *Gui) refreshBranches(g *gocui.Gui) error { } gui.State.Branches = builder.Build() v.Clear() + displayStrings := []string{} for _, branch := range gui.State.Branches { - fmt.Fprintln(v, branch.GetDisplayString()) + displayStrings = append(displayStrings, branch.GetDisplayString()) } + fmt.Fprint(v, strings.Join(displayStrings, "\n")) gui.resetOrigin(v) return gui.refreshStatus(g) }) diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 1c1662475..dd33369a5 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -2,12 +2,27 @@ package gui import ( "errors" + "fmt" + "strings" "github.com/fatih/color" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands" ) +func (gui *Gui) renderCommit(commit commands.Commit) string { + red := color.New(color.FgRed) + yellow := color.New(color.FgYellow) + white := color.New(color.FgWhite) + + shaColor := yellow + if commit.Pushed { + shaColor = red + } + + return shaColor.Sprint(commit.Sha) + " " + white.Sprint(commit.Name) +} + func (gui *Gui) refreshCommits(g *gocui.Gui) error { g.Update(func(*gocui.Gui) error { gui.State.Commits = gui.GitCommand.GetCommits() @@ -16,19 +31,11 @@ func (gui *Gui) refreshCommits(g *gocui.Gui) error { panic(err) } v.Clear() - red := color.New(color.FgRed) - yellow := color.New(color.FgYellow) - white := color.New(color.FgWhite) - shaColor := white - for _, commit := range gui.State.Commits { - if commit.Pushed { - shaColor = red - } else { - shaColor = yellow - } - shaColor.Fprint(v, commit.Sha+" ") - white.Fprintln(v, commit.Name) + displayStrings := make([]string, len(gui.State.Commits)) + for i, commit := range gui.State.Commits { + displayStrings[i] = gui.renderCommit(commit) } + fmt.Fprint(v, strings.Join(displayStrings, "\n")) gui.refreshStatus(g) if g.CurrentView().Name() == "commits" { gui.handleCommitSelect(g, v) diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 8fd2fb30c..6ad2aed5b 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -7,6 +7,7 @@ import ( // "strings" + "fmt" "strings" "github.com/fatih/color" @@ -319,16 +320,15 @@ func (gui *Gui) refreshFiles(g *gocui.Gui) error { return err } gui.refreshStateFiles() - filesView.Clear() + + displayStrings := make([]string, len(gui.State.Files)) for i, file := range gui.State.Files { - str := gui.renderFile(file) - if i < len(gui.State.Files)-1 { - str += "\n" - } - if _, err := filesView.Write([]byte(str)); err != nil { - return err - } + displayStrings[i] = gui.renderFile(file) } + + filesView.Clear() + fmt.Fprint(filesView, strings.Join(displayStrings, "\n")) + gui.correctCursor(filesView) if filesView == g.CurrentView() { gui.handleFileSelect(g, filesView) diff --git a/pkg/gui/stash_panel.go b/pkg/gui/stash_panel.go index 9ca07717b..3a9fac8d4 100644 --- a/pkg/gui/stash_panel.go +++ b/pkg/gui/stash_panel.go @@ -2,6 +2,7 @@ package gui import ( "fmt" + "strings" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands" @@ -14,10 +15,15 @@ func (gui *Gui) refreshStashEntries(g *gocui.Gui) error { panic(err) } gui.State.StashEntries = gui.GitCommand.GetStashEntries() - v.Clear() - for _, stashEntry := range gui.State.StashEntries { - fmt.Fprintln(v, stashEntry.DisplayString) + + displayStrings := make([]string, len(gui.State.StashEntries)) + for i, stashEntry := range gui.State.StashEntries { + displayStrings[i] = stashEntry.DisplayString } + + v.Clear() + fmt.Fprint(v, strings.Join(displayStrings, "\n")) + return gui.resetOrigin(v) }) return nil