Skip to content

Commit

Permalink
Continue PR: configure time format in the info column (#751)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
laktak and maicher authored Feb 12, 2022
1 parent cbb80a0 commit b08ab8d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 5 deletions.
2 changes: 2 additions & 0 deletions complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ var (
"sortby",
"timefmt",
"tempmarks",
"infotimefmtnew",
"infotimefmtold",
"truncatechar",
}
)
Expand Down
10 changes: 10 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions docstring.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 14 additions & 0 deletions lf.1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ var gOpts struct {
shell string
shellflag string
timefmt string
infotimefmtnew string
infotimefmtold string
truncatechar string
ratios []int
hiddenfiles []string
Expand All @@ -74,6 +76,8 @@ var gOpts struct {
tempmarks string
}

var gInfotimefmtMaxLen = 12

func init() {
gOpts.anchorfind = true
gOpts.autoquit = false
Expand Down Expand Up @@ -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{".*"}
Expand Down
10 changes: 5 additions & 5 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit b08ab8d

Please sign in to comment.