This commit is contained in:
Gokcehan 2022-03-19 17:39:04 +03:00
parent c712d304f2
commit 5927a506f4
6 changed files with 59 additions and 60 deletions

2
doc.go
View File

@ -438,7 +438,7 @@ Read a pattern to search for a file name match in the forward/backward direction
setfilter setfilter
Read a pattern to filter out and only view files matching the pattern. Read a pattern to filter out and only view files matching the pattern.
setfilter does the same but uses an argument to set the filter immediatly. setfilter does the same but uses an argument to set the filter immediately.
You can supply an argument to filter, in order to use that as the starting prompt. You can supply an argument to filter, in order to use that as the starting prompt.
(See also 'globsearch', 'incfilter', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options) (See also 'globsearch', 'incfilter', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options)

View File

@ -459,7 +459,7 @@ direction and jump to the next/previous match.
setfilter setfilter
Read a pattern to filter out and only view files matching the pattern. Read a pattern to filter out and only view files matching the pattern.
setfilter does the same but uses an argument to set the filter immediatly. setfilter does the same but uses an argument to set the filter immediately.
You can supply an argument to filter, in order to use that as the starting You can supply an argument to filter, in order to use that as the starting
prompt. prompt.

70
eval.go
View File

@ -793,7 +793,7 @@ func insert(app *app, arg string) {
func (e *callExpr) eval(app *app, args []string) { func (e *callExpr) eval(app *app, args []string) {
switch e.name { switch e.name {
case "up": case "up":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.nav.up(e.count) { if app.nav.up(e.count) {
@ -801,7 +801,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "half-up": case "half-up":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.nav.up(e.count * app.nav.height / 2) { if app.nav.up(e.count * app.nav.height / 2) {
@ -809,7 +809,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "page-up": case "page-up":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.nav.up(e.count * app.nav.height) { if app.nav.up(e.count * app.nav.height) {
@ -817,7 +817,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "scrollup": case "scrollup":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.nav.scrollup(e.count) { if app.nav.scrollup(e.count) {
@ -825,7 +825,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "down": case "down":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.nav.down(e.count) { if app.nav.down(e.count) {
@ -833,7 +833,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "half-down": case "half-down":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.nav.down(e.count * app.nav.height / 2) { if app.nav.down(e.count * app.nav.height / 2) {
@ -841,7 +841,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "page-down": case "page-down":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.nav.down(e.count * app.nav.height) { if app.nav.down(e.count * app.nav.height) {
@ -849,7 +849,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "scrolldown": case "scrolldown":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.nav.scrolldown(e.count) { if app.nav.scrolldown(e.count) {
@ -857,7 +857,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "updir": case "updir":
if (!app.nav.init) { if !app.nav.init {
return return
} }
resetIncCmd(app) resetIncCmd(app)
@ -873,7 +873,7 @@ func (e *callExpr) eval(app *app, args []string) {
restartIncCmd(app) restartIncCmd(app)
onChdir(app) onChdir(app)
case "open": case "open":
if (!app.nav.init) { if !app.nav.init {
return return
} }
curr, err := app.nav.currFile() curr, err := app.nav.currFile()
@ -948,7 +948,7 @@ func (e *callExpr) eval(app *app, args []string) {
case "quit": case "quit":
app.quitChan <- struct{}{} app.quitChan <- struct{}{}
case "top": case "top":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.nav.top() { if app.nav.top() {
@ -956,7 +956,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "bottom": case "bottom":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.nav.bottom() { if app.nav.bottom() {
@ -964,7 +964,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "toggle": case "toggle":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if len(e.args) == 0 { if len(e.args) == 0 {
@ -984,14 +984,14 @@ func (e *callExpr) eval(app *app, args []string) {
} }
} }
case "invert": case "invert":
if (!app.nav.init) { if !app.nav.init {
return return
} }
app.nav.invert() app.nav.invert()
case "unselect": case "unselect":
app.nav.unselect() app.nav.unselect()
case "calcdirsize": case "calcdirsize":
if (!app.nav.init) { if !app.nav.init {
return return
} }
err := app.nav.calcDirSize() err := app.nav.calcDirSize()
@ -1003,7 +1003,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.sort() app.nav.sort()
app.ui.sort() app.ui.sort()
case "copy": case "copy":
if (!app.nav.init) { if !app.nav.init {
return return
} }
@ -1025,7 +1025,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "cut": case "cut":
if (!app.nav.init) { if !app.nav.init {
return return
} }
@ -1047,7 +1047,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "paste": case "paste":
if (!app.nav.init) { if !app.nav.init {
return return
} }
@ -1060,7 +1060,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "delete": case "delete":
if (!app.nav.init) { if !app.nav.init {
return return
} }
@ -1096,7 +1096,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "clear": case "clear":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if err := saveFiles(nil, false); err != nil { if err := saveFiles(nil, false); err != nil {
@ -1117,7 +1117,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "draw": case "draw":
case "redraw": case "redraw":
if (!app.nav.init) { if !app.nav.init {
return return
} }
app.ui.renew() app.ui.renew()
@ -1128,13 +1128,13 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
case "load": case "load":
if (!app.nav.init) { if !app.nav.init {
return return
} }
app.nav.renew() app.nav.renew()
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
case "reload": case "reload":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if err := app.nav.reload(); err != nil { if err := app.nav.reload(); err != nil {
@ -1194,7 +1194,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.findBack = true app.nav.findBack = true
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "find-next": case "find-next":
if (!app.nav.init) { if !app.nav.init {
return return
} }
dir := app.nav.currDir() dir := app.nav.currDir()
@ -1211,7 +1211,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "find-prev": case "find-prev":
if (!app.nav.init) { if !app.nav.init {
return return
} }
dir := app.nav.currDir() dir := app.nav.currDir()
@ -1228,7 +1228,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "search": case "search":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
@ -1242,7 +1242,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.searchBack = false app.nav.searchBack = false
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "search-back": case "search-back":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
@ -1256,7 +1256,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.searchBack = true app.nav.searchBack = true
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "search-next": case "search-next":
if (!app.nav.init) { if !app.nav.init {
return return
} }
for i := 0; i < e.count; i++ { for i := 0; i < e.count; i++ {
@ -1277,7 +1277,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
} }
case "search-prev": case "search-prev":
if (!app.nav.init) { if !app.nav.init {
return return
} }
for i := 0; i < e.count; i++ { for i := 0; i < e.count; i++ {
@ -1298,7 +1298,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
} }
case "filter": case "filter":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
@ -1315,7 +1315,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "setfilter": case "setfilter":
if (!app.nav.init) { if !app.nav.init {
return return
} }
log.Printf("filter: %s", e.args) log.Printf("filter: %s", e.args)
@ -1345,7 +1345,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.menuBuf = listMarks(app.nav.marks) app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-remove: " app.ui.cmdPrefix = "mark-remove: "
case "rename": case "rename":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if cmd, ok := gOpts.cmds["rename"]; ok { if cmd, ok := gOpts.cmds["rename"]; ok {
@ -1421,7 +1421,7 @@ func (e *callExpr) eval(app *app, args []string) {
onChdir(app) onChdir(app)
} }
case "select": case "select":
if (!app.nav.init) { if !app.nav.init {
return return
} }
@ -1461,7 +1461,7 @@ func (e *callExpr) eval(app *app, args []string) {
onChdir(app) onChdir(app)
} }
case "glob-select": case "glob-select":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if len(e.args) != 1 { if len(e.args) != 1 {
@ -1473,7 +1473,7 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
case "glob-unselect": case "glob-unselect":
if (!app.nav.init) { if !app.nav.init {
return return
} }
if len(e.args) != 1 { if len(e.args) != 1 {

2
lf.1
View File

@ -543,7 +543,7 @@ Read a pattern to search for a file name match in the forward/backward direction
setfilter setfilter
.EE .EE
.PP .PP
Read a pattern to filter out and only view files matching the pattern. setfilter does the same but uses an argument to set the filter immediatly. You can supply an argument to filter, in order to use that as the starting prompt. Read a pattern to filter out and only view files matching the pattern. setfilter does the same but uses an argument to set the filter immediately. You can supply an argument to filter, in order to use that as the starting prompt.
.PP .PP
(See also 'globsearch', 'incfilter', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options) (See also 'globsearch', 'incfilter', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options)
.PP .PP

39
nav.go
View File

@ -401,9 +401,8 @@ func (nav *nav) loadDir(path string) *dir {
nav.checkDir(d) nav.checkDir(d)
return d return d
} else {
return nav.loadDirInternal(path)
} }
return nav.loadDirInternal(path)
} }
func (nav *nav) checkDir(dir *dir) { func (nav *nav) checkDir(dir *dir) {
@ -554,7 +553,7 @@ func (nav *nav) reload() error {
} }
func (nav *nav) position() { func (nav *nav) position() {
if (!nav.init) { if !nav.init {
return return
} }
@ -566,7 +565,7 @@ func (nav *nav) position() {
} }
func (nav *nav) exportFiles() { func (nav *nav) exportFiles() {
if (!nav.init) { if !nav.init {
return return
} }
@ -1598,7 +1597,6 @@ func (nav *nav) currFileOrSelections() (list []string, err error) {
} }
func (nav *nav) calcDirSize() error { func (nav *nav) calcDirSize() error {
calc := func(f *file) error { calc := func(f *file) error {
if f.IsDir() { if f.IsDir() {
total, err := copySize([]string{f.path}) total, err := copySize([]string{f.path})
@ -1616,25 +1614,26 @@ func (nav *nav) calcDirSize() error {
return errors.New("no file selected") return errors.New("no file selected")
} }
return calc(curr) return calc(curr)
} else { }
for sel, _ := range nav.selections {
lstat, err := os.Lstat(sel)
if err != nil || !lstat.IsDir() {
continue
}
path, name := filepath.Dir(sel), filepath.Base(sel)
dir := nav.loadDir(path)
for _, f := range dir.files { for sel := range nav.selections {
if f.Name() == name { lstat, err := os.Lstat(sel)
err := calc(f) if err != nil || !lstat.IsDir() {
if err != nil { continue
return err }
} path, name := filepath.Dir(sel), filepath.Base(sel)
break dir := nav.loadDir(path)
for _, f := range dir.files {
if f.Name() == name {
err := calc(f)
if err != nil {
return err
} }
break
} }
} }
} }
return nil return nil
} }

4
ui.go
View File

@ -641,7 +641,7 @@ type reg struct {
} }
func (ui *ui) loadFile(nav *nav, volatile bool) { func (ui *ui) loadFile(nav *nav, volatile bool) {
if (!nav.init) { if !nav.init {
return return
} }
@ -666,7 +666,7 @@ func (ui *ui) loadFile(nav *nav, volatile bool) {
} }
func (ui *ui) loadFileInfo(nav *nav) { func (ui *ui) loadFileInfo(nav *nav) {
if (!nav.init) { if !nav.init {
return return
} }