From b08ab8dfb72d42d69f57c909cdd3afa52e016bc6 Mon Sep 17 00:00:00 2001 From: Christian Zangl Date: Sat, 12 Feb 2022 10:23:22 +0100 Subject: [PATCH] Continue PR: configure time format in the info column (#751) * Allow to configure time format in the info column * Update infotimefmt PR from Krzysztof Maicher Add format length, rename options Co-authored-by: Krzysztof Maicher --- complete.go | 2 ++ doc.go | 10 ++++++++++ docstring.go | 12 ++++++++++++ eval.go | 6 ++++++ lf.1 | 14 ++++++++++++++ opts.go | 6 ++++++ ui.go | 10 +++++----- 7 files changed, 55 insertions(+), 5 deletions(-) diff --git a/complete.go b/complete.go index d985dd2..599323e 100644 --- a/complete.go +++ b/complete.go @@ -159,6 +159,8 @@ var ( "sortby", "timefmt", "tempmarks", + "infotimefmtnew", + "infotimefmtold", "truncatechar", } ) diff --git a/doc.go b/doc.go index bf13f2c..f041ba3 100644 --- a/doc.go +++ b/doc.go @@ -140,6 +140,8 @@ The following options can be used to customize the behavior of lf: tabstop int (default 8) tempmarks string (default '') timefmt string (default 'Mon Jan _2 15:04:05 2006') + infotimefmtnew string (default 'Jan _2 15:04') + infotimefmtold string (default 'Jan _2 2006') truncatechar string (default '~') waitmsg string (default 'Press any key to continue') wrapscan bool (default on) @@ -722,6 +724,14 @@ A string that lists all marks to treat as temporary. They are not synced to othe Format string of the file modification time shown in the bottom line. + infotimefmtnew string (default 'Jan _2 15:04') + +Format string of the file time shown in the info column when it matches this year. + + infotimefmtold string (default 'Jan _2 2006') + +Format string of the file time shown in the info column when it doesn't match this year. + truncatechar string (default '~') Truncate character shown at the end when the file name does not fit to the pane. diff --git a/docstring.go b/docstring.go index 56071d9..eafd161 100644 --- a/docstring.go +++ b/docstring.go @@ -144,6 +144,8 @@ The following options can be used to customize the behavior of lf: tabstop int (default 8) tempmarks string (default '') timefmt string (default 'Mon Jan _2 15:04:05 2006') + infotimefmtnew string (default 'Jan _2 15:04') + infotimefmtold string (default 'Jan _2 2006') truncatechar string (default '~') waitmsg string (default 'Press any key to continue') wrapscan bool (default on) @@ -774,6 +776,16 @@ treated as temporary and does not need to be specified. Format string of the file modification time shown in the bottom line. + infotimefmtnew string (default 'Jan _2 15:04') + +Format string of the file time shown in the info column when it matches this +year. + + infotimefmtold string (default 'Jan _2 2006') + +Format string of the file time shown in the info column when it doesn't +match this year. + truncatechar string (default '~') Truncate character shown at the end when the file name does not fit to the diff --git a/eval.go b/eval.go index 780084c..b9e754f 100644 --- a/eval.go +++ b/eval.go @@ -418,6 +418,12 @@ func (e *setExpr) eval(app *app, args []string) { } case "timefmt": gOpts.timefmt = e.val + case "infotimefmtnew": + gOpts.infotimefmtnew = e.val + gInfotimefmtMaxLen = max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)) + case "infotimefmtold": + gOpts.infotimefmtold = e.val + gInfotimefmtMaxLen = max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)) case "truncatechar": if runeSliceWidth([]rune(e.val)) != 1 { app.ui.echoerr("truncatechar: value should be a single character") diff --git a/lf.1 b/lf.1 index dbd4c74..dbe9311 100644 --- a/lf.1 +++ b/lf.1 @@ -160,6 +160,8 @@ The following options can be used to customize the behavior of lf: tabstop int (default 8) tempmarks string (default '') timefmt string (default 'Mon Jan _2 15:04:05 2006') + infotimefmtnew string (default 'Jan _2 15:04') + infotimefmtold string (default 'Jan _2 2006') truncatechar string (default '~') waitmsg string (default 'Press any key to continue') wrapscan bool (default on) @@ -875,6 +877,18 @@ A string that lists all marks to treat as temporary. They are not synced to othe .PP Format string of the file modification time shown in the bottom line. .PP +.EX + infotimefmtnew string (default 'Jan _2 15:04') +.EE +.PP +Format string of the file time shown in the info column when it matches this year. +.PP +.EX + infotimefmtold string (default 'Jan _2 2006') +.EE +.PP +Format string of the file time shown in the info column when it doesn't match this year. +.PP .EX truncatechar string (default '~') .EE diff --git a/opts.go b/opts.go index e2a1d14..10917b3 100644 --- a/opts.go +++ b/opts.go @@ -62,6 +62,8 @@ var gOpts struct { shell string shellflag string timefmt string + infotimefmtnew string + infotimefmtold string truncatechar string ratios []int hiddenfiles []string @@ -74,6 +76,8 @@ var gOpts struct { tempmarks string } +var gInfotimefmtMaxLen = 12 + func init() { gOpts.anchorfind = true gOpts.autoquit = false @@ -109,6 +113,8 @@ func init() { gOpts.shell = gDefaultShell gOpts.shellflag = gDefaultShellFlag gOpts.timefmt = time.ANSIC + gOpts.infotimefmtnew = "Jan _2 15:04" + gOpts.infotimefmtold = "Jan _2 2006" gOpts.truncatechar = "~" gOpts.ratios = []int{1, 2, 3} gOpts.hiddenfiles = []string{".*"} diff --git a/ui.go b/ui.go index f84d8d4..e30f791 100644 --- a/ui.go +++ b/ui.go @@ -279,9 +279,9 @@ var gThisYear = time.Now().Year() func infotimefmt(t time.Time) string { if t.Year() == gThisYear { - return t.Format("Jan _2 15:04") + return t.Format(gOpts.infotimefmtnew) } - return t.Format("Jan _2 2006") + return t.Format(gOpts.infotimefmtold) } func fileInfo(f *file, d *dir) string { @@ -328,11 +328,11 @@ func fileInfo(f *file, d *dir) string { info = fmt.Sprintf("%s 999+", info) } case "time": - info = fmt.Sprintf("%s %12s", info, infotimefmt(f.ModTime())) + info = fmt.Sprintf(fmt.Sprint("%"+"s %", gInfotimefmtMaxLen, "s"), info, infotimefmt(f.ModTime())) case "atime": - info = fmt.Sprintf("%s %12s", info, infotimefmt(f.accessTime)) + info = fmt.Sprintf(fmt.Sprint("%"+"s %", gInfotimefmtMaxLen, "s"), info, infotimefmt(f.accessTime)) case "ctime": - info = fmt.Sprintf("%s %12s", info, infotimefmt(f.changeTime)) + info = fmt.Sprintf(fmt.Sprint("%"+"s %", gInfotimefmtMaxLen, "s"), info, infotimefmt(f.changeTime)) default: log.Printf("unknown info type: %s", s) }