mirror of
https://github.com/schollz/croc.git
synced 2024-11-24 08:02:33 +03:00
pad filenames according to longest filename
This commit is contained in:
parent
810a04509a
commit
af39b8ca14
@ -89,9 +89,10 @@ type Client struct {
|
|||||||
// tcp connections
|
// tcp connections
|
||||||
conn []*comm.Comm
|
conn []*comm.Comm
|
||||||
|
|
||||||
bar *progressbar.ProgressBar
|
bar *progressbar.ProgressBar
|
||||||
spinner *spinner.Spinner
|
spinner *spinner.Spinner
|
||||||
firstSend bool
|
longestFilename int
|
||||||
|
firstSend bool
|
||||||
|
|
||||||
mutex *sync.Mutex
|
mutex *sync.Mutex
|
||||||
fread *os.File
|
fread *os.File
|
||||||
@ -185,6 +186,9 @@ func (c *Client) sendCollectFiles(options TransferOptions) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if len(fstats.Name()) > c.longestFilename {
|
||||||
|
c.longestFilename = len(fstats.Name())
|
||||||
|
}
|
||||||
c.FilesToTransfer[i] = FileInfo{
|
c.FilesToTransfer[i] = FileInfo{
|
||||||
Name: fstats.Name(),
|
Name: fstats.Name(),
|
||||||
FolderRemote: ".",
|
FolderRemote: ".",
|
||||||
@ -220,6 +224,7 @@ func (c *Client) sendCollectFiles(options TransferOptions) (err error) {
|
|||||||
}
|
}
|
||||||
log.Debugf("file %d info: %+v", i, c.FilesToTransfer[i])
|
log.Debugf("file %d info: %+v", i, c.FilesToTransfer[i])
|
||||||
}
|
}
|
||||||
|
log.Debugf("longestFilename: %+v", c.longestFilename)
|
||||||
fname := fmt.Sprintf("%d files", len(c.FilesToTransfer))
|
fname := fmt.Sprintf("%d files", len(c.FilesToTransfer))
|
||||||
if len(c.FilesToTransfer) == 1 {
|
if len(c.FilesToTransfer) == 1 {
|
||||||
fname = fmt.Sprintf("'%s'", c.FilesToTransfer[0].Name)
|
fname = fmt.Sprintf("'%s'", c.FilesToTransfer[0].Name)
|
||||||
@ -509,6 +514,9 @@ func (c *Client) processMessageFileInfo(m message.Message) (done bool, err error
|
|||||||
totalSize := int64(0)
|
totalSize := int64(0)
|
||||||
for _, fi := range c.FilesToTransfer {
|
for _, fi := range c.FilesToTransfer {
|
||||||
totalSize += fi.Size
|
totalSize += fi.Size
|
||||||
|
if len(fi.Name) > c.longestFilename {
|
||||||
|
c.longestFilename = len(fi.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// c.spinner.Stop()
|
// c.spinner.Stop()
|
||||||
if !c.Options.NoPrompt {
|
if !c.Options.NoPrompt {
|
||||||
@ -817,7 +825,7 @@ func (c *Client) createEmptyFileAndFinish(fileInfo FileInfo, i int) (err error)
|
|||||||
}
|
}
|
||||||
emptyFile.Close()
|
emptyFile.Close()
|
||||||
// setup the progressbar
|
// 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 {
|
if len(c.FilesToTransfer) == 1 {
|
||||||
description = c.FilesToTransfer[i].Name
|
description = c.FilesToTransfer[i].Name
|
||||||
}
|
}
|
||||||
@ -900,7 +908,7 @@ func (c *Client) updateState() (err error) {
|
|||||||
for i := range c.FilesToTransfer {
|
for i := range c.FilesToTransfer {
|
||||||
if c.FilesToTransfer[i].Size == 0 {
|
if c.FilesToTransfer[i].Size == 0 {
|
||||||
// setup the progressbar and takedown the progress bar for empty files
|
// 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 {
|
if len(c.FilesToTransfer) == 1 {
|
||||||
description = c.FilesToTransfer[i].Name
|
description = c.FilesToTransfer[i].Name
|
||||||
}
|
}
|
||||||
@ -942,7 +950,7 @@ func (c *Client) updateState() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) setBar() {
|
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 {
|
if len(c.FilesToTransfer) == 1 {
|
||||||
description = c.FilesToTransfer[c.FilesToTransferCurrentNum].Name
|
description = c.FilesToTransfer[c.FilesToTransferCurrentNum].Name
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user