show progress for delete operation

Related #238
This commit is contained in:
Gokcehan 2019-12-02 19:50:13 +03:00
parent f76bf30f65
commit d5f989f373
3 changed files with 80 additions and 49 deletions

17
app.go
View File

@ -179,7 +179,7 @@ func (app *app) loop() {
continue continue
} }
if app.nav.deleting { if app.nav.deleteTotal > 0 {
app.ui.echoerr("quit: delete operation in progress") app.ui.echoerr("quit: delete operation in progress")
continue continue
} }
@ -237,6 +237,21 @@ func (app *app) loop() {
app.nav.moveUpdate = 0 app.nav.moveUpdate = 0
} }
app.ui.draw(app.nav) app.ui.draw(app.nav)
case n := <-app.nav.deleteCountChan:
app.nav.deleteCount += n
if app.nav.deleteUpdate++; app.nav.deleteUpdate >= 1000 {
app.nav.deleteUpdate = 0
app.ui.draw(app.nav)
}
case n := <-app.nav.deleteTotalChan:
app.nav.deleteTotal += n
if n < 0 {
app.nav.deleteCount += n
}
if app.nav.deleteTotal == 0 {
app.nav.deleteUpdate = 0
}
app.ui.draw(app.nav)
case d := <-app.nav.dirChan: case d := <-app.nav.dirChan:
prev, ok := app.nav.dirCache[d.path] prev, ok := app.nav.dirCache[d.path]
if ok { if ok {

108
nav.go
View File

@ -241,34 +241,38 @@ func (dir *dir) sel(name string, height int) {
} }
type nav struct { type nav struct {
dirs []*dir dirs []*dir
copyBytes int64 copyBytes int64
copyTotal int64 copyTotal int64
copyUpdate int copyUpdate int
moveCount int moveCount int
moveTotal int moveTotal int
moveUpdate int moveUpdate int
deleting bool deleteCount int
copyBytesChan chan int64 deleteTotal int
copyTotalChan chan int64 deleteUpdate int
moveCountChan chan int copyBytesChan chan int64
moveTotalChan chan int copyTotalChan chan int64
dirChan chan *dir moveCountChan chan int
regChan chan *reg moveTotalChan chan int
dirCache map[string]*dir deleteCountChan chan int
regCache map[string]*reg deleteTotalChan chan int
saves map[string]bool dirChan chan *dir
marks map[string]string regChan chan *reg
renameCache []string dirCache map[string]*dir
selections map[string]int regCache map[string]*reg
selectionInd int saves map[string]bool
height int marks map[string]string
find string renameCache []string
findBack bool selections map[string]int
search string selectionInd int
searchBack bool height int
searchInd int find string
searchPos int findBack bool
search string
searchBack bool
searchInd int
searchPos int
} }
func (nav *nav) loadDir(path string) *dir { func (nav *nav) loadDir(path string) *dir {
@ -336,20 +340,22 @@ func newNav(height int) *nav {
} }
nav := &nav{ nav := &nav{
copyBytesChan: make(chan int64, 1024), copyBytesChan: make(chan int64, 1024),
copyTotalChan: make(chan int64, 1024), copyTotalChan: make(chan int64, 1024),
moveCountChan: make(chan int, 1024), moveCountChan: make(chan int, 1024),
moveTotalChan: make(chan int, 1024), moveTotalChan: make(chan int, 1024),
dirChan: make(chan *dir), deleteCountChan: make(chan int, 1024),
regChan: make(chan *reg), deleteTotalChan: make(chan int, 1024),
dirCache: make(map[string]*dir), dirChan: make(chan *dir),
regCache: make(map[string]*reg), regChan: make(chan *reg),
saves: make(map[string]bool), dirCache: make(map[string]*dir),
marks: make(map[string]string), regCache: make(map[string]*reg),
renameCache: make([]string, 2), saves: make(map[string]bool),
selections: make(map[string]int), marks: make(map[string]string),
selectionInd: 0, renameCache: make([]string, 2),
height: height, selections: make(map[string]int),
selectionInd: 0,
height: height,
} }
nav.getDirs(wd) nav.getDirs(wd)
@ -785,21 +791,27 @@ func (nav *nav) del(ui *ui) error {
go func() { go func() {
echo := &callExpr{"echoerr", []string{""}, 1} echo := &callExpr{"echoerr", []string{""}, 1}
errCount := 0 errCount := 0
nav.deleting = true
nav.deleteTotalChan <- len(list)
for _, path := range list { for _, path := range list {
nav.deleteCountChan <- 1
if err := os.RemoveAll(path); err != nil { if err := os.RemoveAll(path); err != nil {
errCount++ errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo ui.exprChan <- echo
} }
} }
nav.deleting = false
}()
if err := remote("send sync"); err != nil { nav.deleteTotalChan <- -len(list)
return fmt.Errorf("delete: %s", err)
} if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}()
return nil return nil
} }

4
ui.go
View File

@ -616,6 +616,10 @@ func (ui *ui) drawStatLine(nav *nav) {
progress += fmt.Sprintf(" [%d/%d]", nav.moveCount, nav.moveTotal) progress += fmt.Sprintf(" [%d/%d]", nav.moveCount, nav.moveTotal)
} }
if nav.deleteTotal > 0 {
progress += fmt.Sprintf(" [%d/%d]", nav.deleteCount, nav.deleteTotal)
}
ruler := fmt.Sprintf("%s%s %d/%d", acc, progress, ind, tot) ruler := fmt.Sprintf("%s%s %d/%d", acc, progress, ind, tot)
ui.msgWin.printRight(0, fg, bg, ruler) ui.msgWin.printRight(0, fg, bg, ruler)