Show progress immediately when copying files (#2093)
This commit is contained in:
1 parent
651264e4de
commit
f716ce1b0f
3 files changed
+20
-3
No files matched your search
@@ -318,7 +318,7 @@ func (app *app) loop() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-app.quitChan:
|
case <-app.quitChan:
|
||||||
if app.nav.copyTotal > 0 {
|
if app.nav.copyJobs > 0 {
|
||||||
app.ui.echoerr("quit: copy operation in progress")
|
app.ui.echoerr("quit: copy operation in progress")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -340,6 +340,9 @@ func (app *app) loop() {
|
|||||||
log.Print("bye!")
|
log.Print("bye!")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
case <-app.nav.copyJobsChan:
|
||||||
|
app.nav.copyJobs += 1
|
||||||
|
app.ui.draw(app.nav)
|
||||||
case n := <-app.nav.copyBytesChan:
|
case n := <-app.nav.copyBytesChan:
|
||||||
app.nav.copyBytes += n
|
app.nav.copyBytes += n
|
||||||
// n is usually 32*1024B (default io.Copy() buffer) so update roughly per 32KB x 128 = 4MB copied
|
// 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
|
app.nav.copyTotal += n
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
app.nav.copyBytes += n
|
app.nav.copyBytes += n
|
||||||
|
app.nav.copyJobs -= 1
|
||||||
}
|
}
|
||||||
if app.nav.copyTotal == 0 {
|
if app.nav.copyTotal == 0 {
|
||||||
app.nav.copyUpdate = 0
|
app.nav.copyUpdate = 0
|
||||||
|
|||||||
@@ -528,6 +528,7 @@ type clipboard struct {
|
|||||||
type nav struct {
|
type nav struct {
|
||||||
init bool
|
init bool
|
||||||
dirs []*dir
|
dirs []*dir
|
||||||
|
copyJobs int
|
||||||
copyBytes int64
|
copyBytes int64
|
||||||
copyTotal int64
|
copyTotal int64
|
||||||
copyUpdate int
|
copyUpdate int
|
||||||
@@ -537,6 +538,7 @@ type nav struct {
|
|||||||
deleteCount int
|
deleteCount int
|
||||||
deleteTotal int
|
deleteTotal int
|
||||||
deleteUpdate int
|
deleteUpdate int
|
||||||
|
copyJobsChan chan struct{}
|
||||||
copyBytesChan chan int64
|
copyBytesChan chan int64
|
||||||
copyTotalChan chan int64
|
copyTotalChan chan int64
|
||||||
moveCountChan chan int
|
moveCountChan chan int
|
||||||
@@ -682,6 +684,7 @@ func (nav *nav) getDirs(wd string) {
|
|||||||
|
|
||||||
func newNav(height int) *nav {
|
func newNav(height int) *nav {
|
||||||
nav := &nav{
|
nav := &nav{
|
||||||
|
copyJobsChan: make(chan struct{}, 1024),
|
||||||
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),
|
moveCountChan: make(chan int, 1024),
|
||||||
@@ -1354,6 +1357,12 @@ func (nav *nav) copyAsync(app *app, srcs []string, dstDir string) {
|
|||||||
return
|
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)
|
total, err := copySize(srcs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sendErr("%v", err)
|
sendErr("%v", err)
|
||||||
|
|||||||
@@ -963,8 +963,12 @@ func (ui *ui) drawRuler(nav *nav) {
|
|||||||
|
|
||||||
progress := []string{}
|
progress := []string{}
|
||||||
|
|
||||||
if nav.copyTotal > 0 {
|
if nav.copyJobs > 0 {
|
||||||
progress = append(progress, fmt.Sprintf("[%d%%]", nav.copyBytes*100/nav.copyTotal))
|
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 {
|
if nav.moveTotal > 0 {
|
||||||
|
|||||||
Reference in new issue
Block a user