1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

More compact and flexible date format

You can now configure both a time format and a short time format, where the short format kicks in
when the time is within the last day
This commit is contained in:
Jesse Duffield
2023-05-26 16:38:58 +10:00
parent 05bfa96936
commit 0e0458f355
9 changed files with 72 additions and 20 deletions

View File

@ -1,6 +1,8 @@
package presentation
import (
"time"
"github.com/jesseduffield/generics/set"
"github.com/jesseduffield/generics/slices"
"github.com/jesseduffield/lazygit/pkg/commands/models"
@ -10,7 +12,7 @@ import (
"github.com/kyokomi/emoji/v2"
)
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, timeFormat string, parseEmoji bool) [][]string {
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, now time.Time, timeFormat string, shortTimeFormat string, parseEmoji bool) [][]string {
var displayFunc func(*models.Commit, reflogCommitDisplayAttributes) []string
if fullDescription {
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
@ -23,10 +25,12 @@ func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription
cherryPicked := cherryPickedCommitShaSet.Includes(commit.Sha)
return displayFunc(commit,
reflogCommitDisplayAttributes{
cherryPicked: cherryPicked,
diffed: diffed,
parseEmoji: parseEmoji,
timeFormat: timeFormat,
cherryPicked: cherryPicked,
diffed: diffed,
parseEmoji: parseEmoji,
timeFormat: timeFormat,
shortTimeFormat: shortTimeFormat,
now: now,
})
})
}
@ -45,10 +49,12 @@ func reflogShaColor(cherryPicked, diffed bool) style.TextStyle {
}
type reflogCommitDisplayAttributes struct {
cherryPicked bool
diffed bool
parseEmoji bool
timeFormat string
cherryPicked bool
diffed bool
parseEmoji bool
timeFormat string
shortTimeFormat string
now time.Time
}
func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, attrs reflogCommitDisplayAttributes) []string {
@ -59,7 +65,7 @@ func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, attrs ref
return []string{
reflogShaColor(attrs.cherryPicked, attrs.diffed).Sprint(c.ShortSha()),
style.FgMagenta.Sprint(utils.UnixToDate(c.UnixTimestamp, attrs.timeFormat)),
style.FgMagenta.Sprint(utils.UnixToDateSmart(attrs.now, c.UnixTimestamp, attrs.timeFormat, attrs.shortTimeFormat)),
theme.DefaultTextColor.Sprint(name),
}
}