Skip to content

Commit

Permalink
Add config options for length of commit hash displayed in commits view
Browse files Browse the repository at this point in the history
- Add config option `commitHashLength` to to pkg/config/user_config.go
- Add config option `commitStatusChar` to display a char if there is nothing else to show the status color.
- Changed the hash display in pkg/gui/presentation/commits.go

- 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.
  • Loading branch information
oliviaBahr committed Apr 24, 2024
1 parent b2ff09e commit acfd6b5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
2 changes: 2 additions & 0 deletions docs/Config.md
Expand Up @@ -80,6 +80,8 @@ 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
commitStatusChar: "" # What to show instead of hash if commitHashLength==0 and NF icons aren't on. Empty string to show nothing.
commandLogSize: 8
splitDiff: 'auto' # one of 'auto' | 'always'
skipRewordInEditorWarning: false # for skipping the confirmation before launching the reword editor
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/user_config.go
Expand Up @@ -123,6 +123,12 @@ 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.
// If 0 and NF icons aren't enabled, show 'commitStatusChar' instead of hash.
CommitHashLength int `yaml:"commitHashLength" jsonschema:"minimum=0"`
// What to show instead of hash if commitHashLength==0 and NF icons aren't on
// Empty string to show nothing
CommitStatusChar string `yaml:"commitStatusChar"`
// If true, show commit hashes alongside branch names in the branches view.
ShowBranchCommitHash bool `yaml:"showBranchCommitHash"`
// Height of the command log view
Expand Down Expand Up @@ -675,6 +681,8 @@ func GetDefaultConfig() *UserConfig {
ShowIcons: false,
NerdFontsVersion: "",
ShowFileIcons: true,
CommitHashLength: 8,
CommitStatusChar: "●",
ShowBranchCommitHash: false,
CommandLogSize: 8,
SplitDiff: "auto",
Expand Down
41 changes: 28 additions & 13 deletions pkg/gui/presentation/commits.go
Expand Up @@ -312,9 +312,32 @@ func displayCommit(
bisectInfo *git_commands.BisectInfo,
isYouAreHereCommit bool,
) []string {
hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo)
bisectString := getBisectStatusText(bisectStatus, bisectInfo)

hashString := commit.Hash
hashColor := getHashColor(commit, diffName, cherryPickedCommitHashSet, bisectStatus, bisectInfo)
hashLength := common.UserConfig.Gui.CommitHashLength
if hashLength == 0 && !icons.IsIconEnabled() { // if no icons and no hash, show a char so user still sees status color
hashString = common.UserConfig.Gui.CommitStatusChar
} else if hashLength < len(hashString) {
hashString = hashString[:hashLength]
}
hashString = hashColor.Sprint(hashString)

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())
Expand Down Expand Up @@ -368,20 +391,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, hashColor.Sprint(commit.ShortHash()))
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),
Expand Down
11 changes: 11 additions & 0 deletions schema/config.json
Expand Up @@ -309,6 +309,17 @@
"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.\nIf 0 and NF icons aren't enabled, show 'commitStatusChar' instead of hash.",
"default": 8
},
"commitStatusChar": {
"type": "string",
"description": "What to show instead of hash if commitHashLength==0 and NF icons aren't on\nEmpty string to show nothing",
"default": ""
},
"showBranchCommitHash": {
"type": "boolean",
"description": "If true, show commit hashes alongside branch names in the branches view."
Expand Down

0 comments on commit acfd6b5

Please sign in to comment.