From c8fdd4726a4a415be40241544bb1bb1c972ee4a8 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 30 Apr 2019 09:24:32 -0700 Subject: [PATCH] simplify ui --- src/croc/croc.go | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/croc/croc.go b/src/croc/croc.go index bf5fe734..e5530366 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -506,19 +506,7 @@ func (c *Client) updateState() (err error) { } // setup the progressbar - c.bar = progressbar.NewOptions64( - c.FilesToTransfer[c.FilesToTransferCurrentNum].Size, - progressbar.OptionOnCompletion(func() { - fmt.Fprintf(os.Stderr, " ✔️\n") - }), - progressbar.OptionSetWidth(8), - progressbar.OptionSetDescription(fmt.Sprintf("%28s", c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)), - progressbar.OptionSetRenderBlankState(true), - progressbar.OptionSetBytes64(c.FilesToTransfer[c.FilesToTransferCurrentNum].Size), - progressbar.OptionSetWriter(os.Stderr), - progressbar.OptionThrottle(100*time.Millisecond), - ) - c.bar.Add(len(c.CurrentFileChunks) * models.TCP_BUFFER_SIZE / 2) + c.setBar() c.TotalSent = 0 bRequest, _ := json.Marshal(RemoteFileRequest{ CurrentFileChunks: c.CurrentFileChunks, @@ -537,19 +525,7 @@ func (c *Client) updateState() (err error) { log.Debug("start sending data!") c.Step4FileTransfer = true // setup the progressbar - c.bar = progressbar.NewOptions64( - c.FilesToTransfer[c.FilesToTransferCurrentNum].Size, - progressbar.OptionOnCompletion(func() { - fmt.Fprintf(os.Stderr, " ✔️\n") - }), - progressbar.OptionSetWidth(8), - progressbar.OptionSetDescription(fmt.Sprintf("%28s", c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)), - progressbar.OptionSetRenderBlankState(true), - progressbar.OptionSetBytes64(c.FilesToTransfer[c.FilesToTransferCurrentNum].Size), - progressbar.OptionSetWriter(os.Stderr), - progressbar.OptionThrottle(100*time.Millisecond), - ) - c.bar.Add(len(c.CurrentFileChunks) * models.TCP_BUFFER_SIZE / 2) + c.setBar() c.TotalSent = 0 for i := 1; i < len(c.Options.RelayPorts); i++ { go c.sendData(i) @@ -558,6 +534,26 @@ func (c *Client) updateState() (err error) { return } +func (c *Client) setBar() { + description := fmt.Sprintf("%28s", c.FilesToTransfer[c.FilesToTransferCurrentNum].Name) + if len(c.FilesToTransfer) == 1 { + description = c.FilesToTransfer[c.FilesToTransferCurrentNum].Name + } + c.bar = progressbar.NewOptions64( + c.FilesToTransfer[c.FilesToTransferCurrentNum].Size, + progressbar.OptionOnCompletion(func() { + fmt.Fprintf(os.Stderr, " ✔️\n") + }), + progressbar.OptionSetWidth(8), + progressbar.OptionSetDescription(description), + progressbar.OptionSetRenderBlankState(true), + progressbar.OptionSetBytes64(c.FilesToTransfer[c.FilesToTransferCurrentNum].Size), + progressbar.OptionSetWriter(os.Stderr), + progressbar.OptionThrottle(100*time.Millisecond), + ) + c.bar.Add(len(c.CurrentFileChunks) * models.TCP_BUFFER_SIZE / 2) +} + func (c *Client) receiveData(i int) { for { log.Debug("waiting for data")