show move progress in the ruler

This commit is contained in:
Gokcehan 2019-03-01 17:44:50 +03:00
parent 99734c7dcf
commit 808404978e
3 changed files with 40 additions and 3 deletions

20
app.go
View File

@ -195,17 +195,35 @@ func (app *app) loop() {
return return
case n := <-app.nav.copyBytesChan: case n := <-app.nav.copyBytesChan:
app.nav.copyBytes += n
// n is usually 4096B so update roughly per 4096B x 1024 = 4MB copied // n is usually 4096B so update roughly per 4096B x 1024 = 4MB copied
if app.nav.copyUpdate++; app.nav.copyUpdate >= 1024 { if app.nav.copyUpdate++; app.nav.copyUpdate >= 1024 {
app.nav.copyUpdate = 0 app.nav.copyUpdate = 0
app.ui.draw(app.nav) app.ui.draw(app.nav)
} }
app.nav.copyBytes += n
case n := <-app.nav.copyTotalChan: case n := <-app.nav.copyTotalChan:
app.nav.copyTotal += n app.nav.copyTotal += n
if n < 0 { if n < 0 {
app.nav.copyBytes += n app.nav.copyBytes += n
} }
if app.nav.copyTotal == 0 {
app.nav.copyUpdate = 0
}
app.ui.draw(app.nav)
case n := <-app.nav.moveCountChan:
app.nav.moveCount += n
if app.nav.moveUpdate++; app.nav.moveUpdate >= 1000 {
app.nav.moveUpdate = 0
app.ui.draw(app.nav)
}
case n := <-app.nav.moveTotalChan:
app.nav.moveTotal += n
if n < 0 {
app.nav.moveCount += n
}
if app.nav.moveTotal == 0 {
app.nav.moveUpdate = 0
}
app.ui.draw(app.nav) 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]

16
nav.go
View File

@ -192,8 +192,13 @@ type nav struct {
copyBytes int64 copyBytes int64
copyTotal int64 copyTotal int64
copyUpdate int copyUpdate int
moveCount int
moveTotal int
moveUpdate int
copyBytesChan chan int64 copyBytesChan chan int64
copyTotalChan chan int64 copyTotalChan chan int64
moveCountChan chan int
moveTotalChan chan int
dirChan chan *dir dirChan chan *dir
regChan chan *reg regChan chan *reg
dirCache map[string]*dir dirCache map[string]*dir
@ -278,6 +283,8 @@ 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),
moveTotalChan: make(chan int, 1024),
dirChan: make(chan *dir), dirChan: make(chan *dir),
regChan: make(chan *reg), regChan: make(chan *reg),
dirCache: make(map[string]*dir), dirCache: make(map[string]*dir),
@ -604,7 +611,6 @@ loop:
nav.copyBytesChan <- n nav.copyBytesChan <- n
case err, ok := <-errs: case err, ok := <-errs:
if !ok { if !ok {
nav.copyTotalChan <- -total
break loop break loop
} }
errCount++ errCount++
@ -613,6 +619,8 @@ loop:
} }
} }
nav.copyTotalChan <- -total
if err := remote("send load"); err != nil { if err := remote("send load"); err != nil {
errCount++ errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
@ -630,8 +638,12 @@ func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
return return
} }
nav.moveTotalChan <- len(srcs)
errCount := 0 errCount := 0
for _, src := range srcs { for _, src := range srcs {
nav.moveCountChan <- 1
srcStat, err := os.Stat(src) srcStat, err := os.Stat(src)
if err != nil { if err != nil {
errCount++ errCount++
@ -664,6 +676,8 @@ func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
} }
} }
nav.moveTotalChan <- -len(srcs)
if err := remote("send load"); err != nil { if err := remote("send load"); err != nil {
errCount++ errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)

7
ui.go
View File

@ -594,9 +594,14 @@ func (ui *ui) drawStatLine(nav *nav) {
acc := string(ui.keyCount) + string(ui.keyAcc) acc := string(ui.keyCount) + string(ui.keyAcc)
var progress string var progress string
if nav.copyTotal > 0 { if nav.copyTotal > 0 {
percentage := int((100 * float64(nav.copyBytes)) / float64(nav.copyTotal)) percentage := int((100 * float64(nav.copyBytes)) / float64(nav.copyTotal))
progress = fmt.Sprintf(" [%d%%]", percentage) progress += fmt.Sprintf(" [%d%%]", percentage)
}
if nav.moveTotal > 0 {
progress += fmt.Sprintf(" [%d/%d]", nav.moveCount, nav.moveTotal)
} }
ruler := fmt.Sprintf("%s%s %d/%d", acc, progress, ind, tot) ruler := fmt.Sprintf("%s%s %d/%d", acc, progress, ind, tot)