Don't redraw volatile previews on ticker period (#546)

This commit is contained in:
neeshy 2021-01-04 14:01:29 +00:00 committed by GitHub
parent d62dd9353f
commit b5f6f6edee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 49 deletions

6
app.go
View File

@ -303,7 +303,7 @@ func (app *app) loop() {
curr, err := app.nav.currFile() curr, err := app.nav.currFile()
if err == nil { if err == nil {
if d.path == app.nav.currDir().path { if d.path == app.nav.currDir().path {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
} }
if d.path == curr.path { if d.path == curr.path {
app.ui.dirPrev = d app.ui.dirPrev = d
@ -352,7 +352,7 @@ func (app *app) loop() {
app.ui.draw(app.nav) app.ui.draw(app.nav)
case <-app.ticker.C: case <-app.ticker.C:
app.nav.renew() app.nav.renew()
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, false)
app.ui.draw(app.nav) app.ui.draw(app.nav)
} }
} }
@ -438,7 +438,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
} }
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
switch prefix { switch prefix {
case "%": case "%":

82
eval.go
View File

@ -61,19 +61,19 @@ func (e *setExpr) eval(app *app, args []string) {
app.nav.sort() app.nav.sort()
app.nav.position() app.nav.position()
app.ui.sort() app.ui.sort()
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
case "nohidden": case "nohidden":
gOpts.sortType.option &= ^hiddenSort gOpts.sortType.option &= ^hiddenSort
app.nav.sort() app.nav.sort()
app.nav.position() app.nav.position()
app.ui.sort() app.ui.sort()
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
case "hidden!": case "hidden!":
gOpts.sortType.option ^= hiddenSort gOpts.sortType.option ^= hiddenSort
app.nav.sort() app.nav.sort()
app.nav.position() app.nav.position()
app.ui.sort() app.ui.sort()
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
case "icons": case "icons":
gOpts.icons = true gOpts.icons = true
case "noicons": case "noicons":
@ -243,7 +243,7 @@ func (e *setExpr) eval(app *app, args []string) {
app.nav.sort() app.nav.sort()
app.nav.position() app.nav.position()
app.ui.sort() app.ui.sort()
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
case "ifs": case "ifs":
gOpts.ifs = e.val gOpts.ifs = e.val
case "info": case "info":
@ -288,7 +288,7 @@ func (e *setExpr) eval(app *app, args []string) {
} }
gOpts.ratios = rats gOpts.ratios = rats
app.ui.wins = getWins(app.ui.screen) app.ui.wins = getWins(app.ui.screen)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
case "shell": case "shell":
gOpts.shell = e.val gOpts.shell = e.val
case "shellopts": case "shellopts":
@ -401,7 +401,7 @@ func update(app *app) {
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) 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)
@ -415,7 +415,7 @@ func update(app *app) {
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
} }
@ -443,7 +443,7 @@ func insert(app *app, arg string) {
case 0: case 0:
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.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) 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)...)
@ -458,7 +458,7 @@ func insert(app *app, arg string) {
if !app.nav.findNext() { if !app.nav.findNext() {
app.ui.echoerrf("find: pattern not found: %s", app.nav.find) app.ui.echoerrf("find: pattern not found: %s", app.nav.find)
} else { } else {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
} }
@ -472,7 +472,7 @@ func insert(app *app, arg string) {
case 0: case 0:
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.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) 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)...)
@ -487,7 +487,7 @@ func insert(app *app, arg string) {
if !app.nav.findPrev() { if !app.nav.findPrev() {
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 { } else {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
} }
@ -506,7 +506,7 @@ func insert(app *app, arg string) {
app.ui.echoerrf("delete: %s", err) app.ui.echoerrf("delete: %s", err)
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case strings.HasPrefix(app.ui.cmdPrefix, "replace"): case strings.HasPrefix(app.ui.cmdPrefix, "replace"):
@ -521,7 +521,7 @@ func insert(app *app, arg string) {
app.ui.echoerrf("rename: %s", err) app.ui.echoerrf("rename: %s", err)
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case strings.HasPrefix(app.ui.cmdPrefix, "create"): case strings.HasPrefix(app.ui.cmdPrefix, "create"):
@ -540,7 +540,7 @@ func insert(app *app, arg string) {
app.ui.echoerrf("rename: %s", err) app.ui.echoerrf("rename: %s", err)
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case app.ui.cmdPrefix == "mark-save: ": case app.ui.cmdPrefix == "mark-save: ":
@ -575,7 +575,7 @@ func insert(app *app, arg string) {
app.ui.echoerrf("%s", err) app.ui.echoerrf("%s", err)
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
if wd != path { if wd != path {
@ -607,42 +607,42 @@ func (e *callExpr) eval(app *app, args []string) {
normal(app) normal(app)
} }
app.nav.up(e.count) app.nav.up(e.count)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "half-up": case "half-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" { if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app) normal(app)
} }
app.nav.up(e.count * app.nav.height / 2) app.nav.up(e.count * app.nav.height / 2)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "page-up": case "page-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" { if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app) normal(app)
} }
app.nav.up(e.count * app.nav.height) app.nav.up(e.count * app.nav.height)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "down": case "down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" { if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app) normal(app)
} }
app.nav.down(e.count) app.nav.down(e.count)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "half-down": case "half-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" { if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app) normal(app)
} }
app.nav.down(e.count * app.nav.height / 2) app.nav.down(e.count * app.nav.height / 2)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "page-down": case "page-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" { if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app) normal(app)
} }
app.nav.down(e.count * app.nav.height) app.nav.down(e.count * app.nav.height)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "updir": case "updir":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" { if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
@ -654,7 +654,7 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
onChdir(app) onChdir(app)
case "open": case "open":
@ -673,7 +673,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("opening directory: %s", err) app.ui.echoerrf("opening directory: %s", err)
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
onChdir(app) onChdir(app)
return return
@ -711,11 +711,11 @@ func (e *callExpr) eval(app *app, args []string) {
app.quitChan <- struct{}{} app.quitChan <- struct{}{}
case "top": case "top":
app.nav.top() app.nav.top()
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "bottom": case "bottom":
app.nav.bottom() app.nav.bottom()
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "toggle": case "toggle":
if len(e.args) == 0 { if len(e.args) == 0 {
@ -766,7 +766,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("paste: %s", err) app.ui.echoerrf("paste: %s", err)
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "delete": case "delete":
if cmd, ok := gOpts.cmds["delete"]; ok { if cmd, ok := gOpts.cmds["delete"]; ok {
@ -789,7 +789,7 @@ 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.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "clear": case "clear":
if err := saveFiles(nil, false); err != nil { if err := saveFiles(nil, false); err != nil {
@ -806,15 +806,15 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.renew() app.ui.renew()
app.ui.screen.Sync() app.ui.screen.Sync()
app.nav.height = app.ui.wins[0].h app.nav.height = app.ui.wins[0].h
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
case "load": case "load":
app.nav.renew() app.nav.renew()
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
case "reload": case "reload":
if err := app.nav.reload(); err != nil { if err := app.nav.reload(); err != nil {
app.ui.echoerrf("reload: %s", err) app.ui.echoerrf("reload: %s", err)
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "read": case "read":
app.ui.cmdPrefix = ":" app.ui.cmdPrefix = ":"
@ -847,7 +847,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.findNext() app.nav.findNext()
} }
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "find-prev": case "find-prev":
for i := 0; i < e.count; i++ { for i := 0; i < e.count; i++ {
@ -857,7 +857,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.findPrev() app.nav.findPrev()
} }
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "search": case "search":
app.ui.cmdPrefix = "/" app.ui.cmdPrefix = "/"
@ -887,7 +887,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
} }
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "search-prev": case "search-prev":
for i := 0; i < e.count; i++ { for i := 0; i < e.count; i++ {
@ -903,7 +903,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
} }
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "mark-save": case "mark-save":
app.ui.cmdPrefix = "mark-save: " app.ui.cmdPrefix = "mark-save: "
@ -929,7 +929,7 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.cmdPrefix = "rename: " app.ui.cmdPrefix = "rename: "
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...)
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "sync": case "sync":
if err := app.nav.sync(); err != nil { if err := app.nav.sync(); err != nil {
@ -957,7 +957,7 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
if !filepath.IsAbs(path) { if !filepath.IsAbs(path) {
@ -986,7 +986,7 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
path := filepath.Dir(e.args[0]) path := filepath.Dir(e.args[0])
@ -1056,7 +1056,7 @@ func (e *callExpr) eval(app *app, args []string) {
dir.ind = app.nav.searchInd dir.ind = app.nav.searchInd
dir.pos = app.nav.searchPos dir.pos = app.nav.searchPos
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
normal(app) normal(app)
@ -1232,7 +1232,7 @@ func (e *callExpr) eval(app *app, args []string) {
if err := app.nav.searchNext(); err != nil { if 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 { } else {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "?": case "?":
@ -1247,7 +1247,7 @@ func (e *callExpr) eval(app *app, args []string) {
if err := app.nav.searchPrev(); err != nil { if err := app.nav.searchPrev(); err != nil {
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search) app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
} else { } else {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case "rename: ": case "rename: ":
@ -1302,7 +1302,7 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
default: default:

4
nav.go
View File

@ -548,9 +548,9 @@ func (nav *nav) preview(path string, win *win) {
} }
} }
func (nav *nav) loadReg(path string) *reg { func (nav *nav) loadReg(path string, volatile bool) *reg {
r, ok := nav.regCache[path] r, ok := nav.regCache[path]
if !ok || r.volatile { if !ok || (volatile && r.volatile) {
r := &reg{loading: true, loadTime: time.Now(), path: path, volatile: true} r := &reg{loading: true, loadTime: time.Now(), path: path, volatile: true}
nav.regCache[path] = r nav.regCache[path] = r
nav.previewChan <- path nav.previewChan <- path

9
ui.go
View File

@ -618,7 +618,7 @@ type reg struct {
lines []string lines []string
} }
func (ui *ui) loadFile(nav *nav) { func (ui *ui) loadFile(nav *nav, volatile bool) {
curr, err := nav.currFile() curr, err := nav.currFile()
if err != nil { if err != nil {
return return
@ -628,11 +628,14 @@ func (ui *ui) loadFile(nav *nav) {
return return
} }
nav.previewChan <- "" if volatile {
nav.previewChan <- ""
}
if curr.IsDir() { if curr.IsDir() {
ui.dirPrev = nav.loadDir(curr.path) ui.dirPrev = nav.loadDir(curr.path)
} else if curr.Mode().IsRegular() { } else if curr.Mode().IsRegular() {
ui.regPrev = nav.loadReg(curr.path) ui.regPrev = nav.loadReg(curr.path, volatile)
} }
} }