modify showinfo to handle multiple values

Mentioned in #39.
This commit is contained in:
Gokcehan 2017-02-04 21:28:03 +03:00
parent 6792ed86df
commit d605781d09
7 changed files with 35 additions and 36 deletions

View File

@ -65,10 +65,10 @@ var (
"ifs",
"previewer",
"shell",
"showinfo",
"sortby",
"timefmt",
"ratios",
"showinfo",
}
)

2
doc.go
View File

@ -58,10 +58,10 @@ The following options can be used to customize the behavior of lf:
ifs string (default "") (not exported if empty)
previewer string (default "") (not filtered if empty)
shell string (default "/bin/sh")
showinfo string (default "none")
sortby string (default "natural")
timefmt string (default "Mon Jan _2 15:04:05 2006")
ratios string (default "1:2:3")
showinfo string (default "")
The following variables are exported for shell commands:

View File

@ -62,10 +62,10 @@ The following options can be used to customize the behavior of lf:
ifs string (default "") (not exported if empty)
previewer string (default "") (not filtered if empty)
shell string (default "/bin/sh")
showinfo string (default "none")
sortby string (default "natural")
timefmt string (default "Mon Jan _2 15:04:05 2006")
ratios string (default "1:2:3")
showinfo string (default "")
The following variables are exported for shell commands:

View File

@ -21,12 +21,13 @@ map zp set preview!
map zh set hidden!
# easily select what information to show
map zn set showinfo none
map zn set showinfo
map zs set showinfo size
map zt set showinfo time
map za set showinfo size:time
# sort files and show the corresponding info
map sn :set sortby name; set showinfo none
map sn :set sortby name; set showinfo
map ss :set sortby size; set showinfo size
map st :set sortby time; set showinfo time

19
eval.go
View File

@ -86,14 +86,6 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.previewer = strings.Replace(e.val, "~", envHome, -1)
case "shell":
gOpts.shell = e.val
case "showinfo":
if e.val != "none" && e.val != "size" && e.val != "time" {
msg := "showinfo should either be 'none', 'size' or 'time'"
app.ui.message = msg
log.Print(msg)
return
}
gOpts.showinfo = e.val
case "sortby":
if e.val != "natural" && e.val != "name" && e.val != "size" && e.val != "time" {
msg := "sortby should either be 'natural', 'name', 'size' or 'time'"
@ -121,6 +113,17 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.ratios = rats
app.ui.wins = getWins()
app.ui.loadFile(app.nav)
case "showinfo":
toks := strings.Split(e.val, ":")
for _, s := range toks {
if s != "" && s != "size" && s != "time" {
msg := "showinfo should consist of 'size' or 'time' separated with colon"
app.ui.message = msg
log.Print(msg)
return
}
}
gOpts.showinfo = toks
default:
msg := fmt.Sprintf("unknown option: %s", e.opt)
app.ui.message = msg

View File

@ -13,10 +13,10 @@ var gOpts struct {
ifs string
previewer string
shell string
showinfo string
sortby string
timefmt string
ratios []int
showinfo []string
keys map[string]expr
cmds map[string]expr
}
@ -30,10 +30,10 @@ func init() {
gOpts.tabstop = 8
gOpts.filesep = ":"
gOpts.shell = "/bin/sh"
gOpts.showinfo = "none"
gOpts.sortby = "natural"
gOpts.timefmt = time.ANSIC
gOpts.ratios = []int{1, 2, 3}
gOpts.showinfo = nil
gOpts.keys = make(map[string]expr)

37
ui.go
View File

@ -286,29 +286,24 @@ func (win *win) printd(dir *dir, marks map[string]int, saves map[string]bool) {
}
}
switch gOpts.showinfo {
case "none":
break
case "size":
if win.w > 8 {
h := humanize(f.Size())
s = runeSliceWidthRange(s, 0, win.w-3-len(h))
s = append(s, ' ')
for _, r := range h {
s = append(s, r)
}
var info string
for _, s := range gOpts.showinfo {
switch s {
case "size":
info = fmt.Sprintf("%s %4s", info, humanize(f.Size()))
case "time":
info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
default:
log.Printf("unknown showinfo type: %s", s)
}
case "time":
if win.w > 24 {
t := f.ModTime().Format("Jan _2 15:04")
s = runeSliceWidthRange(s, 0, win.w-3-len(t))
s = append(s, ' ')
for _, r := range t {
s = append(s, r)
}
}
if len(info) > 0 && win.w > 2*len(info) {
s = runeSliceWidthRange(s, 0, win.w-2-len(info))
for _, r := range info {
s = append(s, r)
}
default:
log.Printf("unknown showinfo type: %s", gOpts.showinfo)
}
// TODO: add a trailing '~' to the name if cut