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", "ifs",
"previewer", "previewer",
"shell", "shell",
"showinfo",
"sortby", "sortby",
"timefmt", "timefmt",
"ratios", "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) ifs string (default "") (not exported if empty)
previewer string (default "") (not filtered if empty) previewer string (default "") (not filtered if empty)
shell string (default "/bin/sh") shell string (default "/bin/sh")
showinfo string (default "none")
sortby string (default "natural") sortby string (default "natural")
timefmt string (default "Mon Jan _2 15:04:05 2006") timefmt string (default "Mon Jan _2 15:04:05 2006")
ratios string (default "1:2:3") ratios string (default "1:2:3")
showinfo string (default "")
The following variables are exported for shell commands: 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) ifs string (default "") (not exported if empty)
previewer string (default "") (not filtered if empty) previewer string (default "") (not filtered if empty)
shell string (default "/bin/sh") shell string (default "/bin/sh")
showinfo string (default "none")
sortby string (default "natural") sortby string (default "natural")
timefmt string (default "Mon Jan _2 15:04:05 2006") timefmt string (default "Mon Jan _2 15:04:05 2006")
ratios string (default "1:2:3") ratios string (default "1:2:3")
showinfo string (default "")
The following variables are exported for shell commands: The following variables are exported for shell commands:

View File

@ -21,12 +21,13 @@ map zp set preview!
map zh set hidden! map zh set hidden!
# easily select what information to show # easily select what information to show
map zn set showinfo none map zn set showinfo
map zs set showinfo size map zs set showinfo size
map zt set showinfo time map zt set showinfo time
map za set showinfo size:time
# sort files and show the corresponding info # 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 ss :set sortby size; set showinfo size
map st :set sortby time; set showinfo time 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) gOpts.previewer = strings.Replace(e.val, "~", envHome, -1)
case "shell": case "shell":
gOpts.shell = e.val 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": case "sortby":
if e.val != "natural" && e.val != "name" && e.val != "size" && e.val != "time" { if e.val != "natural" && e.val != "name" && e.val != "size" && e.val != "time" {
msg := "sortby should either be 'natural', 'name', 'size' or '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 gOpts.ratios = rats
app.ui.wins = getWins() app.ui.wins = getWins()
app.ui.loadFile(app.nav) 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: default:
msg := fmt.Sprintf("unknown option: %s", e.opt) msg := fmt.Sprintf("unknown option: %s", e.opt)
app.ui.message = msg app.ui.message = msg

View File

@ -13,10 +13,10 @@ var gOpts struct {
ifs string ifs string
previewer string previewer string
shell string shell string
showinfo string
sortby string sortby string
timefmt string timefmt string
ratios []int ratios []int
showinfo []string
keys map[string]expr keys map[string]expr
cmds map[string]expr cmds map[string]expr
} }
@ -30,10 +30,10 @@ func init() {
gOpts.tabstop = 8 gOpts.tabstop = 8
gOpts.filesep = ":" gOpts.filesep = ":"
gOpts.shell = "/bin/sh" gOpts.shell = "/bin/sh"
gOpts.showinfo = "none"
gOpts.sortby = "natural" gOpts.sortby = "natural"
gOpts.timefmt = time.ANSIC gOpts.timefmt = time.ANSIC
gOpts.ratios = []int{1, 2, 3} gOpts.ratios = []int{1, 2, 3}
gOpts.showinfo = nil
gOpts.keys = make(map[string]expr) 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 { var info string
case "none":
break for _, s := range gOpts.showinfo {
case "size": switch s {
if win.w > 8 { case "size":
h := humanize(f.Size()) info = fmt.Sprintf("%s %4s", info, humanize(f.Size()))
s = runeSliceWidthRange(s, 0, win.w-3-len(h)) case "time":
s = append(s, ' ') info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
for _, r := range h { default:
s = append(s, r) log.Printf("unknown showinfo type: %s", s)
}
} }
case "time": }
if win.w > 24 {
t := f.ModTime().Format("Jan _2 15:04") if len(info) > 0 && win.w > 2*len(info) {
s = runeSliceWidthRange(s, 0, win.w-3-len(t)) s = runeSliceWidthRange(s, 0, win.w-2-len(info))
s = append(s, ' ') for _, r := range info {
for _, r := range t { s = append(s, r)
s = append(s, r)
}
} }
default:
log.Printf("unknown showinfo type: %s", gOpts.showinfo)
} }
// TODO: add a trailing '~' to the name if cut // TODO: add a trailing '~' to the name if cut