feat: apply loading message delay for directories (#2410)
* refactor preview timer * add preview timer for directory * adjust times * typo * create constant for preview loading delay * Update `CHANGELOG.md`
This commit is contained in:
1 parent
6ec60cf9d8
commit
fd2babd72e
4 files changed
+25
-22
No files matched your search
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|||||||
- Emoji sequences containing Zero Width Joiner characters are now displayed as a single combined glyph (#2286).
|
- Emoji sequences containing Zero Width Joiner characters are now displayed as a single combined glyph (#2286).
|
||||||
- A new field `.All` is added to the `ruler` file to display the number of all files (i.e. visible + hidden) in the current working directory (#2376).
|
- A new field `.All` is added to the `ruler` file to display the number of all files (i.e. visible + hidden) in the current working directory (#2376).
|
||||||
- A new option `numbercursorfmt` is added to further customize the appearance of line numbers (#2395).
|
- A new option `numbercursorfmt` is added to further customize the appearance of line numbers (#2395).
|
||||||
|
- The `loading...` message delay of 100 milliseconds for file previews is now applied to directories as well (#2410).
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|||||||
- The `select` command can now select files immediately after creation as part of a script (#2377).
|
- The `select` command can now select files immediately after creation as part of a script (#2377).
|
||||||
- The `on-load` hook command now ignores `.git` directories to reduce flicker and repeated `on-load` triggers (#2382).
|
- The `on-load` hook command now ignores `.git` directories to reduce flicker and repeated `on-load` triggers (#2382).
|
||||||
- Preview messages like `empty` or `loading...` have their alignment improved (#2400).
|
- Preview messages like `empty` or `loading...` have their alignment improved (#2400).
|
||||||
|
- A bug where the `loading...` message was not displayed for volatile previews after the first time is now fixed (#2410).
|
||||||
|
|
||||||
## [r41](https://github.com/gokcehan/lf/releases/tag/r41)
|
## [r41](https://github.com/gokcehan/lf/releases/tag/r41)
|
||||||
|
|
||||||
|
|||||||
@@ -509,7 +509,6 @@ func (app *app) loop() {
|
|||||||
app.nav.renew()
|
app.nav.renew()
|
||||||
app.ui.loadFile(app, false)
|
app.ui.loadFile(app, false)
|
||||||
case <-app.nav.previewTimer.C:
|
case <-app.nav.previewTimer.C:
|
||||||
app.nav.previewLoading = true
|
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
case <-app.nav.preloadTimer.C:
|
case <-app.nav.preloadTimer.C:
|
||||||
app.nav.preload()
|
app.nav.preload()
|
||||||
|
|||||||
@@ -478,7 +478,6 @@ type nav struct {
|
|||||||
prevFilter []string
|
prevFilter []string
|
||||||
volatilePreview bool
|
volatilePreview bool
|
||||||
previewTimer *time.Timer
|
previewTimer *time.Timer
|
||||||
previewLoading bool
|
|
||||||
preloadTimer *time.Timer
|
preloadTimer *time.Timer
|
||||||
jumpList []string
|
jumpList []string
|
||||||
jumpListInd int
|
jumpListInd int
|
||||||
@@ -495,6 +494,7 @@ func (nav *nav) getDir(path string) *dir {
|
|||||||
|
|
||||||
d := &dir{
|
d := &dir{
|
||||||
loading: true,
|
loading: true,
|
||||||
|
loadTime: time.Now(),
|
||||||
path: path,
|
path: path,
|
||||||
sortby: getSortBy(path),
|
sortby: getSortBy(path),
|
||||||
dircounts: getDirCounts(path),
|
dircounts: getDirCounts(path),
|
||||||
@@ -855,7 +855,6 @@ func (nav *nav) preload() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.startPreview()
|
|
||||||
for i := nav.height / 2; i >= 1; i-- {
|
for i := nav.height / 2; i >= 1; i-- {
|
||||||
doPreload(dir.ind - i)
|
doPreload(dir.ind - i)
|
||||||
doPreload(dir.ind + i)
|
doPreload(dir.ind + i)
|
||||||
@@ -952,7 +951,6 @@ func (nav *nav) loadReg(path string, volatile bool) *reg {
|
|||||||
if !ok || (!gOpts.preload && r.loading) {
|
if !ok || (!gOpts.preload && r.loading) {
|
||||||
r = ®{loading: true, loadTime: time.Now(), path: path}
|
r = ®{loading: true, loadTime: time.Now(), path: path}
|
||||||
nav.regCache[path] = r
|
nav.regCache[path] = r
|
||||||
nav.startPreview()
|
|
||||||
if gOpts.preload {
|
if gOpts.preload {
|
||||||
select {
|
select {
|
||||||
case nav.preloadChan <- path:
|
case nav.preloadChan <- path:
|
||||||
@@ -965,7 +963,10 @@ func (nav *nav) loadReg(path string, volatile bool) *reg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if volatile && r.volatile {
|
if volatile && r.volatile {
|
||||||
nav.startPreview()
|
if !gOpts.preload {
|
||||||
|
r.loadTime = time.Now()
|
||||||
|
r.loading = true
|
||||||
|
}
|
||||||
nav.previewChan <- path
|
nav.previewChan <- path
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -989,17 +990,10 @@ func (nav *nav) checkReg(reg *reg) {
|
|||||||
|
|
||||||
if s.ModTime().After(reg.loadTime) {
|
if s.ModTime().After(reg.loadTime) {
|
||||||
reg.loadTime = now
|
reg.loadTime = now
|
||||||
nav.startPreview()
|
|
||||||
nav.previewChan <- reg.path
|
nav.previewChan <- reg.path
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) startPreview() {
|
|
||||||
nav.previewTimer.Stop()
|
|
||||||
nav.previewLoading = false
|
|
||||||
nav.previewTimer.Reset(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) sort() {
|
func (nav *nav) sort() {
|
||||||
for _, path := range nav.dirPaths {
|
for _, path := range nav.dirPaths {
|
||||||
dir := nav.getDir(path)
|
dir := nav.getDir(path)
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import (
|
|||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const previewLoadingDelay = 100 * time.Millisecond
|
||||||
|
|
||||||
type win struct {
|
type win struct {
|
||||||
w, h, x, y int
|
w, h, x, y int
|
||||||
}
|
}
|
||||||
@@ -121,11 +123,13 @@ func (win *win) printMsg(screen tcell.Screen, s string) {
|
|||||||
win.print(screen, pad, 0, st, s)
|
win.print(screen, pad, 0, st, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (win *win) printReg(screen tcell.Screen, reg *reg, previewLoading bool, sxs *sixelScreen) {
|
func (win *win) printReg(screen tcell.Screen, reg *reg, sxs *sixelScreen, previewTimer *time.Timer) {
|
||||||
switch {
|
switch {
|
||||||
case reg.loading:
|
case reg.loading:
|
||||||
if previewLoading {
|
if time.Since(reg.loadTime) > previewLoadingDelay {
|
||||||
win.printMsg(screen, "loading...")
|
win.printMsg(screen, "loading...")
|
||||||
|
} else {
|
||||||
|
previewTimer.Reset(previewLoadingDelay)
|
||||||
}
|
}
|
||||||
case reg.sixel:
|
case reg.sixel:
|
||||||
sxs.printSixel(win, screen, reg)
|
sxs.printSixel(win, screen, reg)
|
||||||
@@ -234,7 +238,7 @@ type dirStyle struct {
|
|||||||
role dirRole
|
role dirRole
|
||||||
}
|
}
|
||||||
|
|
||||||
func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirStyle) {
|
func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirStyle, previewTimer *time.Timer) {
|
||||||
if win.w < 5 || dir == nil {
|
if win.w < 5 || dir == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -242,12 +246,16 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
|
|||||||
fileslen := len(dir.files)
|
fileslen := len(dir.files)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
case dir.loading && fileslen == 0:
|
||||||
|
if time.Since(dir.loadTime) > previewLoadingDelay {
|
||||||
|
win.printMsg(ui.screen, "loading...")
|
||||||
|
} else {
|
||||||
|
previewTimer.Reset(previewLoadingDelay)
|
||||||
|
}
|
||||||
|
return
|
||||||
case dir.noPerm:
|
case dir.noPerm:
|
||||||
win.printMsg(ui.screen, "permission denied")
|
win.printMsg(ui.screen, "permission denied")
|
||||||
return
|
return
|
||||||
case dir.loading && fileslen == 0:
|
|
||||||
win.printMsg(ui.screen, "loading...")
|
|
||||||
return
|
|
||||||
case fileslen == 0:
|
case fileslen == 0:
|
||||||
win.printMsg(ui.screen, "empty")
|
win.printMsg(ui.screen, "empty")
|
||||||
return
|
return
|
||||||
@@ -1000,13 +1008,13 @@ func (ui *ui) drawPreview(nav *nav, context *dirContext) {
|
|||||||
if gOpts.preview {
|
if gOpts.preview {
|
||||||
if curr.isPreviewable() {
|
if curr.isPreviewable() {
|
||||||
if reg, ok := nav.regCache[curr.path]; ok {
|
if reg, ok := nav.regCache[curr.path]; ok {
|
||||||
win.printReg(ui.screen, reg, nav.previewLoading, &ui.sxScreen)
|
win.printReg(ui.screen, reg, &ui.sxScreen, nav.previewTimer)
|
||||||
}
|
}
|
||||||
} else if curr.IsDir() {
|
} else if curr.IsDir() {
|
||||||
ui.sxScreen.lastFile = ""
|
ui.sxScreen.lastFile = ""
|
||||||
dir := nav.getDir(curr.path)
|
dir := nav.getDir(curr.path)
|
||||||
dirStyle := &dirStyle{colors: ui.styles, icons: ui.icons, role: Preview}
|
dirStyle := &dirStyle{colors: ui.styles, icons: ui.icons, role: Preview}
|
||||||
win.printDir(ui, dir, context, dirStyle)
|
win.printDir(ui, dir, context, dirStyle, nav.previewTimer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1111,8 +1119,8 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
role = Active
|
role = Active
|
||||||
}
|
}
|
||||||
if dir := ui.dirOfWin(nav, i); dir != nil {
|
if dir := ui.dirOfWin(nav, i); dir != nil {
|
||||||
ui.wins[i].printDir(ui, dir, &context,
|
dirStyle := &dirStyle{colors: ui.styles, icons: ui.icons, role: role}
|
||||||
&dirStyle{colors: ui.styles, icons: ui.icons, role: role})
|
ui.wins[i].printDir(ui, dir, &context, dirStyle, nav.previewTimer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user