diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-25 20:11:07 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-25 21:21:07 +1100 |
commit | 9fd9fd6816925debe64aa21269cdba5ec74ed5e9 (patch) | |
tree | a9e9cdf7285f246d9eaf59b42309a70c5ba9a029 /pkg/gui | |
parent | b8717d750a6d60b8f76698756e4d9ca9977ae14d (diff) |
better commit lines in fullscreen mode
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/commits_panel.go | 6 | ||||
-rw-r--r-- | pkg/gui/gui.go | 8 | ||||
-rw-r--r-- | pkg/gui/presentation/commits.go | 126 | ||||
-rw-r--r-- | pkg/gui/view_helpers.go | 9 |
4 files changed, 146 insertions, 3 deletions
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index b84401e79..e42aabfd0 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -7,6 +7,7 @@ import ( "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands" + "github.com/jesseduffield/lazygit/pkg/gui/presentation" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -600,9 +601,8 @@ func (gui *Gui) renderBranchCommitsWithSelection() error { commitsView := gui.getCommitsView() gui.refreshSelectedLine(&gui.State.Panels.Commits.SelectedLine, len(gui.State.Commits)) - if err := gui.renderListPanel(commitsView, gui.State.Commits); err != nil { - return err - } + displayStrings := presentation.GetCommitListDisplayStrings(gui.State.Commits, gui.State.ScreenMode != SCREEN_NORMAL) + gui.renderDisplayStrings(commitsView, displayStrings) if gui.g.CurrentView() == commitsView && commitsView.Context == "branch-commits" { if err := gui.handleCommitSelect(gui.g, commitsView); err != nil { return err diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index f04032fb5..4cf435b8f 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -269,12 +269,20 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *comma func (gui *Gui) nextScreenMode(g *gocui.Gui, v *gocui.View) error { gui.State.ScreenMode = utils.NextIntInCycle([]int{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) + // commits render differently depending on whether we're in fullscreen more or not + if err := gui.renderBranchCommitsWithSelection(); err != nil { + return err + } return nil } func (gui *Gui) prevScreenMode(g *gocui.Gui, v *gocui.View) error { gui.State.ScreenMode = utils.PrevIntInCycle([]int{SCREEN_NORMAL, SCREEN_HALF, SCREEN_FULL}, gui.State.ScreenMode) + // commits render differently depending on whether we're in fullscreen more or not + if err := gui.renderBranchCommitsWithSelection(); err != nil { + return err + } return nil } diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go new file mode 100644 index 000000000..04dbb0780 --- /dev/null +++ b/pkg/gui/presentation/commits.go @@ -0,0 +1,126 @@ +package presentation + +import ( + "strings" + + "github.com/fatih/color" + "github.com/jesseduffield/lazygit/pkg/commands" + "github.com/jesseduffield/lazygit/pkg/theme" + "github.com/jesseduffield/lazygit/pkg/utils" +) + +func GetCommitListDisplayStrings(commits []*commands.Commit, fullDescription bool) [][]string { + lines := make([][]string, len(commits)) + + var displayFunc func(*commands.Commit) []string + if fullDescription { + displayFunc = getFullDescriptionDisplayStringsForCommit + } else { + displayFunc = getDisplayStringsForCommit + } + + for i := range commits { + lines[i] = displayFunc(commits[i]) + } + + return lines +} + +func getFullDescriptionDisplayStringsForCommit(c *commands.Commit) []string { + red := color.New(color.FgRed) + yellow := color.New(color.FgYellow) + green := color.New(color.FgGreen) + blue := color.New(color.FgBlue) + cyan := color.New(color.FgCyan) + defaultColor := color.New(theme.DefaultTextColor) + magenta := color.New(color.FgMagenta) + + // for some reason, setting the background to blue pads out the other commits + // horizontally. For the sake of accessibility I'm considering this a feature, + // not a bug + copied := color.New(color.FgCyan, color.BgBlue) + + var shaColor *color.Color + switch c.Status { + case "unpushed": + shaColor = red + case "pushed": + shaColor = yellow + case "merged": + shaColor = green + case "rebasing": + shaColor = blue + case "reflog": + shaColor = blue + case "selected": + shaColor = magenta + default: + shaColor = defaultColor + } + + if c.Copied { + shaColor = copied + } + + tagString := "" + truncatedDate := utils.TruncateWithEllipsis(c.Date, 15) + secondColumnString := blue.Sprint(truncatedDate) + if c.Action != "" { + secondColumnString = cyan.Sprint(c.Action) + } else if len(c.Tags) > 0 { + tagColor := color.New(color.FgMagenta, color.Bold) + tagString = utils.ColoredStringDirect(c.ExtraInfo, tagColor) + " " + } + + truncatedAuthor := utils.TruncateWithEllipsis(c.Author, 17) + + return []string{shaColor.Sprint(c.Sha[:8]), secondColumnString, yellow.Sprint(truncatedAuthor), tagString + defaultColor.Sprint(c.Name)} +} + +func getDisplayStringsForCommit(c *commands.Commit) []string { + red := color.New(color.FgRed) + yellow := color.New(color.FgYellow) + green := color.New(color.FgGreen) + blue := color.New(color.FgBlue) + cyan := color.New(color.FgCyan) + defaultColor := color.New(theme.DefaultTextColor) + magenta := color.New(color.FgMagenta) + + // for some reason, setting the background to blue pads out the other commits + // horizontally. For the sake of accessibility I'm considering this a feature, + // not a bug + copied := color.New(color.FgCyan, color.BgBlue) + + var shaColor *color.Color + switch c.Status { + case "unpushed": + shaColor = red + case "pushed": + shaColor = yellow + case "merged": + shaColor = green + case "rebasing": + shaColor = blue + case "reflog": + shaColor = blue + case "selected": + shaColor = magenta + default: + shaColor = defaultColor + } + + if c.Copied { + shaColor = copied + } + + actionString := "" + tagString := "" + if c.Action != "" { + actionString = cyan.Sprint(utils.WithPadding(c.Action, 7)) + " " + } else if len(c.Tags) > 0 { + tagColor := color.New(color.FgMagenta, color.Bold) + tagString = utils.ColoredStringDirect(strings.Join(c.Tags, " "), tagColor) + " " + } + + return []string{shaColor.Sprint(c.Sha[:8]), actionString + tagString + defaultColor.Sprint(c.Name)} +} diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 5452f1754..119014802 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -387,6 +387,15 @@ func (gui *Gui) refreshSelectedLine(line *int, total int) { } } +func (gui *Gui) renderDisplayStrings(v *gocui.View, displayStrings [][]string) { + gui.g.Update(func(g *gocui.Gui) error { + list := utils.RenderDisplayStrings(displayStrings) + v.Clear() + fmt.Fprint(v, list) + return nil + }) +} + func (gui *Gui) renderListPanel(v *gocui.View, items interface{}) error { gui.g.Update(func(g *gocui.Gui) error { isFocused := gui.g.CurrentView().Name() == v.Name() |