parent
4846a74320
commit
7acc85f81c
15
nav.go
15
nav.go
@ -370,7 +370,7 @@ func (nav *nav) preview() {
|
||||
reader = f
|
||||
}
|
||||
|
||||
reg := ®{path: curr.path}
|
||||
reg := ®{loadTime: time.Now(), path: curr.path}
|
||||
|
||||
buf := bufio.NewScanner(reader)
|
||||
|
||||
@ -396,10 +396,21 @@ func (nav *nav) loadReg(ui *ui, path string) *reg {
|
||||
r, ok := nav.regCache[path]
|
||||
if !ok {
|
||||
go nav.preview()
|
||||
r := ®{path: path, lines: []string{"\033[1mloading...\033[0m"}}
|
||||
r := ®{loading: true, path: path}
|
||||
nav.regCache[path] = r
|
||||
return r
|
||||
}
|
||||
|
||||
s, err := os.Stat(r.path)
|
||||
if err != nil {
|
||||
return r
|
||||
}
|
||||
|
||||
if s.ModTime().After(r.loadTime) {
|
||||
r.loadTime = time.Now()
|
||||
go nav.preview()
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
|
12
ui.go
12
ui.go
@ -181,6 +181,12 @@ func (win *win) printReg(reg *reg) {
|
||||
|
||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||
|
||||
if reg.loading {
|
||||
fg = termbox.AttrBold
|
||||
win.print(2, 0, fg, bg, "loading...")
|
||||
return
|
||||
}
|
||||
|
||||
for i, l := range reg.lines {
|
||||
fg, bg = win.print(2, i, fg, bg, l)
|
||||
}
|
||||
@ -462,8 +468,10 @@ func (ui *ui) printf(format string, a ...interface{}) {
|
||||
}
|
||||
|
||||
type reg struct {
|
||||
path string
|
||||
lines []string
|
||||
loading bool
|
||||
loadTime time.Time
|
||||
path string
|
||||
lines []string
|
||||
}
|
||||
|
||||
func (ui *ui) loadFile(nav *nav) {
|
||||
|
Loading…
Reference in New Issue
Block a user