From f716ce1b0fdd63fefa59f8fec8d0930b3750d557 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Tue, 12 Aug 2025 14:20:19 +1000 Subject: [PATCH] Show progress immediately when copying files (#2093) --- app.go | 6 +++++- nav.go | 9 +++++++++ ui.go | 8 ++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app.go b/app.go index 974b07e8..f22396a4 100644 --- a/app.go +++ b/app.go @@ -318,7 +318,7 @@ func (app *app) loop() { for { select { case <-app.quitChan: - if app.nav.copyTotal > 0 { + if app.nav.copyJobs > 0 { app.ui.echoerr("quit: copy operation in progress") continue } @@ -340,6 +340,9 @@ func (app *app) loop() { log.Print("bye!") return + case <-app.nav.copyJobsChan: + app.nav.copyJobs += 1 + app.ui.draw(app.nav) case n := <-app.nav.copyBytesChan: app.nav.copyBytes += n // n is usually 32*1024B (default io.Copy() buffer) so update roughly per 32KB x 128 = 4MB copied @@ -351,6 +354,7 @@ func (app *app) loop() { app.nav.copyTotal += n if n < 0 { app.nav.copyBytes += n + app.nav.copyJobs -= 1 } if app.nav.copyTotal == 0 { app.nav.copyUpdate = 0 diff --git a/nav.go b/nav.go index 326e4ee2..1be41e81 100644 --- a/nav.go +++ b/nav.go @@ -528,6 +528,7 @@ type clipboard struct { type nav struct { init bool dirs []*dir + copyJobs int copyBytes int64 copyTotal int64 copyUpdate int @@ -537,6 +538,7 @@ type nav struct { deleteCount int deleteTotal int deleteUpdate int + copyJobsChan chan struct{} copyBytesChan chan int64 copyTotalChan chan int64 moveCountChan chan int @@ -682,6 +684,7 @@ func (nav *nav) getDirs(wd string) { func newNav(height int) *nav { nav := &nav{ + copyJobsChan: make(chan struct{}, 1024), copyBytesChan: make(chan int64, 1024), copyTotalChan: make(chan int64, 1024), moveCountChan: make(chan int, 1024), @@ -1354,6 +1357,12 @@ func (nav *nav) copyAsync(app *app, srcs []string, dstDir string) { return } + // indicate that a copy operation is in progress + // using the total bytes to determine this instead will mean that it is + // possible for copySize to take a while, but not be reflected in the UI + // until it has finished + nav.copyJobsChan <- struct{}{} + total, err := copySize(srcs) if err != nil { sendErr("%v", err) diff --git a/ui.go b/ui.go index 9c9afaad..387db920 100644 --- a/ui.go +++ b/ui.go @@ -963,8 +963,12 @@ func (ui *ui) drawRuler(nav *nav) { progress := []string{} - if nav.copyTotal > 0 { - progress = append(progress, fmt.Sprintf("[%d%%]", nav.copyBytes*100/nav.copyTotal)) + if nav.copyJobs > 0 { + if nav.copyTotal == 0 { + progress = append(progress, fmt.Sprintf("[0%%]")) + } else { + progress = append(progress, fmt.Sprintf("[%d%%]", nav.copyBytes*100/nav.copyTotal)) + } } if nav.moveTotal > 0 {