diff --git a/app.go b/app.go index 8f7d94c6..55c342cc 100644 --- a/app.go +++ b/app.go @@ -467,6 +467,9 @@ func (app *app) loop() { app.nav.renew() app.ui.loadFile(app, false) app.ui.draw(app.nav) + case <-app.nav.previewTimer.C: + app.nav.previewLoading = true + app.ui.draw(app.nav) } } } diff --git a/nav.go b/nav.go index f16a39c3..faf1b880 100644 --- a/nav.go +++ b/nav.go @@ -388,11 +388,15 @@ type nav struct { searchPos int prevFilter []string volatilePreview bool + previewTimer *time.Timer + previewLoading bool jumpList []string jumpListInd int } func (nav *nav) loadDirInternal(path string) *dir { + nav.startPreview() + d := &dir{ loading: true, loadTime: time.Now(), @@ -448,6 +452,7 @@ func (nav *nav) checkDir(dir *dir) { return } + nav.startPreview() dir.loading = true dir.loadTime = now go func() { @@ -511,6 +516,7 @@ func newNav(height int) *nav { tags: make(map[string]string), selectionInd: 0, height: height, + previewTimer: time.NewTimer(0), jumpList: make([]string, 0), jumpListInd: -1, } @@ -813,6 +819,7 @@ func (nav *nav) loadReg(path string, volatile bool) *reg { if !ok || (volatile && r.volatile) { r := ®{loading: true, loadTime: time.Now(), path: path, volatile: true} nav.regCache[path] = r + nav.startPreview() nav.previewChan <- path return r } @@ -838,10 +845,17 @@ func (nav *nav) checkReg(reg *reg) { if s.ModTime().After(reg.loadTime) { reg.loadTime = now + nav.startPreview() nav.previewChan <- reg.path } } +func (nav *nav) startPreview() { + nav.previewTimer.Stop() + nav.previewLoading = false + nav.previewTimer.Reset(100 * time.Millisecond) +} + func (nav *nav) sort() { for _, d := range nav.dirs { name := d.name() diff --git a/ui.go b/ui.go index 09188cfc..d0a14ba6 100644 --- a/ui.go +++ b/ui.go @@ -252,7 +252,7 @@ func (win *win) printRight(screen tcell.Screen, y int, st tcell.Style, s string) win.print(screen, win.w-printLength(s), y, st, s) } -func (win *win) printReg(screen tcell.Screen, reg *reg) { +func (win *win) printReg(screen tcell.Screen, reg *reg, previewLoading bool) { if reg == nil { return } @@ -260,8 +260,10 @@ func (win *win) printReg(screen tcell.Screen, reg *reg) { st := tcell.StyleDefault if reg.loading { - st = st.Reverse(true) - win.print(screen, 2, 0, st, "loading...") + if previewLoading { + st = st.Reverse(true) + win.print(screen, 2, 0, st, "loading...") + } return } @@ -350,7 +352,7 @@ const SelectionColor = tcell.ColorPurple const YankColor = tcell.ColorOlive const CutColor = tcell.ColorMaroon -func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dirStyle *dirStyle) { +func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dirStyle *dirStyle, previewLoading bool) { if win.w < 5 || dir == nil { return } @@ -362,7 +364,9 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir return } if (dir.loading && len(dir.files) == 0) || (dirStyle.role == Preview && dir.loading && gOpts.dirpreviews) { - win.print(screen, 2, 0, messageStyle, "loading...") + if dirStyle.role != Preview || previewLoading { + win.print(screen, 2, 0, messageStyle, "loading...") + } return } @@ -930,7 +934,8 @@ func (ui *ui) draw(nav *nav) { } if dir := ui.dirOfWin(nav, i); dir != nil { ui.wins[i].printDir(ui.screen, dir, &context, - &dirStyle{colors: ui.styles, icons: ui.icons, role: role}) + &dirStyle{colors: ui.styles, icons: ui.icons, role: role}, + nav.previewLoading) } } @@ -966,9 +971,10 @@ func (ui *ui) draw(nav *nav) { if curr.IsDir() { preview.printDir(ui.screen, ui.dirPrev, &context, - &dirStyle{colors: ui.styles, icons: ui.icons, role: Preview}) + &dirStyle{colors: ui.styles, icons: ui.icons, role: Preview}, + nav.previewLoading) } else if curr.Mode().IsRegular() { - preview.printReg(ui.screen, ui.regPrev) + preview.printReg(ui.screen, ui.regPrev, nav.previewLoading) } } }