show copy progress in the ruler
This commit is contained in:
parent
599ac11f26
commit
6ec2924b6b
13
app.go
13
app.go
@ -189,6 +189,19 @@ func (app *app) loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
case n := <-app.nav.copyBytesChan:
|
||||||
|
// n is usually 1024B so update roughly per 1024B x 1024 = 1MB 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
|
||||||
|
}
|
||||||
|
app.ui.draw(app.nav)
|
||||||
case d := <-app.nav.dirChan:
|
case d := <-app.nav.dirChan:
|
||||||
prev, ok := app.nav.dirCache[d.path]
|
prev, ok := app.nav.dirCache[d.path]
|
||||||
if ok {
|
if ok {
|
||||||
|
79
nav.go
79
nav.go
@ -188,22 +188,27 @@ func (dir *dir) sel(name string, height int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type nav struct {
|
type nav struct {
|
||||||
dirs []*dir
|
dirs []*dir
|
||||||
dirChan chan *dir
|
copyBytes int64
|
||||||
regChan chan *reg
|
copyTotal int64
|
||||||
dirCache map[string]*dir
|
copyUpdate int
|
||||||
regCache map[string]*reg
|
copyBytesChan chan int64
|
||||||
saves map[string]bool
|
copyTotalChan chan int64
|
||||||
marks map[string]string
|
dirChan chan *dir
|
||||||
selections map[string]int
|
regChan chan *reg
|
||||||
selectionInd int
|
dirCache map[string]*dir
|
||||||
height int
|
regCache map[string]*reg
|
||||||
find string
|
saves map[string]bool
|
||||||
findBack bool
|
marks map[string]string
|
||||||
search string
|
selections map[string]int
|
||||||
searchBack bool
|
selectionInd int
|
||||||
searchInd int
|
height int
|
||||||
searchPos int
|
find string
|
||||||
|
findBack bool
|
||||||
|
search string
|
||||||
|
searchBack bool
|
||||||
|
searchInd int
|
||||||
|
searchPos int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) loadDir(path string) *dir {
|
func (nav *nav) loadDir(path string) *dir {
|
||||||
@ -271,15 +276,17 @@ func newNav(height int) *nav {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nav := &nav{
|
nav := &nav{
|
||||||
dirChan: make(chan *dir),
|
copyBytesChan: make(chan int64, 1024),
|
||||||
regChan: make(chan *reg),
|
copyTotalChan: make(chan int64, 1024),
|
||||||
dirCache: make(map[string]*dir),
|
dirChan: make(chan *dir),
|
||||||
regCache: make(map[string]*reg),
|
regChan: make(chan *reg),
|
||||||
saves: make(map[string]bool),
|
dirCache: make(map[string]*dir),
|
||||||
marks: make(map[string]string),
|
regCache: make(map[string]*reg),
|
||||||
selections: make(map[string]int),
|
saves: make(map[string]bool),
|
||||||
selectionInd: 0,
|
marks: make(map[string]string),
|
||||||
height: height,
|
selections: make(map[string]int),
|
||||||
|
selectionInd: 0,
|
||||||
|
height: height,
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.getDirs(wd)
|
nav.getDirs(wd)
|
||||||
@ -568,7 +575,7 @@ func (nav *nav) save(cp bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyAsync(ui *ui, srcs []string, dstDir string) {
|
func (nav *nav) copyAsync(ui *ui, srcs []string, dstDir string) {
|
||||||
echo := &callExpr{"echo", []string{""}, 1}
|
echo := &callExpr{"echo", []string{""}, 1}
|
||||||
|
|
||||||
_, err := os.Stat(dstDir)
|
_, err := os.Stat(dstDir)
|
||||||
@ -585,25 +592,19 @@ func copyAsync(ui *ui, srcs []string, dstDir string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nav.copyTotalChan <- total
|
||||||
|
|
||||||
nums, errs := copyAll(srcs, dstDir)
|
nums, errs := copyAll(srcs, dstDir)
|
||||||
|
|
||||||
curr := int64(0)
|
|
||||||
lastUpdate := 0
|
|
||||||
errCount := 0
|
errCount := 0
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case n := <-nums:
|
case n := <-nums:
|
||||||
curr += n
|
nav.copyBytesChan <- n
|
||||||
// n is usually 1024B so update roughly per 1024B x 1024 = 1MB copied
|
|
||||||
if lastUpdate++; lastUpdate >= 1024 {
|
|
||||||
lastUpdate = 0
|
|
||||||
percentage := int((100 * float64(curr)) / float64(total))
|
|
||||||
echo.args[0] = fmt.Sprintf("%d%%", percentage)
|
|
||||||
ui.exprChan <- echo
|
|
||||||
}
|
|
||||||
case err, ok := <-errs:
|
case err, ok := <-errs:
|
||||||
if !ok {
|
if !ok {
|
||||||
|
nav.copyTotalChan <- -total
|
||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
errCount++
|
errCount++
|
||||||
@ -619,7 +620,7 @@ loop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func moveAsync(ui *ui, srcs []string, dstDir string) {
|
func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
|
||||||
echo := &callExpr{"echo", []string{""}, 1}
|
echo := &callExpr{"echo", []string{""}, 1}
|
||||||
|
|
||||||
_, err := os.Stat(dstDir)
|
_, err := os.Stat(dstDir)
|
||||||
@ -683,9 +684,9 @@ func (nav *nav) paste(ui *ui) error {
|
|||||||
dstDir := nav.currDir().path
|
dstDir := nav.currDir().path
|
||||||
|
|
||||||
if cp {
|
if cp {
|
||||||
go copyAsync(ui, srcs, dstDir)
|
go nav.copyAsync(ui, srcs, dstDir)
|
||||||
} else {
|
} else {
|
||||||
go moveAsync(ui, srcs, dstDir)
|
go nav.moveAsync(ui, srcs, dstDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := saveFiles(nil, false); err != nil {
|
if err := saveFiles(nil, false); err != nil {
|
||||||
|
8
ui.go
8
ui.go
@ -576,7 +576,13 @@ func (ui *ui) drawStatLine(nav *nav) {
|
|||||||
ind := min(currDir.ind+1, tot)
|
ind := min(currDir.ind+1, tot)
|
||||||
acc := string(ui.keyCount) + string(ui.keyAcc)
|
acc := string(ui.keyCount) + string(ui.keyAcc)
|
||||||
|
|
||||||
ruler := fmt.Sprintf("%s %d/%d", acc, ind, tot)
|
var progress string
|
||||||
|
if nav.copyTotal > 0 {
|
||||||
|
percentage := int((100 * float64(nav.copyBytes)) / float64(nav.copyTotal))
|
||||||
|
progress = fmt.Sprintf(" [%d%%]", percentage)
|
||||||
|
}
|
||||||
|
|
||||||
|
ruler := fmt.Sprintf("%s%s %d/%d", acc, progress, ind, tot)
|
||||||
|
|
||||||
ui.msgWin.printRight(0, fg, bg, ruler)
|
ui.msgWin.printRight(0, fg, bg, ruler)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user