diff --git a/comp.go b/comp.go index 7c02fe6..a612e82 100644 --- a/comp.go +++ b/comp.go @@ -65,10 +65,10 @@ var ( "ifs", "previewer", "shell", - "showinfo", "sortby", "timefmt", "ratios", + "showinfo", } ) diff --git a/doc.go b/doc.go index 46b009a..913c1ec 100644 --- a/doc.go +++ b/doc.go @@ -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: diff --git a/docstring.go b/docstring.go index bea7bd3..1d128ac 100644 --- a/docstring.go +++ b/docstring.go @@ -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: diff --git a/etc/lfrc.example b/etc/lfrc.example index c91dc46..288d045 100644 --- a/etc/lfrc.example +++ b/etc/lfrc.example @@ -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 diff --git a/eval.go b/eval.go index 8dfadea..0defbcb 100644 --- a/eval.go +++ b/eval.go @@ -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 diff --git a/opts.go b/opts.go index 7a8a839..a7f8805 100644 --- a/opts.go +++ b/opts.go @@ -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) diff --git a/ui.go b/ui.go index 4d3afd6..5c7750b 100644 --- a/ui.go +++ b/ui.go @@ -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