From a4354ccdfb25cac9f4928823dae86336c7571664 Mon Sep 17 00:00:00 2001 From: Olivia Bahr Date: Fri, 19 Apr 2024 14:53:03 -0600 Subject: [PATCH 1/2] Add config option for length of commit hash displayed in commits view - Add config option `commitHashLength` to to pkg/config/user_config.go - Changed the hash display in pkg/gui/presentation/commits.go --- docs/Config.md | 1 + pkg/config/user_config.go | 3 +++ pkg/gui/presentation/commits.go | 14 ++++++++++++-- schema/config.json | 6 ++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/Config.md b/docs/Config.md index c6f5cbbf951..077637ae8a7 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -80,6 +80,7 @@ gui: showIcons: false # deprecated: use nerdFontsVersion instead nerdFontsVersion: "" # nerd fonts version to use ("2" or "3"); empty means don't show nerd font icons showFileIcons: true # for hiding file icons in the file views + commitHashLength: 8 # length of commit hash in commits view. 0 shows '*' if NF icons aren't enabled commandLogSize: 8 splitDiff: 'auto' # one of 'auto' | 'always' skipRewordInEditorWarning: false # for skipping the confirmation before launching the reword editor diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 29b46e903d0..c1562fcde11 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -123,6 +123,8 @@ type GuiConfig struct { NerdFontsVersion string `yaml:"nerdFontsVersion" jsonschema:"enum=2,enum=3,enum="` // If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty. ShowFileIcons bool `yaml:"showFileIcons"` + // Length of commit hash in commits view. 0 shows '*' if NF icons aren't on. + CommitHashLength int `yaml:"commitHashLength" jsonschema:"minimum=0"` // If true, show commit hashes alongside branch names in the branches view. ShowBranchCommitHash bool `yaml:"showBranchCommitHash"` // Height of the command log view @@ -675,6 +677,7 @@ func GetDefaultConfig() *UserConfig { ShowIcons: false, NerdFontsVersion: "", ShowFileIcons: true, + CommitHashLength: 8, ShowBranchCommitHash: false, CommandLogSize: 8, SplitDiff: "auto", diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index 827648dda79..e3867430fcf 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -312,9 +312,19 @@ func displayCommit( bisectInfo *git_commands.BisectInfo, isYouAreHereCommit bool, ) []string { - hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo) bisectString := getBisectStatusText(bisectStatus, bisectInfo) + hashString := "" + hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo) + hashLength := common.UserConfig.Gui.CommitHashLength + if hashLength >= len(commit.Hash) { + hashString = hashColor.Sprint(commit.Hash) + } else if hashLength > 0 { + hashString = hashColor.Sprint(commit.Hash[:hashLength]) + } else if !icons.IsIconEnabled() { // hashLength <= 0 + hashString = hashColor.Sprint("*") + } + actionString := "" if commit.Action != models.ActionNone { todoString := lo.Ternary(commit.Action == models.ActionConflict, "conflict", commit.Action.String()) @@ -373,7 +383,7 @@ func displayCommit( } else if icons.IsIconEnabled() { cols = append(cols, hashColor.Sprint(icons.IconForCommit(commit))) } - cols = append(cols, hashColor.Sprint(commit.ShortHash())) + cols = append(cols, hashString) cols = append(cols, bisectString) if fullDescription { cols = append(cols, style.FgBlue.Sprint( diff --git a/schema/config.json b/schema/config.json index 5d259cbd418..41a8859a4b6 100644 --- a/schema/config.json +++ b/schema/config.json @@ -309,6 +309,12 @@ "description": "If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.", "default": true }, + "commitHashLength": { + "type": "integer", + "minimum": 0, + "description": "Length of commit hash in commits view. 0 shows '*' if NF icons aren't on.", + "default": 8 + }, "showBranchCommitHash": { "type": "boolean", "description": "If true, show commit hashes alongside branch names in the branches view." From b63321a30293e8c9750f6f59390bfe0d1677ab8c Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 27 Apr 2024 11:09:38 +0200 Subject: [PATCH 2/2] Refactor `pkg/gui/presentation/commits.go` slightly to be consistent Change `func displayCommit()` so all the individual strings are built first, then the whole thing `cols` is put together. Before, most strings were built prior to constructing `cols`, but a few were built inside the `cols` construction. --- pkg/gui/presentation/commits.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index e3867430fcf..cff36bf308b 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -325,6 +325,20 @@ func displayCommit( hashString = hashColor.Sprint("*") } + divergenceString := "" + if commit.Divergence != models.DivergenceNone { + divergenceString = hashColor.Sprint(lo.Ternary(commit.Divergence == models.DivergenceLeft, "↑", "↓")) + } else if icons.IsIconEnabled() { + divergenceString = hashColor.Sprint(icons.IconForCommit(commit)) + } + + descriptionString := "" + if fullDescription { + descriptionString = style.FgBlue.Sprint( + utils.UnixToDateSmart(now, commit.UnixTimestamp, timeFormat, shortTimeFormat), + ) + } + actionString := "" if commit.Action != models.ActionNone { todoString := lo.Ternary(commit.Action == models.ActionConflict, "conflict", commit.Action.String()) @@ -378,20 +392,12 @@ func displayCommit( } cols := make([]string, 0, 7) - if commit.Divergence != models.DivergenceNone { - cols = append(cols, hashColor.Sprint(lo.Ternary(commit.Divergence == models.DivergenceLeft, "↑", "↓"))) - } else if icons.IsIconEnabled() { - cols = append(cols, hashColor.Sprint(icons.IconForCommit(commit))) - } - cols = append(cols, hashString) - cols = append(cols, bisectString) - if fullDescription { - cols = append(cols, style.FgBlue.Sprint( - utils.UnixToDateSmart(now, commit.UnixTimestamp, timeFormat, shortTimeFormat), - )) - } cols = append( cols, + divergenceString, + hashString, + bisectString, + descriptionString, actionString, authorFunc(commit.AuthorName), graphLine+mark+tagString+theme.DefaultTextColor.Sprint(name),