mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 05:11:06 +02:00
Merge pull request #794 from asukaminato0721/term.GetSize
use term.GetSize
This commit is contained in:
commit
0017def27c
1 changed files with 22 additions and 5 deletions
|
@ -19,6 +19,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/term"
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
|
|
||||||
"github.com/denisbrodbeck/machineid"
|
"github.com/denisbrodbeck/machineid"
|
||||||
|
@ -1697,7 +1698,12 @@ func (c *Client) recipientGetFileReady(finished bool) (err error) {
|
||||||
c.Step3RecipientRequestFile = true
|
c.Step3RecipientRequestFile = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
func max(a int, b int) int {
|
||||||
|
if a > b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
func (c *Client) createEmptyFileAndFinish(fileInfo FileInfo, i int) (err error) {
|
func (c *Client) createEmptyFileAndFinish(fileInfo FileInfo, i int) (err error) {
|
||||||
log.Debugf("touching file with folder / name")
|
log.Debugf("touching file with folder / name")
|
||||||
if !utils.Exists(fileInfo.FolderRemote) {
|
if !utils.Exists(fileInfo.FolderRemote) {
|
||||||
|
@ -1735,8 +1741,13 @@ func (c *Client) createEmptyFileAndFinish(fileInfo FileInfo, i int) (err error)
|
||||||
} else {
|
} else {
|
||||||
description = " " + description
|
description = " " + description
|
||||||
}
|
}
|
||||||
if len(description) > 20 {
|
width, _, err := term.GetSize(int(os.Stdout.Fd()))
|
||||||
description = description[:17] + "..."
|
width = max(20, width-70)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(description) > width {
|
||||||
|
description = description[:(width-3)] + "..."
|
||||||
}
|
}
|
||||||
c.bar = progressbar.NewOptions64(1,
|
c.bar = progressbar.NewOptions64(1,
|
||||||
progressbar.OptionOnCompletion(func() {
|
progressbar.OptionOnCompletion(func() {
|
||||||
|
@ -1914,8 +1925,14 @@ func (c *Client) setBar() {
|
||||||
} else if !c.Options.IsSender {
|
} else if !c.Options.IsSender {
|
||||||
description = " " + description
|
description = " " + description
|
||||||
}
|
}
|
||||||
if len(description) > 20 {
|
width, _, err := term.GetSize(int(os.Stdout.Fd()))
|
||||||
description = description[:17] + "..."
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
width = max(20, width-70)
|
||||||
|
description = strings.TrimSpace(description)
|
||||||
|
if len(description) > width {
|
||||||
|
description = description[:width-3] + "..."
|
||||||
}
|
}
|
||||||
c.bar = progressbar.NewOptions64(
|
c.bar = progressbar.NewOptions64(
|
||||||
c.FilesToTransfer[c.FilesToTransferCurrentNum].Size,
|
c.FilesToTransfer[c.FilesToTransferCurrentNum].Size,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue