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
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]

16
nav.go
View File

@ -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)

7
ui.go
View File

@ -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)