Show progress immediately when copying files (#2093)

This commit is contained in:
Joe Lim authored and GitHub committed 2025-08-12 14:20:19 +10:00
1 parent 651264e4de
commit f716ce1b0f
3 files changed
+20 -3

No files matched your search

+5 -1
View File
@@ -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
+9
View File
@@ -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)
+6 -2
View File
@@ -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 {