implement dironly option (#669)

Co-authored-by: mtoohey31 <mtoohey31@users.noreply.github.com>
This commit is contained in:
Matthew Tooheyandmtoohey31 authored and GitHub committed 2021-07-31 16:10:25 +03:00
1 parent 8adbd2b9ef
commit 75eba115d2
7 files changed
+63

No files matched your search

+3
View File
@@ -79,6 +79,9 @@ var (
"dirfirst",
"nodirfirst",
"dirfirst!",
"dironly",
"nodironly",
"dironly!",
"drawbox",
"nodrawbox",
"drawbox!",
+5
View File
@@ -101,6 +101,7 @@ The following options can be used to customize the behavior of lf:
autoquit bool (default off)
dircounts bool (default off)
dirfirst bool (default on)
dironly bool (default off)
drawbox bool (default off)
errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n")
@@ -512,6 +513,10 @@ A thousand items are counted per directory at most, and bigger directories are s
Show directories first above regular files.
dironly bool (default off)
Show only directories.
drawbox bool (default off)
Draw boxes around panes with box drawing characters.
+5
View File
@@ -105,6 +105,7 @@ The following options can be used to customize the behavior of lf:
autoquit bool (default off)
dircounts bool (default off)
dirfirst bool (default on)
dironly bool (default off)
drawbox bool (default off)
errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n")
@@ -541,6 +542,10 @@ directories are shown as '999+'.
Show directories first above regular files.
dironly bool (default off)
Show only directories.
drawbox bool (default off)
Draw boxes around panes with box drawing characters.
+18
View File
@@ -32,6 +32,24 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.dircounts = false
case "dircounts!":
gOpts.dircounts = !gOpts.dircounts
case "dironly":
gOpts.dironly = true
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "nodironly":
gOpts.dironly = false
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "dironly!":
gOpts.dironly = !gOpts.dironly
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav, true)
case "dirfirst":
gOpts.sortType.option |= dirfirstSort
app.nav.sort()
+7
View File
@@ -120,6 +120,7 @@ The following options can be used to customize the behavior of lf:
autoquit bool (default off)
dircounts bool (default off)
dirfirst bool (default on)
dironly bool (default off)
drawbox bool (default off)
errorfmt string (default "\e033[7;31;47m%s\e033[0m")
filesep string (default "\en")
@@ -636,6 +637,12 @@ When this option is enabled, directory sizes show the number of items inside ins
.PP
Show directories first above regular files.
.PP
.EX
dironly bool (default off)
.EE
.PP
Show only directories.
.PP
.EX
drawbox bool (default off)
.EE
+23
View File
@@ -113,6 +113,7 @@ type dir struct {
files []*file // displayed files in directory including or excluding hidden ones
allFiles []*file // all files in directory including hidden ones (same array as files)
sortType sortType // sort method and options from last sort
dironly bool // dironly value from last sort
hiddenfiles []string // hiddenfiles value from last sort
ignorecase bool // ignorecase value from last sort
ignoredia bool // ignoredia value from last sort
@@ -150,6 +151,7 @@ func normalize(s1, s2 string, ignorecase, ignoredia bool) (string, string) {
func (dir *dir) sort() {
dir.sortType = gOpts.sortType
dir.dironly = gOpts.dironly
dir.hiddenfiles = gOpts.hiddenfiles
dir.ignorecase = gOpts.ignorecase
dir.ignoredia = gOpts.ignoredia
@@ -219,6 +221,26 @@ func (dir *dir) sort() {
})
}
// when dironly option is enabled, we move files to the beginning of our file
// list and then set the beginning of displayed files to the first directory
// in the list
if dir.dironly {
sort.SliceStable(dir.files, func(i, j int) bool {
if !dir.files[i].IsDir() && !dir.files[j].IsDir() {
return i < j
}
return !dir.files[i].IsDir()
})
dir.files = func() []*file {
for i, f := range dir.files {
if f.IsDir() {
return dir.files[i:]
}
}
return dir.files[len(dir.files):]
}()
}
// when hidden option is disabled, we move hidden files to the
// beginning of our file list and then set the beginning of displayed
// files to the first non-hidden file in the list
@@ -362,6 +384,7 @@ func (nav *nav) checkDir(dir *dir) {
nav.dirChan <- nd
}()
case dir.sortType != gOpts.sortType ||
dir.dironly != gOpts.dironly ||
!reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles) ||
dir.ignorecase != gOpts.ignorecase ||
dir.ignoredia != gOpts.ignoredia:
+2
View File
@@ -31,6 +31,7 @@ var gOpts struct {
anchorfind bool
autoquit bool
dircounts bool
dironly bool
drawbox bool
globsearch bool
icons bool
@@ -74,6 +75,7 @@ func init() {
gOpts.anchorfind = true
gOpts.autoquit = false
gOpts.dircounts = false
gOpts.dironly = false
gOpts.drawbox = false
gOpts.globsearch = false
gOpts.icons = false