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{ gOptWords = []string{
"dirfirst",
"nodirfirst",
"dirfirst!",
"hidden", "hidden",
"nohidden", "nohidden",
"hidden!", "hidden!",
"preview", "preview",
"nopreview", "nopreview",
"preview!", "preview!",
"dirfirst",
"nodirfirst",
"dirfirst!",
"scrolloff", "scrolloff",
"tabstop", "tabstop",
"ifs", "ifs",
@ -60,6 +60,7 @@ var (
"shell", "shell",
"showinfo", "showinfo",
"sortby", "sortby",
"timefmt",
"ratios", "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. The following options can be used to customize the behavior of lf.
dirfirst bool (default on)
hidden bool (default off) hidden bool (default off)
preview bool (default on) preview bool (default on)
dirfirst bool (default on)
scrolloff int (default 0) scrolloff int (default 0)
tabstop int (default 8) tabstop int (default 8)
ifs string (default "") (not exported if empty) 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") shell string (default "$SHELL")
showinfo string (default "none") showinfo string (default "none")
sortby string (default "name") sortby string (default "name")
timefmt string (default "Mon Jan _2 15:04:05 2006")
ratios string (default "1:2:3") ratios string (default "1:2:3")
The following variables are exported for shell commands. 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. The following options can be used to customize the behavior of lf.
dirfirst bool (default on)
hidden bool (default off) hidden bool (default off)
preview bool (default on) preview bool (default on)
dirfirst bool (default on)
scrolloff int (default 0) scrolloff int (default 0)
tabstop int (default 8) tabstop int (default 8)
ifs string (default "") (not exported if empty) 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") shell string (default "$SHELL")
showinfo string (default "none") showinfo string (default "none")
sortby string (default "name") sortby string (default "name")
timefmt string (default "Mon Jan _2 15:04:05 2006")
ratios string (default "1:2:3") ratios string (default "1:2:3")
The following variables are exported for shell commands. 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) { func (e *SetExpr) eval(app *App, args []string) {
switch e.opt { 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": case "hidden":
gOpts.hidden = true gOpts.hidden = true
app.nav.renew(app.nav.height) app.nav.renew(app.nav.height)
@ -26,15 +35,6 @@ func (e *SetExpr) eval(app *App, args []string) {
gOpts.preview = false gOpts.preview = false
case "preview!": case "preview!":
gOpts.preview = !gOpts.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": case "scrolloff":
n, err := strconv.Atoi(e.val) n, err := strconv.Atoi(e.val)
if err != nil { if err != nil {
@ -92,6 +92,8 @@ func (e *SetExpr) eval(app *App, args []string) {
} }
gOpts.sortby = e.val gOpts.sortby = e.val
app.nav.renew(app.nav.height) app.nav.renew(app.nav.height)
case "timefmt":
gOpts.timefmt = e.val
case "ratios": case "ratios":
toks := strings.Split(e.val, ":") toks := strings.Split(e.val, ":")
var rats []int var rats []int

View File

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

3
ui.go
View File

@ -13,7 +13,6 @@ import (
"strconv" "strconv"
"strings" "strings"
"text/tabwriter" "text/tabwriter"
"time"
"unicode/utf8" "unicode/utf8"
"github.com/nsf/termbox-go" "github.com/nsf/termbox-go"
@ -405,7 +404,7 @@ func (ui *UI) loadFile(nav *Nav) {
return 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 { if !gOpts.preview {
return return