add timefmt option for time format in status line

Mentioned in #41.
This commit is contained in:
Gokcehan 2016-11-21 23:13:33 +03:00
parent fdf8e9d480
commit c8202bbc7a
6 changed files with 26 additions and 18 deletions

View File

@ -44,15 +44,15 @@ var (
}
gOptWords = []string{
"dirfirst",
"nodirfirst",
"dirfirst!",
"hidden",
"nohidden",
"hidden!",
"preview",
"nopreview",
"preview!",
"dirfirst",
"nodirfirst",
"dirfirst!",
"scrolloff",
"tabstop",
"ifs",
@ -60,6 +60,7 @@ var (
"shell",
"showinfo",
"sortby",
"timefmt",
"ratios",
}
)

3
doc.go
View File

@ -45,9 +45,9 @@ The following commands are provided by lf without default keybindings.
The following options can be used to customize the behavior of lf.
dirfirst bool (default on)
hidden bool (default off)
preview bool (default on)
dirfirst bool (default on)
scrolloff int (default 0)
tabstop int (default 8)
ifs string (default "") (not exported if empty)
@ -55,6 +55,7 @@ The following options can be used to customize the behavior of lf.
shell string (default "$SHELL")
showinfo string (default "none")
sortby string (default "name")
timefmt string (default "Mon Jan _2 15:04:05 2006")
ratios string (default "1:2:3")
The following variables are exported for shell commands.

View File

@ -49,9 +49,9 @@ The following commands are provided by lf without default keybindings.
The following options can be used to customize the behavior of lf.
dirfirst bool (default on)
hidden bool (default off)
preview bool (default on)
dirfirst bool (default on)
scrolloff int (default 0)
tabstop int (default 8)
ifs string (default "") (not exported if empty)
@ -59,6 +59,7 @@ The following options can be used to customize the behavior of lf.
shell string (default "$SHELL")
showinfo string (default "none")
sortby string (default "name")
timefmt string (default "Mon Jan _2 15:04:05 2006")
ratios string (default "1:2:3")
The following variables are exported for shell commands.

20
eval.go
View File

@ -11,6 +11,15 @@ import (
func (e *SetExpr) eval(app *App, args []string) {
switch e.opt {
case "dirfirst":
gOpts.dirfirst = true
app.nav.renew(app.nav.height)
case "nodirfirst":
gOpts.dirfirst = false
app.nav.renew(app.nav.height)
case "dirfirst!":
gOpts.dirfirst = !gOpts.dirfirst
app.nav.renew(app.nav.height)
case "hidden":
gOpts.hidden = true
app.nav.renew(app.nav.height)
@ -26,15 +35,6 @@ func (e *SetExpr) eval(app *App, args []string) {
gOpts.preview = false
case "preview!":
gOpts.preview = !gOpts.preview
case "dirfirst":
gOpts.dirfirst = true
app.nav.renew(app.nav.height)
case "nodirfirst":
gOpts.dirfirst = false
app.nav.renew(app.nav.height)
case "dirfirst!":
gOpts.dirfirst = !gOpts.dirfirst
app.nav.renew(app.nav.height)
case "scrolloff":
n, err := strconv.Atoi(e.val)
if err != nil {
@ -92,6 +92,8 @@ func (e *SetExpr) eval(app *App, args []string) {
}
gOpts.sortby = e.val
app.nav.renew(app.nav.height)
case "timefmt":
gOpts.timefmt = e.val
case "ratios":
toks := strings.Split(e.val, ":")
var rats []int

View File

@ -1,6 +1,9 @@
package main
import "time"
var gOpts struct {
dirfirst bool
hidden bool
preview bool
scrolloff int
@ -10,13 +13,14 @@ var gOpts struct {
shell string
showinfo string
sortby string
dirfirst bool
timefmt string
ratios []int
keys map[string]Expr
cmds map[string]Expr
}
func init() {
gOpts.dirfirst = true
gOpts.hidden = false
gOpts.preview = true
gOpts.scrolloff = 0
@ -24,7 +28,7 @@ func init() {
gOpts.shell = envShell
gOpts.showinfo = "none"
gOpts.sortby = "name"
gOpts.dirfirst = true
gOpts.timefmt = time.ANSIC
gOpts.ratios = []int{1, 2, 3}
gOpts.keys = make(map[string]Expr)

3
ui.go
View File

@ -13,7 +13,6 @@ import (
"strconv"
"strings"
"text/tabwriter"
"time"
"unicode/utf8"
"github.com/nsf/termbox-go"
@ -405,7 +404,7 @@ func (ui *UI) loadFile(nav *Nav) {
return
}
ui.message = fmt.Sprintf("%v %v %v", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(time.ANSIC))
ui.message = fmt.Sprintf("%v %v %v", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(gOpts.timefmt))
if !gOpts.preview {
return