fix: emtpy progrese_bar and add change the color style white into green after upload success. (#4857)

This commit is contained in:
jiuker
2024-02-23 17:33:20 -08:00
committed by GitHub
parent 744dc910d8
commit a21d1efd4c
4 changed files with 44 additions and 18 deletions
+1 -1
View File
@@ -644,7 +644,7 @@ loop:
console.Eraseline()
}
} else if progressReader.ProgressBar.Get() > 0 {
progressReader.ProgressBar.Finish()
progressReader.Finish()
}
} else {
if accntReader, ok := pg.(*accounter); ok {
+14 -7
View File
@@ -58,7 +58,7 @@ EXAMPLES:
}
// mainGet is the entry point for get command.
func mainGet(cliCtx *cli.Context) error {
func mainGet(cliCtx *cli.Context) (e error) {
ctx, cancelGet := context.WithCancel(globalContext)
defer cancelGet()
@@ -78,14 +78,12 @@ func mainGet(cliCtx *cli.Context) error {
// Store a progress bar or an accounter
var pg ProgressReader
// Enable progress bar reader only during default mode.
if !globalQuiet && !globalJSON { // set up progress bar
pg = newProgressBar(totalBytes)
} else {
pg = newAccounter(totalBytes)
}
defer showLastProgressBar(pg)
go func() {
opts := prepareCopyURLsOpts{
sourceURLs: sourceURLs,
@@ -96,7 +94,7 @@ func mainGet(cliCtx *cli.Context) error {
for getURLs := range prepareGetURLs(ctx, opts) {
if getURLs.Error != nil {
printGetURLsError(&getURLs)
getURLsCh <- getURLs
break
}
totalBytes += getURLs.SourceContent.Size
@@ -109,14 +107,23 @@ func mainGet(cliCtx *cli.Context) error {
for {
select {
case <-ctx.Done():
return nil
showLastProgressBar(pg, nil)
return
case getURLs, ok := <-getURLsCh:
if !ok {
return nil
showLastProgressBar(pg, nil)
return
}
if getURLs.Error != nil {
printGetURLsError(&getURLs)
showLastProgressBar(pg, getURLs.Error.ToGoError())
return
}
urls := doCopy(ctx, doCopyOpts{cpURLs: getURLs, pg: pg, encKeyDB: encKeyDB, isMvCmd: false, preserve: false, isZip: false, ignoreStat: true})
if urls.Error != nil {
return urls.Error.ToGoError()
e = urls.Error.ToGoError()
showLastProgressBar(pg, e)
return
}
}
}
+6 -1
View File
@@ -35,7 +35,7 @@ type progressBar struct {
func newPB(total int64) *pb.ProgressBar {
// Progress bar specific theme customization.
console.SetColor("Bar", color.New(color.FgGreen, color.Bold))
console.SetColor("Bar", color.New(color.FgYellow, color.Bold))
// get the new original progress bar.
bar := pb.New64(total)
@@ -98,6 +98,11 @@ func (p *progressBar) SetCaption(caption string) *progressBar {
return p
}
func (p *progressBar) Finish() {
console.SetColor("Bar", color.New(color.FgGreen, color.Bold))
p.ProgressBar.Finish()
}
func (p *progressBar) Set64(length int64) *progressBar {
p.ProgressBar = p.ProgressBar.Set64(length)
return p
+23 -9
View File
@@ -76,7 +76,7 @@ EXAMPLES:
}
// mainPut is the entry point for put command.
func mainPut(cliCtx *cli.Context) error {
func mainPut(cliCtx *cli.Context) (e error) {
args := cliCtx.Args()
if len(args) < 2 {
showCommandHelpAndExit(cliCtx, 1) // last argument is exit code.
@@ -121,7 +121,6 @@ func mainPut(cliCtx *cli.Context) error {
} else {
pg = newAccounter(totalBytes)
}
defer showLastProgressBar(pg)
go func() {
opts := prepareCopyURLsOpts{
sourceURLs: sourceURLs,
@@ -132,7 +131,7 @@ func mainPut(cliCtx *cli.Context) error {
for putURLs := range preparePutURLs(ctx, opts) {
if putURLs.Error != nil {
printPutURLsError(&putURLs)
putURLsCh <- putURLs
break
}
totalBytes += putURLs.SourceContent.Size
@@ -145,14 +144,23 @@ func mainPut(cliCtx *cli.Context) error {
for {
select {
case <-ctx.Done():
return nil
showLastProgressBar(pg, nil)
return
case putURLs, ok := <-putURLsCh:
if !ok {
return nil
showLastProgressBar(pg, nil)
return
}
if putURLs.Error != nil {
printPutURLsError(&putURLs)
showLastProgressBar(pg, putURLs.Error.ToGoError())
return
}
urls := doCopy(ctx, doCopyOpts{cpURLs: putURLs, pg: pg, encKeyDB: encKeyDB, isMvCmd: false, preserve: false, isZip: false, multipartSize: size, multipartThreads: strconv.Itoa(threads)})
if urls.Error != nil {
return urls.Error.ToGoError()
e = urls.Error.ToGoError()
showLastProgressBar(pg, e)
return
}
}
}
@@ -164,7 +172,6 @@ func printPutURLsError(putURLs *URLs) {
if !globalQuiet && !globalJSON {
console.Eraseline()
}
if strings.Contains(putURLs.Error.ToGoError().Error(),
" is a folder.") {
errorIf(putURLs.Error.Trace(),
@@ -175,9 +182,16 @@ func printPutURLsError(putURLs *URLs) {
}
}
func showLastProgressBar(pg ProgressReader) {
func showLastProgressBar(pg ProgressReader, e error) {
if e != nil {
// We only erase a line if we are displaying a progress bar
if !globalQuiet && !globalJSON {
console.Eraseline()
}
return
}
if progressReader, ok := pg.(*progressBar); ok {
progressReader.ProgressBar.Finish()
progressReader.Finish()
} else {
if accntReader, ok := pg.(*accounter); ok {
printMsg(accntReader.Stat())