mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 04:15:48 +02:00
Provide two config keys for configuring the author length in commits view
One is for the normal view, the other for the expanded view.
This commit is contained in:
parent
7be82d4713
commit
bd782f16dd
6 changed files with 79 additions and 10 deletions
|
@ -185,6 +185,12 @@ gui:
|
||||||
# If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.
|
# If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.
|
||||||
showFileIcons: true
|
showFileIcons: true
|
||||||
|
|
||||||
|
# Length of author name in (non-expanded) commits view. 2 means show initials only.
|
||||||
|
commitAuthorShortLength: 2
|
||||||
|
|
||||||
|
# Length of author name in expanded commits view. 2 means show initials only.
|
||||||
|
commitAuthorLongLength: 17
|
||||||
|
|
||||||
# Length of commit hash in commits view. 0 shows '*' if NF icons aren't on.
|
# Length of commit hash in commits view. 0 shows '*' if NF icons aren't on.
|
||||||
commitHashLength: 8
|
commitHashLength: 8
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,10 @@ type GuiConfig struct {
|
||||||
NerdFontsVersion string `yaml:"nerdFontsVersion" jsonschema:"enum=2,enum=3,enum="`
|
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.
|
// If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.
|
||||||
ShowFileIcons bool `yaml:"showFileIcons"`
|
ShowFileIcons bool `yaml:"showFileIcons"`
|
||||||
|
// Length of author name in (non-expanded) commits view. 2 means show initials only.
|
||||||
|
CommitAuthorShortLength int `yaml:"commitAuthorShortLength"`
|
||||||
|
// Length of author name in expanded commits view. 2 means show initials only.
|
||||||
|
CommitAuthorLongLength int `yaml:"commitAuthorLongLength"`
|
||||||
// Length of commit hash in commits view. 0 shows '*' if NF icons aren't on.
|
// Length of commit hash in commits view. 0 shows '*' if NF icons aren't on.
|
||||||
CommitHashLength int `yaml:"commitHashLength" jsonschema:"minimum=0"`
|
CommitHashLength int `yaml:"commitHashLength" jsonschema:"minimum=0"`
|
||||||
// If true, show commit hashes alongside branch names in the branches view.
|
// If true, show commit hashes alongside branch names in the branches view.
|
||||||
|
@ -694,6 +698,8 @@ func GetDefaultConfig() *UserConfig {
|
||||||
ShowIcons: false,
|
ShowIcons: false,
|
||||||
NerdFontsVersion: "",
|
NerdFontsVersion: "",
|
||||||
ShowFileIcons: true,
|
ShowFileIcons: true,
|
||||||
|
CommitAuthorShortLength: 2,
|
||||||
|
CommitAuthorLongLength: 17,
|
||||||
CommitHashLength: 8,
|
CommitHashLength: 8,
|
||||||
ShowBranchCommitHash: false,
|
ShowBranchCommitHash: false,
|
||||||
ShowDivergenceFromBaseBranch: "none",
|
ShowDivergenceFromBaseBranch: "none",
|
||||||
|
|
|
@ -11,11 +11,16 @@ import (
|
||||||
"github.com/mattn/go-runewidth"
|
"github.com/mattn/go-runewidth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type authorNameCacheKey struct {
|
||||||
|
authorName string
|
||||||
|
truncateTo int
|
||||||
|
}
|
||||||
|
|
||||||
// if these being global variables causes trouble we can wrap them in a struct
|
// if these being global variables causes trouble we can wrap them in a struct
|
||||||
// attached to the gui state.
|
// attached to the gui state.
|
||||||
var (
|
var (
|
||||||
authorInitialCache = make(map[string]string)
|
authorInitialCache = make(map[string]string)
|
||||||
authorNameCache = make(map[string]string)
|
authorNameCache = make(map[authorNameCacheKey]string)
|
||||||
authorStyleCache = make(map[string]style.TextStyle)
|
authorStyleCache = make(map[string]style.TextStyle)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -37,19 +42,37 @@ func ShortAuthor(authorName string) string {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
func LongAuthor(authorName string) string {
|
func LongAuthor(authorName string, length int) string {
|
||||||
if value, ok := authorNameCache[authorName]; ok {
|
cacheKey := authorNameCacheKey{authorName: authorName, truncateTo: length}
|
||||||
|
if value, ok := authorNameCache[cacheKey]; ok {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
paddedAuthorName := utils.WithPadding(authorName, 17, utils.AlignLeft)
|
paddedAuthorName := utils.WithPadding(authorName, length, utils.AlignLeft)
|
||||||
truncatedName := utils.TruncateWithEllipsis(paddedAuthorName, 17)
|
truncatedName := utils.TruncateWithEllipsis(paddedAuthorName, length)
|
||||||
value := AuthorStyle(authorName).Sprint(truncatedName)
|
value := AuthorStyle(authorName).Sprint(truncatedName)
|
||||||
authorNameCache[authorName] = value
|
authorNameCache[cacheKey] = value
|
||||||
|
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuthorWithLength returns a representation of the author that fits into a
|
||||||
|
// given maximum length:
|
||||||
|
// - if the length is less than 2, it returns an empty string
|
||||||
|
// - if the length is 2, it returns the initials
|
||||||
|
// - otherwise, it returns the author name truncated to the maximum length
|
||||||
|
func AuthorWithLength(authorName string, length int) string {
|
||||||
|
if length < 2 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if length == 2 {
|
||||||
|
return ShortAuthor(authorName)
|
||||||
|
}
|
||||||
|
|
||||||
|
return LongAuthor(authorName, length)
|
||||||
|
}
|
||||||
|
|
||||||
func AuthorStyle(authorName string) style.TextStyle {
|
func AuthorStyle(authorName string) style.TextStyle {
|
||||||
if value, ok := authorStyleCache[authorName]; ok {
|
if value, ok := authorStyleCache[authorName]; ok {
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package authors
|
package authors
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
func TestGetInitials(t *testing.T) {
|
func TestGetInitials(t *testing.T) {
|
||||||
for input, expectedOutput := range map[string]string{
|
for input, expectedOutput := range map[string]string{
|
||||||
|
@ -18,3 +23,21 @@ func TestGetInitials(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAuthorWithLength(t *testing.T) {
|
||||||
|
scenarios := []struct {
|
||||||
|
authorName string
|
||||||
|
length int
|
||||||
|
expectedOutput string
|
||||||
|
}{
|
||||||
|
{"Jesse Duffield", 0, ""},
|
||||||
|
{"Jesse Duffield", 1, ""},
|
||||||
|
{"Jesse Duffield", 2, "JD"},
|
||||||
|
{"Jesse Duffield", 3, "Je…"},
|
||||||
|
{"Jesse Duffield", 10, "Jesse Duf…"},
|
||||||
|
{"Jesse Duffield", 14, "Jesse Duffield"},
|
||||||
|
}
|
||||||
|
for _, s := range scenarios {
|
||||||
|
assert.Equal(t, s.expectedOutput, utils.Decolorise(AuthorWithLength(s.authorName, s.length)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -440,10 +440,11 @@ func displayCommit(
|
||||||
mark = fmt.Sprintf("%s ", willBeRebased)
|
mark = fmt.Sprintf("%s ", willBeRebased)
|
||||||
}
|
}
|
||||||
|
|
||||||
authorFunc := authors.ShortAuthor
|
authorLength := common.UserConfig.Gui.CommitAuthorShortLength
|
||||||
if fullDescription {
|
if fullDescription {
|
||||||
authorFunc = authors.LongAuthor
|
authorLength = common.UserConfig.Gui.CommitAuthorLongLength
|
||||||
}
|
}
|
||||||
|
author := authors.AuthorWithLength(commit.AuthorName, authorLength)
|
||||||
|
|
||||||
cols := make([]string, 0, 7)
|
cols := make([]string, 0, 7)
|
||||||
cols = append(
|
cols = append(
|
||||||
|
@ -453,7 +454,7 @@ func displayCommit(
|
||||||
bisectString,
|
bisectString,
|
||||||
descriptionString,
|
descriptionString,
|
||||||
actionString,
|
actionString,
|
||||||
authorFunc(commit.AuthorName),
|
author,
|
||||||
graphLine+mark+tagString+theme.DefaultTextColor.Sprint(name),
|
graphLine+mark+tagString+theme.DefaultTextColor.Sprint(name),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -332,6 +332,16 @@
|
||||||
"description": "If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.",
|
"description": "If true (default), file icons are shown in the file views. Only relevant if NerdFontsVersion is not empty.",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
|
"commitAuthorShortLength": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Length of author name in (non-expanded) commits view. 2 means show initials only.",
|
||||||
|
"default": 2
|
||||||
|
},
|
||||||
|
"commitAuthorLongLength": {
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Length of author name in expanded commits view. 2 means show initials only.",
|
||||||
|
"default": 17
|
||||||
|
},
|
||||||
"commitHashLength": {
|
"commitHashLength": {
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
"minimum": 0,
|
"minimum": 0,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue