From 808404978ea6231fbd611361b8910e6ba09f41fe Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Fri, 1 Mar 2019 17:44:50 +0300 Subject: [PATCH] show move progress in the ruler --- app.go | 20 +++++++++++++++++++- nav.go | 16 +++++++++++++++- ui.go | 7 ++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app.go b/app.go index c30f760..b30b8b6 100644 --- a/app.go +++ b/app.go @@ -195,17 +195,35 @@ func (app *app) loop() { return case n := <-app.nav.copyBytesChan: + app.nav.copyBytes += n // n is usually 4096B so update roughly per 4096B x 1024 = 4MB copied if app.nav.copyUpdate++; app.nav.copyUpdate >= 1024 { app.nav.copyUpdate = 0 app.ui.draw(app.nav) } - app.nav.copyBytes += n case n := <-app.nav.copyTotalChan: app.nav.copyTotal += n if n < 0 { 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) case d := <-app.nav.dirChan: prev, ok := app.nav.dirCache[d.path] diff --git a/nav.go b/nav.go index 78554f0..39efa07 100644 --- a/nav.go +++ b/nav.go @@ -192,8 +192,13 @@ type nav struct { copyBytes int64 copyTotal int64 copyUpdate int + moveCount int + moveTotal int + moveUpdate int copyBytesChan chan int64 copyTotalChan chan int64 + moveCountChan chan int + moveTotalChan chan int dirChan chan *dir regChan chan *reg dirCache map[string]*dir @@ -278,6 +283,8 @@ func newNav(height int) *nav { nav := &nav{ copyBytesChan: make(chan int64, 1024), copyTotalChan: make(chan int64, 1024), + moveCountChan: make(chan int, 1024), + moveTotalChan: make(chan int, 1024), dirChan: make(chan *dir), regChan: make(chan *reg), dirCache: make(map[string]*dir), @@ -604,7 +611,6 @@ loop: nav.copyBytesChan <- n case err, ok := <-errs: if !ok { - nav.copyTotalChan <- -total break loop } errCount++ @@ -613,6 +619,8 @@ loop: } } + nav.copyTotalChan <- -total + if err := remote("send load"); err != nil { errCount++ echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) @@ -630,8 +638,12 @@ func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) { return } + nav.moveTotalChan <- len(srcs) + errCount := 0 for _, src := range srcs { + nav.moveCountChan <- 1 + srcStat, err := os.Stat(src) if err != nil { 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 { errCount++ echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) diff --git a/ui.go b/ui.go index 2587dda..5cc861f 100644 --- a/ui.go +++ b/ui.go @@ -594,9 +594,14 @@ func (ui *ui) drawStatLine(nav *nav) { acc := string(ui.keyCount) + string(ui.keyAcc) var progress string + if nav.copyTotal > 0 { 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)