Add reverse option (#55)

This commit is contained in:
Karol Woźniak 2016-12-26 21:49:18 +01:00 committed by gokcehan
parent 79b874e147
commit 8be854d3ba
6 changed files with 22 additions and 0 deletions

View File

@ -56,6 +56,9 @@ var (
"preview",
"nopreview",
"preview!",
"reverse",
"noreverse",
"reverse!",
"scrolloff",
"tabstop",
"filesep",

1
doc.go
View File

@ -51,6 +51,7 @@ The following options can be used to customize the behavior of lf:
dirfirst bool (default on)
hidden bool (default off)
preview bool (default on)
reverse bool (default off)
scrolloff int (default 0)
tabstop int (default 8)
filesep string (default ":")

View File

@ -55,6 +55,7 @@ The following options can be used to customize the behavior of lf:
dirfirst bool (default on)
hidden bool (default off)
preview bool (default on)
reverse bool (default off)
scrolloff int (default 0)
tabstop int (default 8)
filesep string (default ":")

View File

@ -35,6 +35,15 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.preview = false
case "preview!":
gOpts.preview = !gOpts.preview
case "reverse":
gOpts.reverse = true
app.nav.renew(app.nav.height)
case "noreverse":
gOpts.reverse = false
app.nav.renew(app.nav.height)
case "reverse!":
gOpts.reverse = !gOpts.reverse
app.nav.renew(app.nav.height)
case "scrolloff":
n, err := strconv.Atoi(e.val)
if err != nil {

6
nav.go
View File

@ -66,6 +66,12 @@ func getFilesSorted(path string) []*file {
log.Printf("unknown sorting type: %s", gOpts.sortby)
}
if gOpts.reverse {
for i, j := 0, len(fi)-1; i < j; i, j = i+1, j-1 {
fi[i], fi[j] = fi[j], fi[i]
}
}
if gOpts.dirfirst {
sortFilesStable(fi, func(i, j int) bool {
if fi[i].IsDir() == fi[j].IsDir() {

View File

@ -6,6 +6,7 @@ var gOpts struct {
dirfirst bool
hidden bool
preview bool
reverse bool
scrolloff int
tabstop int
filesep string
@ -24,6 +25,7 @@ func init() {
gOpts.dirfirst = true
gOpts.hidden = false
gOpts.preview = true
gOpts.reverse = false
gOpts.scrolloff = 0
gOpts.tabstop = 8
gOpts.filesep = ":"