1
0
mirror of https://github.com/minio/mc.git synced 2025-11-14 23:42:27 +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"
"io"
"math"
"path/filepath"
"runtime"
"sync"
"github.com/minio/cli"
"github.com/minio/mc/pkg/client"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/pkg/countlock"
"github.com/minio/mc/pkg/yielder"
@@ -71,8 +71,7 @@ EXAMPLES:
// doCopy - Copy a singe file from source to destination
func doCopy(cURLs cpURLs, bar *barSend) error {
if !globalQuietFlag {
sourceContentParse, _ := client.Parse(cURLs.SourceContent.Name)
bar.SetCaption(caption{message: cURLs.SourceContent.Name + ": ", separator: sourceContentParse.Separator})
bar.SetCaption(filepath.Base(cURLs.SourceContent.Name) + ": ")
}
reader, length, err := getSource(cURLs.SourceContent.Name)
if err != nil {

View File

@@ -20,11 +20,11 @@ import (
"fmt"
"io"
"math"
"path/filepath"
"runtime"
"sync"
"github.com/minio/cli"
"github.com/minio/mc/pkg/client"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/pkg/countlock"
"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) {
defer wg.Done()
if !globalQuietFlag {
sourceContentParse, _ := client.Parse(sURLs.SourceContent.Name)
bar.SetCaption(caption{message: sURLs.SourceContent.Name + ": ", separator: sourceContentParse.Separator})
bar.SetCaption(filepath.Base(sURLs.SourceContent.Name) + ": ")
}
reader, length, err := getSource(sURLs.SourceContent.Name)
if err != nil {

35
pb.go
View File

@@ -19,7 +19,6 @@ package main
import (
"io"
"runtime"
"strings"
"sync/atomic"
"time"
@@ -79,7 +78,7 @@ func (b *barSend) NewProxyReader(r io.Reader) *proxyReader {
return &proxyReader{r, b}
}
func (b *barSend) SetCaption(c caption) {
func (b *barSend) SetCaption(c string) {
b.cmdCh <- barMsg{Cmd: pbBarCmdSetCaption, Arg: c}
}
@@ -108,25 +107,19 @@ func cursorAnimate() <-chan rune {
return cursorCh
}
type caption struct {
message string
separator rune
func fixateBarCaption(c string, s string, width int) string {
if len(c) > width {
// Trim caption to fit within the screen
trimSize := len(c) - width + 3 + 1
if trimSize < len(c) {
c = "..." + c[trimSize:]
}
}
return s + " " + c
}
func fixateBarCaption(c caption, s string, width int) string {
if len(c.message) > width {
// Trim caption to fit within the screen
trimSize := len(c.message) - width + 2 + 1
if trimSize < len(c.message) {
c.message = ".." + c.message[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
func getFixedWidth(width, percent int) int {
return width * percent / 100
}
// newCpBar - instantiate a pbBar.
@@ -138,7 +131,7 @@ func newCpBar() barSend {
var totalBytesRead int64 // total amounts of bytes read
bar := pb.New64(0)
bar.SetUnits(pb.U_BYTES)
bar.SetRefreshRate(time.Millisecond * 10)
bar.SetRefreshRate(time.Millisecond * 125)
bar.NotPrint = true
bar.ShowSpeed = true
bar.Callback = func(s string) {
@@ -150,7 +143,7 @@ func newCpBar() barSend {
for msg := range cmdCh {
switch msg.Cmd {
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:
atomic.AddInt64(&bar.Total, msg.Arg.(int64))
case pbBarCmdProgress: