change progress unicode style, simplify progress bar init() (#4224)

This commit is contained in:
Harshavardhana
2022-08-26 12:45:12 -07:00
committed by GitHub
parent 55c5b96323
commit af1d0ee6da
3 changed files with 18 additions and 58 deletions
+1 -1
View File
@@ -257,7 +257,7 @@ func doCopy(ctx context.Context, cpURLs URLs, pg ProgressReader, encKeyDB map[st
sourcePath := filepath.ToSlash(filepath.Join(sourceAlias, sourceURL.Path))
if progressReader, ok := pg.(*progressBar); ok {
progressReader.SetCaption(cpURLs.SourceContent.URL.String() + ": ")
progressReader.SetCaption(cpURLs.SourceContent.URL.String() + ":")
} else {
targetPath := filepath.ToSlash(filepath.Join(targetAlias, targetURL.Path))
printMsg(copyMessage{
+1 -1
View File
@@ -432,7 +432,7 @@ func (mj *mirrorJob) doMirror(ctx context.Context, sURLs URLs) URLs {
targetURL := sURLs.TargetContent.URL
length := sURLs.SourceContent.Size
mj.status.SetCaption(sourceURL.String() + ": ")
mj.status.SetCaption(sourceURL.String() + ":")
// Initialize target metadata.
sURLs.TargetContent.Metadata = make(map[string]string)
+16 -56
View File
@@ -25,7 +25,6 @@ import (
"github.com/cheggaaa/pb"
"github.com/fatih/color"
"github.com/minio/pkg/console"
)
@@ -34,7 +33,7 @@ type progressBar struct {
*pb.ProgressBar
}
func newProgressReader(r io.Reader, caption string, total int64) *pb.Reader {
func newPB(total int64) *pb.ProgressBar {
// Progress bar specific theme customization.
console.SetColor("Bar", color.New(color.FgGreen, color.Bold))
@@ -60,12 +59,9 @@ func newProgressReader(r io.Reader, caption string, total int64) *pb.Reader {
// Use different unicodes for Linux, OS X and Windows.
switch runtime.GOOS {
case "linux":
case "linux", "darwin":
// Need to add '\x00' as delimiter for unicode characters.
bar.Format("┃\x00▓\x00█\x00░\x00┃")
case "darwin":
// Need to add '\x00' as delimiter for unicode characters.
bar.Format(" \x00▓\x00 \x00░\x00 ")
bar.Format("━\x00━\x00━\x00┉\x00━")
default:
// Default to non unicode characters.
bar.Format("[=> ]")
@@ -74,6 +70,12 @@ func newProgressReader(r io.Reader, caption string, total int64) *pb.Reader {
// Start the progress bar.
bar.Start()
return bar
}
func newProgressReader(r io.Reader, caption string, total int64) *pb.Reader {
bar := newPB(total)
if caption != "" {
bar.Prefix(caption)
}
@@ -83,52 +85,10 @@ func newProgressReader(r io.Reader, caption string, total int64) *pb.Reader {
// newProgressBar - instantiate a progress bar.
func newProgressBar(total int64) *progressBar {
// Progress bar speific theme customization.
console.SetColor("Bar", color.New(color.FgGreen, color.Bold))
pgbar := progressBar{}
// get the new original progress bar.
bar := pb.New64(total)
// Set new human friendly print units.
bar.SetUnits(pb.U_BYTES)
// Refresh rate for progress bar is set to 125 milliseconds.
bar.SetRefreshRate(time.Millisecond * 125)
// Do not print a newline by default handled, it is handled manually.
bar.NotPrint = true
// Show current speed is true.
bar.ShowSpeed = true
// Custom callback with colorized bar.
bar.Callback = func(s string) {
console.Print(console.Colorize("Bar", "\r"+s))
}
// Use different unicodes for Linux, OS X and Windows.
switch runtime.GOOS {
case "linux":
// Need to add '\x00' as delimiter for unicode characters.
bar.Format("┃\x00▓\x00█\x00░\x00┃")
case "darwin":
// Need to add '\x00' as delimiter for unicode characters.
bar.Format(" \x00▓\x00 \x00░\x00 ")
default:
// Default to non unicode characters.
bar.Format("[=> ]")
}
// Start the progress bar.
bar.Start()
// Copy for future
pgbar.ProgressBar = bar
bar := newPB(total)
// Return new progress bar here.
return &pgbar
return &progressBar{ProgressBar: bar}
}
// Set caption.
@@ -163,26 +123,26 @@ func (p *progressBar) SetTotal(total int64) {
// cursorAnimate - returns a animated rune through read channel for every read.
func cursorAnimate() <-chan string {
cursorCh := make(chan string)
var cursors string
var cursors []string
switch runtime.GOOS {
case "linux":
// cursors = "➩➪➫➬➭➮➯➱"
// cursors = "▁▃▄▅▆▇█▇▆▅▄▃"
cursors = "◐◓◑◒"
cursors = []string{"◐", "◓", "◑", "◒"}
// cursors = "←↖↑↗→↘↓↙"
// cursors = "◴◷◶◵"
// cursors = "◰◳◲◱"
// cursors = "⣾⣽⣻⢿⡿⣟⣯⣷"
case "darwin":
cursors = "◐◓◑◒"
cursors = []string{"◐", "◓", "◑", "◒"}
default:
cursors = "|/-\\"
cursors = []string{"|", "/", "-", "\\"}
}
go func() {
for {
for _, cursor := range cursors {
cursorCh <- string(cursor)
cursorCh <- cursor
}
}
}()