Improve preview loading message flickering (#1154)
* Improve preview loading * Change timeout to 100 milliseconds * Add previewtimeout option * Start preview outside other goroutines * Revert previewtimeout option
This commit is contained in:
1 parent
25288fd90b
commit
68e2433d48
3 files changed
+31
-8
No files matched your search
@@ -467,6 +467,9 @@ func (app *app) loop() {
|
|||||||
app.nav.renew()
|
app.nav.renew()
|
||||||
app.ui.loadFile(app, false)
|
app.ui.loadFile(app, false)
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
|
case <-app.nav.previewTimer.C:
|
||||||
|
app.nav.previewLoading = true
|
||||||
|
app.ui.draw(app.nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,11 +388,15 @@ type nav struct {
|
|||||||
searchPos int
|
searchPos int
|
||||||
prevFilter []string
|
prevFilter []string
|
||||||
volatilePreview bool
|
volatilePreview bool
|
||||||
|
previewTimer *time.Timer
|
||||||
|
previewLoading bool
|
||||||
jumpList []string
|
jumpList []string
|
||||||
jumpListInd int
|
jumpListInd int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) loadDirInternal(path string) *dir {
|
func (nav *nav) loadDirInternal(path string) *dir {
|
||||||
|
nav.startPreview()
|
||||||
|
|
||||||
d := &dir{
|
d := &dir{
|
||||||
loading: true,
|
loading: true,
|
||||||
loadTime: time.Now(),
|
loadTime: time.Now(),
|
||||||
@@ -448,6 +452,7 @@ func (nav *nav) checkDir(dir *dir) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nav.startPreview()
|
||||||
dir.loading = true
|
dir.loading = true
|
||||||
dir.loadTime = now
|
dir.loadTime = now
|
||||||
go func() {
|
go func() {
|
||||||
@@ -511,6 +516,7 @@ func newNav(height int) *nav {
|
|||||||
tags: make(map[string]string),
|
tags: make(map[string]string),
|
||||||
selectionInd: 0,
|
selectionInd: 0,
|
||||||
height: height,
|
height: height,
|
||||||
|
previewTimer: time.NewTimer(0),
|
||||||
jumpList: make([]string, 0),
|
jumpList: make([]string, 0),
|
||||||
jumpListInd: -1,
|
jumpListInd: -1,
|
||||||
}
|
}
|
||||||
@@ -813,6 +819,7 @@ func (nav *nav) loadReg(path string, volatile bool) *reg {
|
|||||||
if !ok || (volatile && r.volatile) {
|
if !ok || (volatile && r.volatile) {
|
||||||
r := ®{loading: true, loadTime: time.Now(), path: path, volatile: true}
|
r := ®{loading: true, loadTime: time.Now(), path: path, volatile: true}
|
||||||
nav.regCache[path] = r
|
nav.regCache[path] = r
|
||||||
|
nav.startPreview()
|
||||||
nav.previewChan <- path
|
nav.previewChan <- path
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@@ -838,10 +845,17 @@ 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 _, d := range nav.dirs {
|
for _, d := range nav.dirs {
|
||||||
name := d.name()
|
name := d.name()
|
||||||
|
|||||||
@@ -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)
|
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 {
|
if reg == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -260,8 +260,10 @@ func (win *win) printReg(screen tcell.Screen, reg *reg) {
|
|||||||
st := tcell.StyleDefault
|
st := tcell.StyleDefault
|
||||||
|
|
||||||
if reg.loading {
|
if reg.loading {
|
||||||
st = st.Reverse(true)
|
if previewLoading {
|
||||||
win.print(screen, 2, 0, st, "loading...")
|
st = st.Reverse(true)
|
||||||
|
win.print(screen, 2, 0, st, "loading...")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,7 +352,7 @@ const SelectionColor = tcell.ColorPurple
|
|||||||
const YankColor = tcell.ColorOlive
|
const YankColor = tcell.ColorOlive
|
||||||
const CutColor = tcell.ColorMaroon
|
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 {
|
if win.w < 5 || dir == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -362,7 +364,9 @@ func (win *win) printDir(screen tcell.Screen, dir *dir, context *dirContext, dir
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (dir.loading && len(dir.files) == 0) || (dirStyle.role == Preview && dir.loading && gOpts.dirpreviews) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -930,7 +934,8 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
}
|
}
|
||||||
if dir := ui.dirOfWin(nav, i); dir != nil {
|
if dir := ui.dirOfWin(nav, i); dir != nil {
|
||||||
ui.wins[i].printDir(ui.screen, dir, &context,
|
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() {
|
if curr.IsDir() {
|
||||||
preview.printDir(ui.screen, ui.dirPrev, &context,
|
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() {
|
} else if curr.Mode().IsRegular() {
|
||||||
preview.printReg(ui.screen, ui.regPrev)
|
preview.printReg(ui.screen, ui.regPrev, nav.previewLoading)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user