Clear error messages after a command runs successfully (#2117)

* Draw stat info on demand

* Remove loadfileinfo function

* Fix clearmsg bug when opening directories

* Move visual code
This commit is contained in:
Joe Lim authored and GitHub committed 2025-08-26 17:48:15 +10:00
1 parent 8f97bf806a
commit 8150586bc2
3 files changed
+119 -160

No files matched your search

-7
View File
@@ -420,9 +420,6 @@ func (app *app) loop() {
if err == nil { if err == nil {
if curr.path != oldCurrPath { if curr.path != oldCurrPath {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
if app.ui.msgIsStat {
app.ui.loadFileInfo(app.nav)
}
} }
if d.path == curr.path { if d.path == curr.path {
app.ui.dirPrev = d app.ui.dirPrev = d
@@ -469,10 +466,6 @@ func (app *app) loop() {
} }
app.ui.loadFile(app, false) app.ui.loadFile(app, false)
if app.ui.msgIsStat {
app.ui.loadFileInfo(app.nav)
}
onLoad(app, []string{f.path}) onLoad(app, []string{f.path})
app.ui.draw(app.nav) app.ui.draw(app.nav)
case path := <-app.nav.delChan: case path := <-app.nav.delChan:
+68 -97
View File
@@ -446,7 +446,7 @@ func (e *setExpr) eval(app *app, args []string) {
return return
} }
app.ui.loadFileInfo(app.nav) app.ui.echo("")
} }
func (e *setLocalExpr) eval(app *app, args []string) { func (e *setLocalExpr) eval(app *app, args []string) {
@@ -521,7 +521,7 @@ func (e *setLocalExpr) eval(app *app, args []string) {
return return
} }
app.ui.loadFileInfo(app.nav) app.ui.echo("")
} }
func (e *mapExpr) eval(app *app, args []string) { func (e *mapExpr) eval(app *app, args []string) {
@@ -532,7 +532,7 @@ func (e *mapExpr) eval(app *app, args []string) {
gOpts.nkeys[e.keys] = e.expr gOpts.nkeys[e.keys] = e.expr
gOpts.vkeys[e.keys] = e.expr gOpts.vkeys[e.keys] = e.expr
} }
app.ui.loadFileInfo(app.nav) app.ui.echo("")
} }
func (e *nmapExpr) eval(app *app, args []string) { func (e *nmapExpr) eval(app *app, args []string) {
@@ -541,7 +541,7 @@ func (e *nmapExpr) eval(app *app, args []string) {
} else { } else {
gOpts.nkeys[e.keys] = e.expr gOpts.nkeys[e.keys] = e.expr
} }
app.ui.loadFileInfo(app.nav) app.ui.echo("")
} }
func (e *vmapExpr) eval(app *app, args []string) { func (e *vmapExpr) eval(app *app, args []string) {
@@ -550,7 +550,7 @@ func (e *vmapExpr) eval(app *app, args []string) {
} else { } else {
gOpts.vkeys[e.keys] = e.expr gOpts.vkeys[e.keys] = e.expr
} }
app.ui.loadFileInfo(app.nav) app.ui.echo("")
} }
func (e *cmapExpr) eval(app *app, args []string) { func (e *cmapExpr) eval(app *app, args []string) {
@@ -559,7 +559,7 @@ func (e *cmapExpr) eval(app *app, args []string) {
} else { } else {
gOpts.cmdkeys[e.key] = e.expr gOpts.cmdkeys[e.key] = e.expr
} }
app.ui.loadFileInfo(app.nav) app.ui.echo("")
} }
func (e *cmdExpr) eval(app *app, args []string) { func (e *cmdExpr) eval(app *app, args []string) {
@@ -580,7 +580,7 @@ func (e *cmdExpr) eval(app *app, args []string) {
} }
} }
app.ui.loadFileInfo(app.nav) app.ui.echo("")
} }
func preChdir(app *app) { func preChdir(app *app) {
@@ -677,7 +677,6 @@ func update(app *app) {
app.ui.echoerrf("search: %s: %s", err, app.nav.search) app.ui.echoerrf("search: %s: %s", err, app.nav.search)
} else if old != dir.ind { } else if old != dir.ind {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case gOpts.incsearch && app.ui.cmdPrefix == "?": case gOpts.incsearch && app.ui.cmdPrefix == "?":
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight) app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
@@ -694,7 +693,6 @@ func update(app *app) {
app.ui.echoerrf("search: %s: %s", err, app.nav.search) app.ui.echoerrf("search: %s: %s", err, app.nav.search)
} else if old != dir.ind { } else if old != dir.ind {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case gOpts.incfilter && app.ui.cmdPrefix == "filter: ": case gOpts.incfilter && app.ui.cmdPrefix == "filter: ":
filter := string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight) filter := string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
@@ -705,7 +703,6 @@ func update(app *app) {
app.ui.echoerrf("filter: %s", err) app.ui.echoerrf("filter: %s", err)
} else if old != dir.ind { } else if old != dir.ind {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
} }
} }
@@ -730,7 +727,6 @@ func resetIncCmd(app *app) {
if dir.ind != app.nav.searchInd { if dir.ind != app.nav.searchInd {
dir.ind = app.nav.searchInd dir.ind = app.nav.searchInd
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
} else if gOpts.incfilter && app.ui.cmdPrefix == "filter: " { } else if gOpts.incfilter && app.ui.cmdPrefix == "filter: " {
dir := app.nav.currDir() dir := app.nav.currDir()
@@ -738,7 +734,6 @@ func resetIncCmd(app *app) {
app.nav.setFilter(app.nav.prevFilter) app.nav.setFilter(app.nav.prevFilter)
if old != dir.ind { if old != dir.ind {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
} }
} }
@@ -753,17 +748,6 @@ func normal(app *app) {
app.ui.cmdAccLeft = nil app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil app.ui.cmdAccRight = nil
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
// ensure the mode indicator in `statfmt` is updated properly
app.ui.loadFileInfo(app.nav)
}
func visual(app *app) {
dir := app.nav.currDir()
dir.visualAnchor = dir.ind
dir.visualWrap = 0
app.ui.loadFileInfo(app.nav)
} }
func insert(app *app, arg string) { func insert(app *app, arg string) {
@@ -783,7 +767,6 @@ func insert(app *app, arg string) {
app.ui.echoerrf("find: pattern not found: %s", app.nav.find) app.ui.echoerrf("find: pattern not found: %s", app.nav.find)
case 1: case 1:
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
default: default:
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
return return
@@ -798,7 +781,6 @@ func insert(app *app, arg string) {
app.ui.echoerrf("find: pattern not found: %s", app.nav.find) app.ui.echoerrf("find: pattern not found: %s", app.nav.find)
} else if moved { } else if moved {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
} }
@@ -812,7 +794,6 @@ func insert(app *app, arg string) {
app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find) app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find)
case 1: case 1:
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
default: default:
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
return return
@@ -827,7 +808,6 @@ func insert(app *app, arg string) {
app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find) app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find)
} else if moved { } else if moved {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
} }
@@ -842,7 +822,6 @@ func insert(app *app, arg string) {
} }
app.nav.unselect() app.nav.unselect()
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case strings.HasPrefix(app.ui.cmdPrefix, "replace"): case strings.HasPrefix(app.ui.cmdPrefix, "replace"):
normal(app) normal(app)
@@ -862,7 +841,6 @@ func insert(app *app, arg string) {
} }
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case strings.HasPrefix(app.ui.cmdPrefix, "create"): case strings.HasPrefix(app.ui.cmdPrefix, "create"):
normal(app) normal(app)
@@ -886,7 +864,6 @@ func insert(app *app, arg string) {
} }
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case app.ui.cmdPrefix == "mark-save: ": case app.ui.cmdPrefix == "mark-save: ":
normal(app) normal(app)
@@ -907,7 +884,6 @@ func insert(app *app, arg string) {
return return
} }
} }
app.ui.loadFileInfo(app.nav)
case app.ui.cmdPrefix == "mark-load: ": case app.ui.cmdPrefix == "mark-load: ":
normal(app) normal(app)
@@ -932,7 +908,6 @@ func insert(app *app, arg string) {
return return
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
if wd != path { if wd != path {
app.nav.marks["'"] = wd app.nav.marks["'"] = wd
@@ -960,7 +935,6 @@ func insert(app *app, arg string) {
return return
} }
} }
app.ui.loadFileInfo(app.nav)
case app.ui.cmdPrefix == ":" && len(app.ui.cmdAccLeft) == 0: case app.ui.cmdPrefix == ":" && len(app.ui.cmdAccLeft) == 0:
switch arg { switch arg {
case "!", "$", "%", "&": case "!", "$", "%", "&":
@@ -987,7 +961,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if app.nav.up(e.count) { if app.nav.up(e.count) {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "half-up": case "half-up":
if !app.nav.init { if !app.nav.init {
@@ -995,7 +968,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if app.nav.up(e.count * app.nav.height / 2) { if app.nav.up(e.count * app.nav.height / 2) {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "page-up": case "page-up":
if !app.nav.init { if !app.nav.init {
@@ -1003,7 +975,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if app.nav.up(e.count * app.nav.height) { if app.nav.up(e.count * app.nav.height) {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "scroll-up": case "scroll-up":
if !app.nav.init { if !app.nav.init {
@@ -1011,7 +982,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if app.nav.scrollUp(e.count) { if app.nav.scrollUp(e.count) {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "down": case "down":
if !app.nav.init { if !app.nav.init {
@@ -1019,7 +989,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if app.nav.down(e.count) { if app.nav.down(e.count) {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "half-down": case "half-down":
if !app.nav.init { if !app.nav.init {
@@ -1027,7 +996,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if app.nav.down(e.count * app.nav.height / 2) { if app.nav.down(e.count * app.nav.height / 2) {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "page-down": case "page-down":
if !app.nav.init { if !app.nav.init {
@@ -1035,7 +1003,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if app.nav.down(e.count * app.nav.height) { if app.nav.down(e.count * app.nav.height) {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "scroll-down": case "scroll-down":
if !app.nav.init { if !app.nav.init {
@@ -1043,7 +1010,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if app.nav.scrollDown(e.count) { if app.nav.scrollDown(e.count) {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "updir": case "updir":
if !app.nav.init { if !app.nav.init {
@@ -1058,7 +1024,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
restartIncCmd(app) restartIncCmd(app)
onChdir(app) onChdir(app)
case "open": case "open":
@@ -1080,22 +1045,18 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
restartIncCmd(app) restartIncCmd(app)
onChdir(app) onChdir(app)
return } else {
} if gSelectionPath != "" || gPrintSelection {
app.selectionOut, _ = app.nav.currFileOrSelections()
app.quitChan <- struct{}{}
return
}
if gSelectionPath != "" || gPrintSelection { if cmd, ok := gOpts.cmds["open"]; ok {
app.selectionOut, _ = app.nav.currFileOrSelections() cmd.eval(app, e.args)
app.quitChan <- struct{}{} }
return
}
app.ui.loadFileInfo(app.nav)
if cmd, ok := gOpts.cmds["open"]; ok {
cmd.eval(app, e.args)
} }
case "jump-next": case "jump-next":
resetIncCmd(app) resetIncCmd(app)
@@ -1104,7 +1065,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.cdJumpListNext() app.nav.cdJumpListNext()
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
restartIncCmd(app) restartIncCmd(app)
onChdir(app) onChdir(app)
case "jump-prev": case "jump-prev":
@@ -1114,7 +1074,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.cdJumpListPrev() app.nav.cdJumpListPrev()
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
restartIncCmd(app) restartIncCmd(app)
onChdir(app) onChdir(app)
case "top": case "top":
@@ -1129,7 +1088,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if moved { if moved {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "bottom": case "bottom":
if !app.nav.init { if !app.nav.init {
@@ -1145,7 +1103,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if moved { if moved {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "high": case "high":
if !app.nav.init { if !app.nav.init {
@@ -1153,7 +1110,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if app.nav.high() { if app.nav.high() {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "middle": case "middle":
if !app.nav.init { if !app.nav.init {
@@ -1161,7 +1117,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if app.nav.middle() { if app.nav.middle() {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "low": case "low":
if !app.nav.init { if !app.nav.init {
@@ -1169,7 +1124,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if app.nav.low() { if app.nav.low() {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "toggle": case "toggle":
if !app.nav.init { if !app.nav.init {
@@ -1243,7 +1197,6 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
} }
app.ui.loadFileInfo(app.nav)
case "cut": case "cut":
if !app.nav.init { if !app.nav.init {
return return
@@ -1265,7 +1218,6 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
} }
app.ui.loadFileInfo(app.nav)
case "paste": case "paste":
if !app.nav.init { if !app.nav.init {
return return
@@ -1278,7 +1230,6 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
case "clear": case "clear":
if !app.nav.init { if !app.nav.init {
return return
@@ -1298,7 +1249,6 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
} }
app.ui.loadFileInfo(app.nav)
case "sync": case "sync":
if err := app.nav.sync(); err != nil { if err := app.nav.sync(); err != nil {
app.ui.echoerrf("sync: %s", err) app.ui.echoerrf("sync: %s", err)
@@ -1334,7 +1284,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("reload: %s", err) app.ui.echoerrf("reload: %s", err)
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
case "delete": case "delete":
if !app.nav.init { if !app.nav.init {
return return
@@ -1369,7 +1318,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.cmdPrefix = "delete " + strconv.Itoa(len(list)) + " items? [y/N] " app.ui.cmdPrefix = "delete " + strconv.Itoa(len(list)) + " items? [y/N] "
} }
} }
app.ui.loadFileInfo(app.nav)
case "rename": case "rename":
if !app.nav.init { if !app.nav.init {
return return
@@ -1405,42 +1353,36 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.cmdAccRight = append(app.ui.cmdAccRight, []rune(extension)...) app.ui.cmdAccRight = append(app.ui.cmdAccRight, []rune(extension)...)
} }
} }
app.ui.loadFileInfo(app.nav)
case "read": case "read":
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
return return
} }
normal(app) normal(app)
app.ui.cmdPrefix = ":" app.ui.cmdPrefix = ":"
app.ui.loadFileInfo(app.nav)
case "shell": case "shell":
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
return return
} }
normal(app) normal(app)
app.ui.cmdPrefix = "$" app.ui.cmdPrefix = "$"
app.ui.loadFileInfo(app.nav)
case "shell-pipe": case "shell-pipe":
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
return return
} }
normal(app) normal(app)
app.ui.cmdPrefix = "%" app.ui.cmdPrefix = "%"
app.ui.loadFileInfo(app.nav)
case "shell-wait": case "shell-wait":
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
return return
} }
normal(app) normal(app)
app.ui.cmdPrefix = "!" app.ui.cmdPrefix = "!"
app.ui.loadFileInfo(app.nav)
case "shell-async": case "shell-async":
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
return return
} }
normal(app) normal(app)
app.ui.cmdPrefix = "&" app.ui.cmdPrefix = "&"
app.ui.loadFileInfo(app.nav)
case "find": case "find":
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
return return
@@ -1448,7 +1390,6 @@ func (e *callExpr) eval(app *app, args []string) {
normal(app) normal(app)
app.ui.cmdPrefix = "find: " app.ui.cmdPrefix = "find: "
app.nav.findBack = false app.nav.findBack = false
app.ui.loadFileInfo(app.nav)
case "find-back": case "find-back":
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
return return
@@ -1456,7 +1397,6 @@ func (e *callExpr) eval(app *app, args []string) {
normal(app) normal(app)
app.ui.cmdPrefix = "find-back: " app.ui.cmdPrefix = "find-back: "
app.nav.findBack = true app.nav.findBack = true
app.ui.loadFileInfo(app.nav)
case "find-next": case "find-next":
if !app.nav.init { if !app.nav.init {
return return
@@ -1472,7 +1412,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if old != dir.ind { if old != dir.ind {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "find-prev": case "find-prev":
if !app.nav.init { if !app.nav.init {
@@ -1489,7 +1428,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if old != dir.ind { if old != dir.ind {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "search": case "search":
if !app.nav.init { if !app.nav.init {
@@ -1504,7 +1442,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.searchInd = dir.ind app.nav.searchInd = dir.ind
app.nav.searchPos = dir.pos app.nav.searchPos = dir.pos
app.nav.searchBack = false app.nav.searchBack = false
app.ui.loadFileInfo(app.nav)
case "search-back": case "search-back":
if !app.nav.init { if !app.nav.init {
return return
@@ -1518,7 +1455,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.searchInd = dir.ind app.nav.searchInd = dir.ind
app.nav.searchPos = dir.pos app.nav.searchPos = dir.pos
app.nav.searchBack = true app.nav.searchBack = true
app.ui.loadFileInfo(app.nav)
case "search-next": case "search-next":
if !app.nav.init { if !app.nav.init {
return return
@@ -1529,14 +1465,12 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search) app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
} else if moved { } else if moved {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
} else { } else {
if moved, err := app.nav.searchNext(); err != nil { if moved, err := app.nav.searchNext(); err != nil {
app.ui.echoerrf("search: %s: %s", err, app.nav.search) app.ui.echoerrf("search: %s: %s", err, app.nav.search)
} else if moved { } else if moved {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
} }
} }
@@ -1550,14 +1484,12 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search) app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
} else if moved { } else if moved {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
} else { } else {
if moved, err := app.nav.searchPrev(); err != nil { if moved, err := app.nav.searchPrev(); err != nil {
app.ui.echoerrf("search: %s: %s", err, app.nav.search) app.ui.echoerrf("search: %s: %s", err, app.nav.search)
} else if moved { } else if moved {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
} }
} }
@@ -1577,7 +1509,6 @@ func (e *callExpr) eval(app *app, args []string) {
} else { } else {
app.ui.cmdAccLeft = []rune(strings.Join(e.args, " ")) app.ui.cmdAccLeft = []rune(strings.Join(e.args, " "))
} }
app.ui.loadFileInfo(app.nav)
case "setfilter": case "setfilter":
if !app.nav.init { if !app.nav.init {
return return
@@ -1587,7 +1518,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("filter: %s", err) app.ui.echoerrf("filter: %s", err)
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
case "mark-save": case "mark-save":
if app.ui.cmdPrefix == ">" { if app.ui.cmdPrefix == ">" {
return return
@@ -1693,7 +1623,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
if wd != path { if wd != path {
app.nav.marks["'"] = wd app.nav.marks["'"] = wd
@@ -1733,7 +1662,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
if wd != path { if wd != path {
app.nav.marks["'"] = wd app.nav.marks["'"] = wd
@@ -1746,7 +1674,6 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
app.readFile(replaceTilde(e.args[0])) app.readFile(replaceTilde(e.args[0]))
app.ui.loadFileInfo(app.nav)
case "push": case "push":
if len(e.args) != 1 { if len(e.args) != 1 {
app.ui.echoerr("push: requires an argument") app.ui.echoerr("push: requires an argument")
@@ -1812,7 +1739,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("calcdirsize: %s", err) app.ui.echoerrf("calcdirsize: %s", err)
return return
} }
app.ui.loadFileInfo(app.nav)
app.nav.sort() app.nav.sort()
app.ui.sort() app.ui.sort()
case "clearmaps": case "clearmaps":
@@ -1838,7 +1764,9 @@ func (e *callExpr) eval(app *app, args []string) {
if !app.nav.init { if !app.nav.init {
return return
} }
visual(app) dir := app.nav.currDir()
dir.visualAnchor = dir.ind
dir.visualWrap = 0
case "visual-accept": case "visual-accept":
if !app.nav.init { if !app.nav.init {
return return
@@ -1963,7 +1891,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("search: %s: %s", err, app.nav.search) app.ui.echoerrf("search: %s: %s", err, app.nav.search)
} else if old != dir.ind { } else if old != dir.ind {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "?": case "?":
dir := app.nav.currDir() dir := app.nav.currDir()
@@ -1979,7 +1906,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search) app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
} else if old != dir.ind { } else if old != dir.ind {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "filter: ": case "filter: ":
log.Printf("filter: %s", s) log.Printf("filter: %s", s)
@@ -1988,14 +1914,12 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("filter: %s", err) app.ui.echoerrf("filter: %s", err)
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
case "find: ": case "find: ":
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
if moved, found := app.nav.findNext(); !found { if moved, found := app.nav.findNext(); !found {
app.ui.echoerrf("find: pattern not found: %s", app.nav.find) app.ui.echoerrf("find: pattern not found: %s", app.nav.find)
} else if moved { } else if moved {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "find-back: ": case "find-back: ":
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
@@ -2003,7 +1927,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find) app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find)
} else if moved { } else if moved {
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
} }
case "rename: ": case "rename: ":
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
@@ -2060,7 +1983,6 @@ func (e *callExpr) eval(app *app, args []string) {
} }
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
app.ui.loadFileInfo(app.nav)
default: default:
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix) log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
} }
@@ -2309,6 +2231,55 @@ func (e *callExpr) eval(app *app, args []string) {
} }
cmd.eval(app, e.args) cmd.eval(app, e.args)
} }
// commands that run silently or write messages shouldn't clear existing messages
keepMsgCmds := []string{
"addcustominfo",
"draw",
"echo",
"echoerr",
"echomsg",
"load",
"push",
"redraw",
"sync",
"tty-write",
"cmd-insert",
"cmd-escape",
"cmd-complete",
"cmd-menu-complete",
"cmd-menu-complete-back",
"cmd-menu-accept",
"cmd-enter",
"cmd-interrupt",
"cmd-history-next",
"cmd-history-prev",
"cmd-left",
"cmd-right",
"cmd-home",
"cmd-end",
"cmd-delete",
"cmd-delete-back",
"cmd-delete-home",
"cmd-delete-end",
"cmd-delete-unix-word",
"cmd-yank",
"cmd-transpose",
"cmd-transpose-word",
"cmd-word",
"cmd-word-back",
"cmd-delete-word",
"cmd-delete-word-back",
"cmd-capitalize-word",
"cmd-uppercase-word",
"cmd-lowercase-word",
"on-focus-gained",
"on-focus-lost",
"on-init",
}
if !slices.Contains(keepMsgCmds, e.name) {
app.ui.echo("")
}
} }
func (e *execExpr) eval(app *app, args []string) { func (e *execExpr) eval(app *app, args []string) {
+51 -56
View File
@@ -648,7 +648,6 @@ type ui struct {
msgWin *win msgWin *win
menuWin *win menuWin *win
msg string msg string
msgIsStat bool
regPrev *reg regPrev *reg
dirPrev *dir dirPrev *dir
exprChan chan expr exprChan chan expr
@@ -678,7 +677,6 @@ func newUI(screen tcell.Screen) *ui {
promptWin: newWin(wtot, 1, 0, 0), promptWin: newWin(wtot, 1, 0, 0),
msgWin: newWin(wtot, 1, 0, htot-1), msgWin: newWin(wtot, 1, 0, htot-1),
menuWin: newWin(wtot, 1, 0, htot-2), menuWin: newWin(wtot, 1, 0, htot-2),
msgIsStat: true,
exprChan: make(chan expr, 1000), exprChan: make(chan expr, 1000),
keyChan: make(chan string, 1000), keyChan: make(chan string, 1000),
tevChan: make(chan tcell.Event, 1000), tevChan: make(chan tcell.Event, 1000),
@@ -736,7 +734,6 @@ func (ui *ui) sort() {
func (ui *ui) echo(msg string) { func (ui *ui) echo(msg string) {
ui.msg = msg ui.msg = msg
ui.msgIsStat = false
} }
func (ui *ui) echomsg(msg string) { func (ui *ui) echomsg(msg string) {
@@ -795,57 +792,6 @@ func (ui *ui) loadFile(app *app, volatile bool) {
} }
} }
func (ui *ui) loadFileInfo(nav *nav) {
if !nav.init {
return
}
ui.msg = ""
ui.msgIsStat = true
curr, err := nav.currFile()
if err != nil {
return
}
if curr.err != nil {
ui.echoerrf("stat: %s", curr.err)
return
}
statfmt := strings.ReplaceAll(gOpts.statfmt, "|", "\x1f")
replace := func(s string, val string) {
if val == "" {
val = "\x00"
}
statfmt = strings.ReplaceAll(statfmt, s, val)
}
if nav.isVisualMode() {
replace("%m", "VISUAL")
replace("%M", "VISUAL")
} else {
replace("%m", "")
replace("%M", "NORMAL")
}
replace("%p", curr.Mode().String())
replace("%c", linkCount(curr))
replace("%u", userName(curr))
replace("%g", groupName(curr))
replace("%s", humanize(uint64(curr.Size())))
replace("%S", fmt.Sprintf("%5s", humanize(uint64(curr.Size()))))
replace("%t", curr.ModTime().Format(gOpts.timefmt))
replace("%l", curr.linkTarget)
var fileInfo strings.Builder
for _, section := range strings.Split(statfmt, "\x1f") {
if !strings.Contains(section, "\x00") {
fileInfo.WriteString(section)
}
}
ui.msg = fileInfo.String()
}
func (ui *ui) drawPromptLine(nav *nav) { func (ui *ui) drawPromptLine(nav *nav) {
st := tcell.StyleDefault st := tcell.StyleDefault
@@ -919,13 +865,61 @@ func formatRulerOpt(name string, val string) string {
return val return val
} }
func (ui *ui) drawStat(nav *nav) {
if ui.msg != "" {
ui.msgWin.print(ui.screen, 0, 0, tcell.StyleDefault, ui.msg)
return
}
curr, err := nav.currFile()
if err != nil {
return
}
if curr.err != nil {
ui.echoerrf("stat: %s", curr.err)
ui.msgWin.print(ui.screen, 0, 0, tcell.StyleDefault, ui.msg)
return
}
statfmt := strings.ReplaceAll(gOpts.statfmt, "|", "\x1f")
replace := func(s string, val string) {
if val == "" {
val = "\x00"
}
statfmt = strings.ReplaceAll(statfmt, s, val)
}
if nav.isVisualMode() {
replace("%m", "VISUAL")
replace("%M", "VISUAL")
} else {
replace("%m", "")
replace("%M", "NORMAL")
}
replace("%p", curr.Mode().String())
replace("%c", linkCount(curr))
replace("%u", userName(curr))
replace("%g", groupName(curr))
replace("%s", humanize(uint64(curr.Size())))
replace("%S", fmt.Sprintf("%5s", humanize(uint64(curr.Size()))))
replace("%t", curr.ModTime().Format(gOpts.timefmt))
replace("%l", curr.linkTarget)
var fileInfo strings.Builder
for _, section := range strings.Split(statfmt, "\x1f") {
if !strings.Contains(section, "\x00") {
fileInfo.WriteString(section)
}
}
ui.msgWin.print(ui.screen, 0, 0, tcell.StyleDefault, fileInfo.String())
}
func (ui *ui) drawRuler(nav *nav) { func (ui *ui) drawRuler(nav *nav) {
st := tcell.StyleDefault st := tcell.StyleDefault
dir := nav.currDir() dir := nav.currDir()
ui.msgWin.print(ui.screen, 0, 0, st, ui.msg)
tot := len(dir.files) tot := len(dir.files)
ind := min(dir.ind+1, tot) ind := min(dir.ind+1, tot)
hid := len(dir.allFiles) - tot hid := len(dir.allFiles) - tot
@@ -1098,6 +1092,7 @@ func (ui *ui) draw(nav *nav) {
switch ui.cmdPrefix { switch ui.cmdPrefix {
case "": case "":
ui.drawStat(nav)
ui.drawRuler(nav) ui.drawRuler(nav)
ui.screen.HideCursor() ui.screen.HideCursor()
case ">": case ">":