Skip to content

Commit

Permalink
pad filenames according to longest filename
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Oct 7, 2019
1 parent 810a045 commit af39b8c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/croc/croc.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ type Client struct {
// tcp connections
conn []*comm.Comm

bar *progressbar.ProgressBar
spinner *spinner.Spinner
firstSend bool
bar *progressbar.ProgressBar
spinner *spinner.Spinner
longestFilename int
firstSend bool

mutex *sync.Mutex
fread *os.File
Expand Down Expand Up @@ -185,6 +186,9 @@ func (c *Client) sendCollectFiles(options TransferOptions) (err error) {
if err != nil {
return
}
if len(fstats.Name()) > c.longestFilename {
c.longestFilename = len(fstats.Name())
}
c.FilesToTransfer[i] = FileInfo{
Name: fstats.Name(),
FolderRemote: ".",
Expand Down Expand Up @@ -220,6 +224,7 @@ func (c *Client) sendCollectFiles(options TransferOptions) (err error) {
}
log.Debugf("file %d info: %+v", i, c.FilesToTransfer[i])
}
log.Debugf("longestFilename: %+v", c.longestFilename)
fname := fmt.Sprintf("%d files", len(c.FilesToTransfer))
if len(c.FilesToTransfer) == 1 {
fname = fmt.Sprintf("'%s'", c.FilesToTransfer[0].Name)
Expand Down Expand Up @@ -509,6 +514,9 @@ func (c *Client) processMessageFileInfo(m message.Message) (done bool, err error
totalSize := int64(0)
for _, fi := range c.FilesToTransfer {
totalSize += fi.Size
if len(fi.Name) > c.longestFilename {
c.longestFilename = len(fi.Name)
}
}
// c.spinner.Stop()
if !c.Options.NoPrompt {
Expand Down Expand Up @@ -817,7 +825,7 @@ func (c *Client) createEmptyFileAndFinish(fileInfo FileInfo, i int) (err error)
}
emptyFile.Close()
// setup the progressbar
description := fmt.Sprintf("%-28s", c.FilesToTransfer[i].Name)
description := fmt.Sprintf("%-*s", c.longestFilename, c.FilesToTransfer[i].Name)
if len(c.FilesToTransfer) == 1 {
description = c.FilesToTransfer[i].Name
}
Expand Down Expand Up @@ -900,7 +908,7 @@ func (c *Client) updateState() (err error) {
for i := range c.FilesToTransfer {
if c.FilesToTransfer[i].Size == 0 {
// setup the progressbar and takedown the progress bar for empty files
description := fmt.Sprintf("%-28s", c.FilesToTransfer[i].Name)
description := fmt.Sprintf("%-*s", c.longestFilename, c.FilesToTransfer[i].Name)
if len(c.FilesToTransfer) == 1 {
description = c.FilesToTransfer[i].Name
}
Expand Down Expand Up @@ -942,7 +950,7 @@ func (c *Client) updateState() (err error) {
}

func (c *Client) setBar() {
description := fmt.Sprintf("%-28s", c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
description := fmt.Sprintf("%-*s", c.longestFilename, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
if len(c.FilesToTransfer) == 1 {
description = c.FilesToTransfer[c.FilesToTransferCurrentNum].Name
}
Expand Down

0 comments on commit af39b8c

Please sign in to comment.