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 <krzysztof.maicher@gmail.com>
This commit is contained in:
Christian Zangl 2022-02-12 10:23:22 +01:00 committed by GitHub
parent cbb80a0d44
commit b08ab8dfb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 55 additions and 5 deletions

View File

@ -159,6 +159,8 @@ var (
"sortby", "sortby",
"timefmt", "timefmt",
"tempmarks", "tempmarks",
"infotimefmtnew",
"infotimefmtold",
"truncatechar", "truncatechar",
} }
) )

10
doc.go
View File

@ -140,6 +140,8 @@ The following options can be used to customize the behavior of lf:
tabstop int (default 8) tabstop int (default 8)
tempmarks string (default '') tempmarks string (default '')
timefmt string (default 'Mon Jan _2 15:04:05 2006') 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 '~') truncatechar string (default '~')
waitmsg string (default 'Press any key to continue') waitmsg string (default 'Press any key to continue')
wrapscan bool (default on) 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. 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 '~') truncatechar string (default '~')
Truncate character shown at the end when the file name does not fit to the pane. Truncate character shown at the end when the file name does not fit to the pane.

View File

@ -144,6 +144,8 @@ The following options can be used to customize the behavior of lf:
tabstop int (default 8) tabstop int (default 8)
tempmarks string (default '') tempmarks string (default '')
timefmt string (default 'Mon Jan _2 15:04:05 2006') 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 '~') truncatechar string (default '~')
waitmsg string (default 'Press any key to continue') waitmsg string (default 'Press any key to continue')
wrapscan bool (default on) 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. 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 '~') truncatechar string (default '~')
Truncate character shown at the end when the file name does not fit to the Truncate character shown at the end when the file name does not fit to the

View File

@ -418,6 +418,12 @@ func (e *setExpr) eval(app *app, args []string) {
} }
case "timefmt": case "timefmt":
gOpts.timefmt = e.val 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": case "truncatechar":
if runeSliceWidth([]rune(e.val)) != 1 { if runeSliceWidth([]rune(e.val)) != 1 {
app.ui.echoerr("truncatechar: value should be a single character") app.ui.echoerr("truncatechar: value should be a single character")

14
lf.1
View File

@ -160,6 +160,8 @@ The following options can be used to customize the behavior of lf:
tabstop int (default 8) tabstop int (default 8)
tempmarks string (default '') tempmarks string (default '')
timefmt string (default 'Mon Jan _2 15:04:05 2006') 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 '~') truncatechar string (default '~')
waitmsg string (default 'Press any key to continue') waitmsg string (default 'Press any key to continue')
wrapscan bool (default on) 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 .PP
Format string of the file modification time shown in the bottom line. Format string of the file modification time shown in the bottom line.
.PP .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 .EX
truncatechar string (default '~') truncatechar string (default '~')
.EE .EE

View File

@ -62,6 +62,8 @@ var gOpts struct {
shell string shell string
shellflag string shellflag string
timefmt string timefmt string
infotimefmtnew string
infotimefmtold string
truncatechar string truncatechar string
ratios []int ratios []int
hiddenfiles []string hiddenfiles []string
@ -74,6 +76,8 @@ var gOpts struct {
tempmarks string tempmarks string
} }
var gInfotimefmtMaxLen = 12
func init() { func init() {
gOpts.anchorfind = true gOpts.anchorfind = true
gOpts.autoquit = false gOpts.autoquit = false
@ -109,6 +113,8 @@ func init() {
gOpts.shell = gDefaultShell gOpts.shell = gDefaultShell
gOpts.shellflag = gDefaultShellFlag gOpts.shellflag = gDefaultShellFlag
gOpts.timefmt = time.ANSIC gOpts.timefmt = time.ANSIC
gOpts.infotimefmtnew = "Jan _2 15:04"
gOpts.infotimefmtold = "Jan _2 2006"
gOpts.truncatechar = "~" gOpts.truncatechar = "~"
gOpts.ratios = []int{1, 2, 3} gOpts.ratios = []int{1, 2, 3}
gOpts.hiddenfiles = []string{".*"} gOpts.hiddenfiles = []string{".*"}

10
ui.go
View File

@ -279,9 +279,9 @@ var gThisYear = time.Now().Year()
func infotimefmt(t time.Time) string { func infotimefmt(t time.Time) string {
if t.Year() == gThisYear { 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 { func fileInfo(f *file, d *dir) string {
@ -328,11 +328,11 @@ func fileInfo(f *file, d *dir) string {
info = fmt.Sprintf("%s 999+", info) info = fmt.Sprintf("%s 999+", info)
} }
case "time": 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": 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": case "ctime":
info = fmt.Sprintf("%s %12s", info, infotimefmt(f.changeTime)) info = fmt.Sprintf(fmt.Sprint("%"+"s %", gInfotimefmtMaxLen, "s"), info, infotimefmt(f.changeTime))
default: default:
log.Printf("unknown info type: %s", s) log.Printf("unknown info type: %s", s)
} }