1
0
mirror of https://github.com/minio/mc.git synced 2025-11-16 11:02:34 +03:00

Trim caption for just file names and getFixedWidth for 10%.

Remove spaces in between unicode characters, these were causing spurious space characters
This commit is contained in:
Harshavardhana
2015-06-16 02:11:36 -07:00
parent 0357efbdef
commit 476e184a90
3 changed files with 18 additions and 27 deletions

View File

@@ -20,11 +20,11 @@ import (
"fmt" "fmt"
"io" "io"
"math" "math"
"path/filepath"
"runtime" "runtime"
"sync" "sync"
"github.com/minio/cli" "github.com/minio/cli"
"github.com/minio/mc/pkg/client"
"github.com/minio/mc/pkg/console" "github.com/minio/mc/pkg/console"
"github.com/minio/mc/pkg/countlock" "github.com/minio/mc/pkg/countlock"
"github.com/minio/mc/pkg/yielder" "github.com/minio/mc/pkg/yielder"
@@ -71,8 +71,7 @@ EXAMPLES:
// doCopy - Copy a singe file from source to destination // doCopy - Copy a singe file from source to destination
func doCopy(cURLs cpURLs, bar *barSend) error { func doCopy(cURLs cpURLs, bar *barSend) error {
if !globalQuietFlag { if !globalQuietFlag {
sourceContentParse, _ := client.Parse(cURLs.SourceContent.Name) bar.SetCaption(filepath.Base(cURLs.SourceContent.Name) + ": ")
bar.SetCaption(caption{message: cURLs.SourceContent.Name + ": ", separator: sourceContentParse.Separator})
} }
reader, length, err := getSource(cURLs.SourceContent.Name) reader, length, err := getSource(cURLs.SourceContent.Name)
if err != nil { if err != nil {

View File

@@ -20,11 +20,11 @@ import (
"fmt" "fmt"
"io" "io"
"math" "math"
"path/filepath"
"runtime" "runtime"
"sync" "sync"
"github.com/minio/cli" "github.com/minio/cli"
"github.com/minio/mc/pkg/client"
"github.com/minio/mc/pkg/console" "github.com/minio/mc/pkg/console"
"github.com/minio/mc/pkg/countlock" "github.com/minio/mc/pkg/countlock"
"github.com/minio/mc/pkg/yielder" "github.com/minio/mc/pkg/yielder"
@@ -72,8 +72,7 @@ EXAMPLES:
func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, errCh chan error, wg *sync.WaitGroup) { func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, errCh chan error, wg *sync.WaitGroup) {
defer wg.Done() defer wg.Done()
if !globalQuietFlag { if !globalQuietFlag {
sourceContentParse, _ := client.Parse(sURLs.SourceContent.Name) bar.SetCaption(filepath.Base(sURLs.SourceContent.Name) + ": ")
bar.SetCaption(caption{message: sURLs.SourceContent.Name + ": ", separator: sourceContentParse.Separator})
} }
reader, length, err := getSource(sURLs.SourceContent.Name) reader, length, err := getSource(sURLs.SourceContent.Name)
if err != nil { if err != nil {

35
pb.go
View File

@@ -19,7 +19,6 @@ package main
import ( import (
"io" "io"
"runtime" "runtime"
"strings"
"sync/atomic" "sync/atomic"
"time" "time"
@@ -79,7 +78,7 @@ func (b *barSend) NewProxyReader(r io.Reader) *proxyReader {
return &proxyReader{r, b} return &proxyReader{r, b}
} }
func (b *barSend) SetCaption(c caption) { func (b *barSend) SetCaption(c string) {
b.cmdCh <- barMsg{Cmd: pbBarCmdSetCaption, Arg: c} b.cmdCh <- barMsg{Cmd: pbBarCmdSetCaption, Arg: c}
} }
@@ -96,7 +95,7 @@ func cursorAnimate() <-chan rune {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
cursors = "|/-\\" cursors = "|/-\\"
} else { } else {
cursors = "➩ ➪ ➫ ➬ ➭ ➮ ➯ ➱" cursors = "➩➪➫➬➭➮➯➱"
} }
go func() { go func() {
for { for {
@@ -108,25 +107,19 @@ func cursorAnimate() <-chan rune {
return cursorCh return cursorCh
} }
type caption struct { func fixateBarCaption(c string, s string, width int) string {
message string if len(c) > width {
separator rune
}
func fixateBarCaption(c caption, s string, width int) string {
if len(c.message) > width {
// Trim caption to fit within the screen // Trim caption to fit within the screen
trimSize := len(c.message) - width + 2 + 1 trimSize := len(c) - width + 3 + 1
if trimSize < len(c.message) { if trimSize < len(c) {
c.message = ".." + c.message[trimSize:] c = "..." + c[trimSize:]
// Further trim partial names.
partialTrimSize := strings.IndexByte(c.message, byte(c.separator))
if partialTrimSize > 0 {
c.message = c.message[partialTrimSize:]
}
} }
} }
return s + " " + c.message return s + " " + c
}
func getFixedWidth(width, percent int) int {
return width * percent / 100
} }
// newCpBar - instantiate a pbBar. // newCpBar - instantiate a pbBar.
@@ -138,7 +131,7 @@ func newCpBar() barSend {
var totalBytesRead int64 // total amounts of bytes read var totalBytesRead int64 // total amounts of bytes read
bar := pb.New64(0) bar := pb.New64(0)
bar.SetUnits(pb.U_BYTES) bar.SetUnits(pb.U_BYTES)
bar.SetRefreshRate(time.Millisecond * 10) bar.SetRefreshRate(time.Millisecond * 125)
bar.NotPrint = true bar.NotPrint = true
bar.ShowSpeed = true bar.ShowSpeed = true
bar.Callback = func(s string) { bar.Callback = func(s string) {
@@ -150,7 +143,7 @@ func newCpBar() barSend {
for msg := range cmdCh { for msg := range cmdCh {
switch msg.Cmd { switch msg.Cmd {
case pbBarCmdSetCaption: case pbBarCmdSetCaption:
bar.Prefix(fixateBarCaption(msg.Arg.(caption), string(<-cursorCh), 15)) bar.Prefix(fixateBarCaption(msg.Arg.(string), string(<-cursorCh), getFixedWidth(bar.GetWidth(), 10)))
case pbBarCmdExtend: case pbBarCmdExtend:
atomic.AddInt64(&bar.Total, msg.Arg.(int64)) atomic.AddInt64(&bar.Total, msg.Arg.(int64))
case pbBarCmdProgress: case pbBarCmdProgress: