mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-25 18:55:28 -06:00
feat: add ability to customize time format
This commit is contained in:
@@ -36,6 +36,7 @@ func GetCommitListDisplayStrings(
|
||||
fullDescription bool,
|
||||
cherryPickedCommitShaSet *set.Set[string],
|
||||
diffName string,
|
||||
timeFormat string,
|
||||
parseEmoji bool,
|
||||
selectedCommitSha string,
|
||||
startIdx int,
|
||||
@@ -98,6 +99,7 @@ func GetCommitListDisplayStrings(
|
||||
commit,
|
||||
cherryPickedCommitShaSet,
|
||||
diffName,
|
||||
timeFormat,
|
||||
parseEmoji,
|
||||
getGraphLine(unfilteredIdx),
|
||||
fullDescription,
|
||||
@@ -241,6 +243,7 @@ func displayCommit(
|
||||
commit *models.Commit,
|
||||
cherryPickedCommitShaSet *set.Set[string],
|
||||
diffName string,
|
||||
timeFormat string,
|
||||
parseEmoji bool,
|
||||
graphLine string,
|
||||
fullDescription bool,
|
||||
@@ -283,7 +286,7 @@ func displayCommit(
|
||||
cols = append(cols, shaColor.Sprint(commit.ShortSha()))
|
||||
cols = append(cols, bisectString)
|
||||
if fullDescription {
|
||||
cols = append(cols, style.FgBlue.Sprint(utils.UnixToDate(commit.UnixTimestamp)))
|
||||
cols = append(cols, style.FgBlue.Sprint(utils.UnixToDate(commit.UnixTimestamp, timeFormat)))
|
||||
}
|
||||
cols = append(
|
||||
cols,
|
||||
|
||||
@@ -28,6 +28,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
fullDescription bool
|
||||
cherryPickedCommitShaSet *set.Set[string]
|
||||
diffName string
|
||||
timeFormat string
|
||||
parseEmoji bool
|
||||
selectedCommitSha string
|
||||
startIdx int
|
||||
@@ -203,6 +204,24 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
sha2 pick commit2
|
||||
`),
|
||||
},
|
||||
{
|
||||
testName: "custom time format",
|
||||
commits: []*models.Commit{
|
||||
{Name: "commit1", Sha: "sha1", UnixTimestamp: 1652443200, AuthorName: "Jesse Duffield"},
|
||||
{Name: "commit2", Sha: "sha2", UnixTimestamp: 1652529600, AuthorName: "Jesse Duffield"},
|
||||
},
|
||||
fullDescription: true,
|
||||
timeFormat: "2006-01-02 15:04:05",
|
||||
startIdx: 0,
|
||||
length: 2,
|
||||
showGraph: false,
|
||||
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||
cherryPickedCommitShaSet: set.New[string](),
|
||||
expected: formatExpected(`
|
||||
sha1 2022-05-13 21:00:00 Jesse Duffield commit1
|
||||
sha2 2022-05-14 21:00:00 Jesse Duffield commit2
|
||||
`),
|
||||
},
|
||||
}
|
||||
|
||||
focusing := false
|
||||
@@ -221,6 +240,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
s.fullDescription,
|
||||
s.cherryPickedCommitShaSet,
|
||||
s.diffName,
|
||||
s.timeFormat,
|
||||
s.parseEmoji,
|
||||
s.selectedCommitSha,
|
||||
s.startIdx,
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"github.com/kyokomi/emoji/v2"
|
||||
)
|
||||
|
||||
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, parseEmoji bool) [][]string {
|
||||
var displayFunc func(*models.Commit, bool, bool, bool) []string
|
||||
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, timeFormat string, parseEmoji bool) [][]string {
|
||||
var displayFunc func(*models.Commit, string, bool, bool, bool) []string
|
||||
if fullDescription {
|
||||
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
|
||||
} else {
|
||||
@@ -21,7 +21,7 @@ func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription
|
||||
return slices.Map(commits, func(commit *models.Commit) []string {
|
||||
diffed := commit.Sha == diffName
|
||||
cherryPicked := cherryPickedCommitShaSet.Includes(commit.Sha)
|
||||
return displayFunc(commit, cherryPicked, diffed, parseEmoji)
|
||||
return displayFunc(commit, timeFormat, cherryPicked, diffed, parseEmoji)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func reflogShaColor(cherryPicked, diffed bool) style.TextStyle {
|
||||
return shaColor
|
||||
}
|
||||
|
||||
func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, cherryPicked, diffed, parseEmoji bool) []string {
|
||||
func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, timeFormat string, cherryPicked, diffed, parseEmoji bool) []string {
|
||||
name := c.Name
|
||||
if parseEmoji {
|
||||
name = emoji.Sprint(name)
|
||||
@@ -46,12 +46,12 @@ func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, cherryPic
|
||||
|
||||
return []string{
|
||||
reflogShaColor(cherryPicked, diffed).Sprint(c.ShortSha()),
|
||||
style.FgMagenta.Sprint(utils.UnixToDate(c.UnixTimestamp)),
|
||||
style.FgMagenta.Sprint(utils.UnixToDate(c.UnixTimestamp, timeFormat)),
|
||||
theme.DefaultTextColor.Sprint(name),
|
||||
}
|
||||
}
|
||||
|
||||
func getDisplayStringsForReflogCommit(c *models.Commit, cherryPicked, diffed, parseEmoji bool) []string {
|
||||
func getDisplayStringsForReflogCommit(c *models.Commit, timeFormat string, cherryPicked, diffed, parseEmoji bool) []string {
|
||||
name := c.Name
|
||||
if parseEmoji {
|
||||
name = emoji.Sprint(name)
|
||||
|
||||
Reference in New Issue
Block a user