mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-03 13:21:56 +02: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:
parent
05bfa96936
commit
0e0458f355
@ -28,7 +28,8 @@ gui:
|
||||
expandFocusedSidePanel: false
|
||||
mainPanelSplitMode: 'flexible' # one of 'horizontal' | 'flexible' | 'vertical'
|
||||
language: 'auto' # one of 'auto' | 'en' | 'zh' | 'pl' | 'nl' | 'ja' | 'ko'
|
||||
timeFormat: '02 Jan 06 15:04 MST' # https://pkg.go.dev/time#Time.Format
|
||||
timeFormat: '02 Jan 06' # https://pkg.go.dev/time#Time.Format
|
||||
shortTimeFormat: '3:04PM'
|
||||
theme:
|
||||
activeBorderColor:
|
||||
- green
|
||||
|
@ -39,6 +39,7 @@ type GuiConfig struct {
|
||||
MainPanelSplitMode string `yaml:"mainPanelSplitMode"`
|
||||
Language string `yaml:"language"`
|
||||
TimeFormat string `yaml:"timeFormat"`
|
||||
ShortTimeFormat string `yaml:"shortTimeFormat"`
|
||||
Theme ThemeConfig `yaml:"theme"`
|
||||
CommitLength CommitLengthConfig `yaml:"commitLength"`
|
||||
SkipNoStagedFilesWarning bool `yaml:"skipNoStagedFilesWarning"`
|
||||
@ -398,7 +399,8 @@ func GetDefaultConfig() *UserConfig {
|
||||
ExpandFocusedSidePanel: false,
|
||||
MainPanelSplitMode: "flexible",
|
||||
Language: "auto",
|
||||
TimeFormat: time.RFC822,
|
||||
TimeFormat: "02 Jan 06",
|
||||
ShortTimeFormat: time.Kitchen,
|
||||
Theme: ThemeConfig{
|
||||
ActiveBorderColor: []string{"green", "bold"},
|
||||
InactiveBorderColor: []string{"default"},
|
||||
|
@ -2,6 +2,7 @@ package context
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
||||
@ -44,6 +45,8 @@ func NewLocalCommitsContext(c *ContextCommon) *LocalCommitsContext {
|
||||
c.Modes().CherryPicking.SelectedShaSet(),
|
||||
c.Modes().Diffing.Ref,
|
||||
c.UserConfig.Gui.TimeFormat,
|
||||
c.UserConfig.Gui.ShortTimeFormat,
|
||||
time.Now(),
|
||||
c.UserConfig.Git.ParseEmoji,
|
||||
selectedCommitSha,
|
||||
startIdx,
|
||||
|
@ -1,6 +1,8 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
@ -25,7 +27,9 @@ func NewReflogCommitsContext(c *ContextCommon) *ReflogCommitsContext {
|
||||
c.State().GetRepoState().GetScreenMode() != types.SCREEN_NORMAL,
|
||||
c.Modes().CherryPicking.SelectedShaSet(),
|
||||
c.Modes().Diffing.Ref,
|
||||
time.Now(),
|
||||
c.UserConfig.Gui.TimeFormat,
|
||||
c.UserConfig.Gui.ShortTimeFormat,
|
||||
c.UserConfig.Git.ParseEmoji,
|
||||
)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package context
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
@ -47,6 +48,8 @@ func NewSubCommitsContext(
|
||||
c.Modes().CherryPicking.SelectedShaSet(),
|
||||
c.Modes().Diffing.Ref,
|
||||
c.UserConfig.Gui.TimeFormat,
|
||||
c.UserConfig.Gui.ShortTimeFormat,
|
||||
time.Now(),
|
||||
c.UserConfig.Git.ParseEmoji,
|
||||
selectedCommitSha,
|
||||
startIdx,
|
||||
|
@ -3,6 +3,7 @@ package presentation
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fsmiamoto/git-todo-parser/todo"
|
||||
"github.com/jesseduffield/generics/set"
|
||||
@ -41,6 +42,8 @@ func GetCommitListDisplayStrings(
|
||||
cherryPickedCommitShaSet *set.Set[string],
|
||||
diffName string,
|
||||
timeFormat string,
|
||||
shortTimeFormat string,
|
||||
now time.Time,
|
||||
parseEmoji bool,
|
||||
selectedCommitSha string,
|
||||
startIdx int,
|
||||
@ -107,6 +110,8 @@ func GetCommitListDisplayStrings(
|
||||
cherryPickedCommitShaSet,
|
||||
diffName,
|
||||
timeFormat,
|
||||
shortTimeFormat,
|
||||
now,
|
||||
parseEmoji,
|
||||
getGraphLine(unfilteredIdx),
|
||||
fullDescription,
|
||||
@ -253,6 +258,8 @@ func displayCommit(
|
||||
cherryPickedCommitShaSet *set.Set[string],
|
||||
diffName string,
|
||||
timeFormat string,
|
||||
shortTimeFormat string,
|
||||
now time.Time,
|
||||
parseEmoji bool,
|
||||
graphLine string,
|
||||
fullDescription bool,
|
||||
@ -304,7 +311,9 @@ 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, timeFormat)))
|
||||
cols = append(cols, style.FgBlue.Sprint(
|
||||
utils.UnixToDateSmart(now, commit.UnixTimestamp, timeFormat, shortTimeFormat),
|
||||
))
|
||||
}
|
||||
cols = append(
|
||||
cols,
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/fsmiamoto/git-todo-parser/todo"
|
||||
"github.com/gookit/color"
|
||||
@ -31,6 +32,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
cherryPickedCommitShaSet *set.Set[string]
|
||||
diffName string
|
||||
timeFormat string
|
||||
shortTimeFormat string
|
||||
now time.Time
|
||||
parseEmoji bool
|
||||
selectedCommitSha string
|
||||
startIdx int
|
||||
@ -49,6 +52,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
showGraph: false,
|
||||
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||
cherryPickedCommitShaSet: set.New[string](),
|
||||
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
@ -62,6 +66,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
showGraph: false,
|
||||
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||
cherryPickedCommitShaSet: set.New[string](),
|
||||
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
expected: formatExpected(`
|
||||
sha1 commit1
|
||||
sha2 commit2
|
||||
@ -81,6 +86,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
showGraph: true,
|
||||
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||
cherryPickedCommitShaSet: set.New[string](),
|
||||
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
expected: formatExpected(`
|
||||
sha1 ⏣─╮ commit1
|
||||
sha2 ◯ │ commit2
|
||||
@ -104,6 +110,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||
cherryPickedCommitShaSet: set.New[string](),
|
||||
showYouAreHereLabel: true,
|
||||
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
expected: formatExpected(`
|
||||
sha1 pick commit1
|
||||
sha2 pick commit2
|
||||
@ -127,6 +134,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||
cherryPickedCommitShaSet: set.New[string](),
|
||||
showYouAreHereLabel: true,
|
||||
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
expected: formatExpected(`
|
||||
sha2 pick commit2
|
||||
sha3 ◯ <-- YOU ARE HERE --- commit3
|
||||
@ -149,6 +157,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||
cherryPickedCommitShaSet: set.New[string](),
|
||||
showYouAreHereLabel: true,
|
||||
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
expected: formatExpected(`
|
||||
sha4 ◯ commit4
|
||||
sha5 ◯ commit5
|
||||
@ -169,6 +178,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||
cherryPickedCommitShaSet: set.New[string](),
|
||||
showYouAreHereLabel: true,
|
||||
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
expected: formatExpected(`
|
||||
sha1 pick commit1
|
||||
sha2 pick commit2
|
||||
@ -189,6 +199,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||
cherryPickedCommitShaSet: set.New[string](),
|
||||
showYouAreHereLabel: true,
|
||||
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
expected: formatExpected(`
|
||||
sha5 ◯ commit5
|
||||
`),
|
||||
@ -208,6 +219,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||
cherryPickedCommitShaSet: set.New[string](),
|
||||
showYouAreHereLabel: true,
|
||||
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
expected: formatExpected(`
|
||||
sha1 pick commit1
|
||||
sha2 pick commit2
|
||||
@ -226,6 +238,7 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||
cherryPickedCommitShaSet: set.New[string](),
|
||||
showYouAreHereLabel: false,
|
||||
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||
expected: formatExpected(`
|
||||
sha1 pick commit1
|
||||
sha2 ◯ commit2
|
||||
@ -235,19 +248,21 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
{
|
||||
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"},
|
||||
{Name: "commit1", Sha: "sha1", UnixTimestamp: 1577844184, AuthorName: "Jesse Duffield"},
|
||||
{Name: "commit2", Sha: "sha2", UnixTimestamp: 1576844184, AuthorName: "Jesse Duffield"},
|
||||
},
|
||||
fullDescription: true,
|
||||
timeFormat: "2006-01-02 15:04:05",
|
||||
timeFormat: "2006-01-02",
|
||||
shortTimeFormat: "3:04PM",
|
||||
startIdx: 0,
|
||||
length: 2,
|
||||
showGraph: false,
|
||||
bisectInfo: git_commands.NewNullBisectInfo(),
|
||||
cherryPickedCommitShaSet: set.New[string](),
|
||||
now: time.Date(2020, 1, 1, 5, 3, 4, 0, time.UTC),
|
||||
expected: formatExpected(`
|
||||
sha1 2022-05-13 12:00:00 Jesse Duffield commit1
|
||||
sha2 2022-05-14 12:00:00 Jesse Duffield commit2
|
||||
sha1 2:03AM Jesse Duffield commit1
|
||||
sha2 2019-12-20 Jesse Duffield commit2
|
||||
`),
|
||||
},
|
||||
}
|
||||
@ -274,6 +289,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
|
||||
s.cherryPickedCommitShaSet,
|
||||
s.diffName,
|
||||
s.timeFormat,
|
||||
s.shortTimeFormat,
|
||||
s.now,
|
||||
s.parseEmoji,
|
||||
s.selectedCommitSha,
|
||||
s.startIdx,
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,13 @@ func UnixToTimeAgo(timestamp int64) string {
|
||||
return fmt.Sprintf("%dy", int(delta))
|
||||
}
|
||||
|
||||
func UnixToDate(timestamp int64, timeFormat string) string {
|
||||
return time.Unix(timestamp, 0).Format(timeFormat)
|
||||
// formats the date in a smart way, if the date is today, it will show the time, otherwise it will show the date
|
||||
func UnixToDateSmart(now time.Time, timestamp int64, longTimeFormat string, shortTimeFormat string) string {
|
||||
date := time.Unix(timestamp, 0)
|
||||
|
||||
if date.Day() == now.Day() && date.Month() == now.Month() && date.Year() == now.Year() {
|
||||
return date.Format(shortTimeFormat)
|
||||
}
|
||||
|
||||
return date.Format(longTimeFormat)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user