From 98fbc6122150986ebd72bbf18a5a9b262ad932ce Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 21 Mar 2020 12:18:26 +1100 Subject: [PATCH] better formatted reflog list --- pkg/gui/presentation/reflog_commits.go | 37 ++++++++++++++++++++++++++ pkg/gui/reflog_panel.go | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 pkg/gui/presentation/reflog_commits.go diff --git a/pkg/gui/presentation/reflog_commits.go b/pkg/gui/presentation/reflog_commits.go new file mode 100644 index 000000000..9ec325fb3 --- /dev/null +++ b/pkg/gui/presentation/reflog_commits.go @@ -0,0 +1,37 @@ +package presentation + +import ( + "github.com/fatih/color" + "github.com/jesseduffield/lazygit/pkg/commands" + "github.com/jesseduffield/lazygit/pkg/theme" + "github.com/jesseduffield/lazygit/pkg/utils" +) + +func GetReflogCommitListDisplayStrings(commits []*commands.Commit, fullDescription bool) [][]string { + lines := make([][]string, len(commits)) + + var displayFunc func(*commands.Commit) []string + if fullDescription { + displayFunc = getFullDescriptionDisplayStringsForReflogCommit + } else { + displayFunc = getDisplayStringsForReflogCommit + } + + for i := range commits { + lines[i] = displayFunc(commits[i]) + } + + return lines +} + +func getFullDescriptionDisplayStringsForReflogCommit(c *commands.Commit) []string { + defaultColor := color.New(theme.DefaultTextColor) + + return []string{utils.ColoredString(c.Sha[:8], color.FgBlue), utils.ColoredString(c.Date, color.FgMagenta), defaultColor.Sprint(c.Name)} +} + +func getDisplayStringsForReflogCommit(c *commands.Commit) []string { + defaultColor := color.New(theme.DefaultTextColor) + + return []string{utils.ColoredString(c.Sha[:8], color.FgBlue), defaultColor.Sprint(c.Name)} +} diff --git a/pkg/gui/reflog_panel.go b/pkg/gui/reflog_panel.go index fb1aa3978..4bdfddb54 100644 --- a/pkg/gui/reflog_panel.go +++ b/pkg/gui/reflog_panel.go @@ -67,7 +67,7 @@ func (gui *Gui) renderReflogCommitsWithSelection() error { commitsView := gui.getCommitsView() gui.refreshSelectedLine(&gui.State.Panels.ReflogCommits.SelectedLine, len(gui.State.ReflogCommits)) - displayStrings := presentation.GetCommitListDisplayStrings(gui.State.ReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL) + displayStrings := presentation.GetReflogCommitListDisplayStrings(gui.State.ReflogCommits, gui.State.ScreenMode != SCREEN_NORMAL) gui.renderDisplayStrings(commitsView, displayStrings) if gui.g.CurrentView() == commitsView && commitsView.Context == "reflog-commits" { if err := gui.handleReflogCommitSelect(gui.g, commitsView); err != nil {