mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-27 12:32:37 +02:00
Merge pull request #1948 from Ryooooooga/feature/time-format
This commit is contained in:
commit
e1e16a34da
@ -23,6 +23,7 @@ gui:
|
|||||||
expandFocusedSidePanel: false
|
expandFocusedSidePanel: false
|
||||||
mainPanelSplitMode: 'flexible' # one of 'horizontal' | 'flexible' | 'vertical'
|
mainPanelSplitMode: 'flexible' # one of 'horizontal' | 'flexible' | 'vertical'
|
||||||
language: 'auto' # one of 'auto' | 'en' | 'zh' | 'pl' | 'nl' | 'ja'
|
language: 'auto' # one of 'auto' | 'en' | 'zh' | 'pl' | 'nl' | 'ja'
|
||||||
|
timeFormat: '02 Jan 06 15:04 MST' # https://pkg.go.dev/time#Time.Format
|
||||||
theme:
|
theme:
|
||||||
lightTheme: false # For terminals with a light background
|
lightTheme: false # For terminals with a light background
|
||||||
activeBorderColor:
|
activeBorderColor:
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type UserConfig struct {
|
type UserConfig struct {
|
||||||
Gui GuiConfig `yaml:"gui"`
|
Gui GuiConfig `yaml:"gui"`
|
||||||
Git GitConfig `yaml:"git"`
|
Git GitConfig `yaml:"git"`
|
||||||
@ -36,6 +40,7 @@ type GuiConfig struct {
|
|||||||
ExpandFocusedSidePanel bool `yaml:"expandFocusedSidePanel"`
|
ExpandFocusedSidePanel bool `yaml:"expandFocusedSidePanel"`
|
||||||
MainPanelSplitMode string `yaml:"mainPanelSplitMode"`
|
MainPanelSplitMode string `yaml:"mainPanelSplitMode"`
|
||||||
Language string `yaml:"language"`
|
Language string `yaml:"language"`
|
||||||
|
TimeFormat string `yaml:"timeFormat"`
|
||||||
Theme ThemeConfig `yaml:"theme"`
|
Theme ThemeConfig `yaml:"theme"`
|
||||||
CommitLength CommitLengthConfig `yaml:"commitLength"`
|
CommitLength CommitLengthConfig `yaml:"commitLength"`
|
||||||
SkipNoStagedFilesWarning bool `yaml:"skipNoStagedFilesWarning"`
|
SkipNoStagedFilesWarning bool `yaml:"skipNoStagedFilesWarning"`
|
||||||
@ -341,6 +346,7 @@ func GetDefaultConfig() *UserConfig {
|
|||||||
ExpandFocusedSidePanel: false,
|
ExpandFocusedSidePanel: false,
|
||||||
MainPanelSplitMode: "flexible",
|
MainPanelSplitMode: "flexible",
|
||||||
Language: "auto",
|
Language: "auto",
|
||||||
|
TimeFormat: time.RFC822,
|
||||||
Theme: ThemeConfig{
|
Theme: ThemeConfig{
|
||||||
LightTheme: false,
|
LightTheme: false,
|
||||||
ActiveBorderColor: []string{"green", "bold"},
|
ActiveBorderColor: []string{"green", "bold"},
|
||||||
|
@ -123,6 +123,7 @@ func (gui *Gui) branchCommitsListContext() *context.LocalCommitsContext {
|
|||||||
gui.State.ScreenMode != SCREEN_NORMAL,
|
gui.State.ScreenMode != SCREEN_NORMAL,
|
||||||
gui.helpers.CherryPick.CherryPickedCommitShaSet(),
|
gui.helpers.CherryPick.CherryPickedCommitShaSet(),
|
||||||
gui.State.Modes.Diffing.Ref,
|
gui.State.Modes.Diffing.Ref,
|
||||||
|
gui.c.UserConfig.Gui.TimeFormat,
|
||||||
gui.c.UserConfig.Git.ParseEmoji,
|
gui.c.UserConfig.Git.ParseEmoji,
|
||||||
selectedCommitSha,
|
selectedCommitSha,
|
||||||
startIdx,
|
startIdx,
|
||||||
@ -155,6 +156,7 @@ func (gui *Gui) subCommitsListContext() *context.SubCommitsContext {
|
|||||||
gui.State.ScreenMode != SCREEN_NORMAL,
|
gui.State.ScreenMode != SCREEN_NORMAL,
|
||||||
gui.helpers.CherryPick.CherryPickedCommitShaSet(),
|
gui.helpers.CherryPick.CherryPickedCommitShaSet(),
|
||||||
gui.State.Modes.Diffing.Ref,
|
gui.State.Modes.Diffing.Ref,
|
||||||
|
gui.c.UserConfig.Gui.TimeFormat,
|
||||||
gui.c.UserConfig.Git.ParseEmoji,
|
gui.c.UserConfig.Git.ParseEmoji,
|
||||||
selectedCommitSha,
|
selectedCommitSha,
|
||||||
startIdx,
|
startIdx,
|
||||||
@ -199,6 +201,7 @@ func (gui *Gui) reflogCommitsListContext() *context.ReflogCommitsContext {
|
|||||||
gui.State.ScreenMode != SCREEN_NORMAL,
|
gui.State.ScreenMode != SCREEN_NORMAL,
|
||||||
gui.helpers.CherryPick.CherryPickedCommitShaSet(),
|
gui.helpers.CherryPick.CherryPickedCommitShaSet(),
|
||||||
gui.State.Modes.Diffing.Ref,
|
gui.State.Modes.Diffing.Ref,
|
||||||
|
gui.c.UserConfig.Gui.TimeFormat,
|
||||||
gui.c.UserConfig.Git.ParseEmoji,
|
gui.c.UserConfig.Git.ParseEmoji,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -36,6 +36,7 @@ func GetCommitListDisplayStrings(
|
|||||||
fullDescription bool,
|
fullDescription bool,
|
||||||
cherryPickedCommitShaSet *set.Set[string],
|
cherryPickedCommitShaSet *set.Set[string],
|
||||||
diffName string,
|
diffName string,
|
||||||
|
timeFormat string,
|
||||||
parseEmoji bool,
|
parseEmoji bool,
|
||||||
selectedCommitSha string,
|
selectedCommitSha string,
|
||||||
startIdx int,
|
startIdx int,
|
||||||
@ -98,6 +99,7 @@ func GetCommitListDisplayStrings(
|
|||||||
commit,
|
commit,
|
||||||
cherryPickedCommitShaSet,
|
cherryPickedCommitShaSet,
|
||||||
diffName,
|
diffName,
|
||||||
|
timeFormat,
|
||||||
parseEmoji,
|
parseEmoji,
|
||||||
getGraphLine(unfilteredIdx),
|
getGraphLine(unfilteredIdx),
|
||||||
fullDescription,
|
fullDescription,
|
||||||
@ -241,6 +243,7 @@ func displayCommit(
|
|||||||
commit *models.Commit,
|
commit *models.Commit,
|
||||||
cherryPickedCommitShaSet *set.Set[string],
|
cherryPickedCommitShaSet *set.Set[string],
|
||||||
diffName string,
|
diffName string,
|
||||||
|
timeFormat string,
|
||||||
parseEmoji bool,
|
parseEmoji bool,
|
||||||
graphLine string,
|
graphLine string,
|
||||||
fullDescription bool,
|
fullDescription bool,
|
||||||
@ -283,7 +286,7 @@ func displayCommit(
|
|||||||
cols = append(cols, shaColor.Sprint(commit.ShortSha()))
|
cols = append(cols, shaColor.Sprint(commit.ShortSha()))
|
||||||
cols = append(cols, bisectString)
|
cols = append(cols, bisectString)
|
||||||
if fullDescription {
|
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 = append(
|
||||||
cols,
|
cols,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package presentation
|
package presentation
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
|||||||
fullDescription bool
|
fullDescription bool
|
||||||
cherryPickedCommitShaSet *set.Set[string]
|
cherryPickedCommitShaSet *set.Set[string]
|
||||||
diffName string
|
diffName string
|
||||||
|
timeFormat string
|
||||||
parseEmoji bool
|
parseEmoji bool
|
||||||
selectedCommitSha string
|
selectedCommitSha string
|
||||||
startIdx int
|
startIdx int
|
||||||
@ -203,8 +205,28 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
|||||||
sha2 pick commit2
|
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 12:00:00 Jesse Duffield commit1
|
||||||
|
sha2 2022-05-14 12:00:00 Jesse Duffield commit2
|
||||||
|
`),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
os.Setenv("TZ", "UTC")
|
||||||
|
|
||||||
focusing := false
|
focusing := false
|
||||||
for _, scenario := range scenarios {
|
for _, scenario := range scenarios {
|
||||||
if scenario.focus {
|
if scenario.focus {
|
||||||
@ -221,6 +243,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
|||||||
s.fullDescription,
|
s.fullDescription,
|
||||||
s.cherryPickedCommitShaSet,
|
s.cherryPickedCommitShaSet,
|
||||||
s.diffName,
|
s.diffName,
|
||||||
|
s.timeFormat,
|
||||||
s.parseEmoji,
|
s.parseEmoji,
|
||||||
s.selectedCommitSha,
|
s.selectedCommitSha,
|
||||||
s.startIdx,
|
s.startIdx,
|
||||||
|
@ -10,8 +10,8 @@ import (
|
|||||||
"github.com/kyokomi/emoji/v2"
|
"github.com/kyokomi/emoji/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaSet *set.Set[string], diffName string, parseEmoji 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, bool, bool, bool) []string
|
var displayFunc func(*models.Commit, string, bool, bool, bool) []string
|
||||||
if fullDescription {
|
if fullDescription {
|
||||||
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
|
displayFunc = getFullDescriptionDisplayStringsForReflogCommit
|
||||||
} else {
|
} else {
|
||||||
@ -21,7 +21,7 @@ func GetReflogCommitListDisplayStrings(commits []*models.Commit, fullDescription
|
|||||||
return slices.Map(commits, func(commit *models.Commit) []string {
|
return slices.Map(commits, func(commit *models.Commit) []string {
|
||||||
diffed := commit.Sha == diffName
|
diffed := commit.Sha == diffName
|
||||||
cherryPicked := cherryPickedCommitShaSet.Includes(commit.Sha)
|
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
|
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
|
name := c.Name
|
||||||
if parseEmoji {
|
if parseEmoji {
|
||||||
name = emoji.Sprint(name)
|
name = emoji.Sprint(name)
|
||||||
@ -46,12 +46,12 @@ func getFullDescriptionDisplayStringsForReflogCommit(c *models.Commit, cherryPic
|
|||||||
|
|
||||||
return []string{
|
return []string{
|
||||||
reflogShaColor(cherryPicked, diffed).Sprint(c.ShortSha()),
|
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),
|
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
|
name := c.Name
|
||||||
if parseEmoji {
|
if parseEmoji {
|
||||||
name = emoji.Sprint(name)
|
name = emoji.Sprint(name)
|
||||||
|
@ -20,6 +20,6 @@ func UnixToTimeAgo(timestamp int64) string {
|
|||||||
return fmt.Sprintf("%dy", int(delta))
|
return fmt.Sprintf("%dy", int(delta))
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnixToDate(timestamp int64) string {
|
func UnixToDate(timestamp int64, timeFormat string) string {
|
||||||
return time.Unix(timestamp, 0).Format(time.RFC822)
|
return time.Unix(timestamp, 0).Format(timeFormat)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user