1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-26 09:00:57 +02:00

don't use newlines at the end of panel buffers

This commit is contained in:
Jesse Duffield 2018-09-12 18:23:25 +10:00
parent 52b132fe01
commit f8b484f638
4 changed files with 39 additions and 24 deletions

View File

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

View File

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

View File

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

View File

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