Skip to content

Commit 9a3d42a

Browse files
committed
fix: progressbar width
1 parent b1a3595 commit 9a3d42a

File tree

3 files changed

+74
-58
lines changed

3 files changed

+74
-58
lines changed

src/cli/cli.go

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Run() (err error) {
3636
app := cli.NewApp()
3737
app.Name = "croc"
3838
if Version == "" {
39-
Version = "v10.4.1"
39+
Version = "v10.4.2"
4040
}
4141
app.Version = Version
4242
app.Compiled = time.Now()
@@ -309,33 +309,33 @@ func send(c *cli.Context) (err error) {
309309
}
310310

311311
crocOptions := croc.Options{
312-
SharedSecret: c.String("code"),
313-
IsSender: true,
314-
Debug: c.Bool("debug"),
315-
NoPrompt: c.Bool("yes"),
316-
RelayAddress: c.String("relay"),
317-
RelayAddress6: c.String("relay6"),
318-
Stdout: c.Bool("stdout"),
319-
DisableLocal: c.Bool("no-local"),
320-
OnlyLocal: c.Bool("local"),
321-
IgnoreStdin: c.Bool("ignore-stdin"),
322-
RelayPorts: ports,
323-
Ask: c.Bool("ask"),
324-
NoMultiplexing: c.Bool("no-multi"),
325-
RelayPassword: determinePass(c),
326-
SendingText: c.String("text") != "",
327-
NoCompress: c.Bool("no-compress"),
328-
Overwrite: c.Bool("overwrite"),
329-
Curve: c.String("curve"),
330-
HashAlgorithm: c.String("hash"),
331-
ThrottleUpload: c.String("throttleUpload"),
332-
ZipFolder: c.Bool("zip"),
333-
GitIgnore: c.Bool("git"),
334-
ShowQrCode: c.Bool("qrcode"),
335-
MulticastAddress: c.String("multicast"),
336-
Exclude: excludeStrings,
337-
Quiet: c.Bool("quiet"),
338-
DisableClipboard: c.Bool("disable-clipboard"),
312+
SharedSecret: c.String("code"),
313+
IsSender: true,
314+
Debug: c.Bool("debug"),
315+
NoPrompt: c.Bool("yes"),
316+
RelayAddress: c.String("relay"),
317+
RelayAddress6: c.String("relay6"),
318+
Stdout: c.Bool("stdout"),
319+
DisableLocal: c.Bool("no-local"),
320+
OnlyLocal: c.Bool("local"),
321+
IgnoreStdin: c.Bool("ignore-stdin"),
322+
RelayPorts: ports,
323+
Ask: c.Bool("ask"),
324+
NoMultiplexing: c.Bool("no-multi"),
325+
RelayPassword: determinePass(c),
326+
SendingText: c.String("text") != "",
327+
NoCompress: c.Bool("no-compress"),
328+
Overwrite: c.Bool("overwrite"),
329+
Curve: c.String("curve"),
330+
HashAlgorithm: c.String("hash"),
331+
ThrottleUpload: c.String("throttleUpload"),
332+
ZipFolder: c.Bool("zip"),
333+
GitIgnore: c.Bool("git"),
334+
ShowQrCode: c.Bool("qrcode"),
335+
MulticastAddress: c.String("multicast"),
336+
Exclude: excludeStrings,
337+
Quiet: c.Bool("quiet"),
338+
DisableClipboard: c.Bool("disable-clipboard"),
339339
ExtendedClipboard: c.Bool("extended-clipboard"),
340340
}
341341
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
@@ -612,23 +612,23 @@ func receive(c *cli.Context) (err error) {
612612
comm.Socks5Proxy = c.String("socks5")
613613
comm.HttpProxy = c.String("connect")
614614
crocOptions := croc.Options{
615-
SharedSecret: c.String("code"),
616-
IsSender: false,
617-
Debug: c.Bool("debug"),
618-
NoPrompt: c.Bool("yes"),
619-
RelayAddress: c.String("relay"),
620-
RelayAddress6: c.String("relay6"),
621-
Stdout: c.Bool("stdout"),
622-
Ask: c.Bool("ask"),
623-
RelayPassword: determinePass(c),
624-
OnlyLocal: c.Bool("local"),
625-
IP: c.String("ip"),
626-
Overwrite: c.Bool("overwrite"),
627-
Curve: c.String("curve"),
628-
TestFlag: c.Bool("testing"),
629-
MulticastAddress: c.String("multicast"),
630-
Quiet: c.Bool("quiet"),
631-
DisableClipboard: c.Bool("disable-clipboard"),
615+
SharedSecret: c.String("code"),
616+
IsSender: false,
617+
Debug: c.Bool("debug"),
618+
NoPrompt: c.Bool("yes"),
619+
RelayAddress: c.String("relay"),
620+
RelayAddress6: c.String("relay6"),
621+
Stdout: c.Bool("stdout"),
622+
Ask: c.Bool("ask"),
623+
RelayPassword: determinePass(c),
624+
OnlyLocal: c.Bool("local"),
625+
IP: c.String("ip"),
626+
Overwrite: c.Bool("overwrite"),
627+
Curve: c.String("curve"),
628+
TestFlag: c.Bool("testing"),
629+
MulticastAddress: c.String("multicast"),
630+
Quiet: c.Bool("quiet"),
631+
DisableClipboard: c.Bool("disable-clipboard"),
632632
ExtendedClipboard: c.Bool("extended-clipboard"),
633633
}
634634
if crocOptions.RelayAddress != models.DEFAULT_RELAY {

src/croc/croc.go

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,21 +1798,37 @@ func (c *Client) recipientGetFileReady(finished bool) (err error) {
17981798
return
17991799
}
18001800

1801-
func max(a int, b int) int {
1802-
if a > b {
1803-
return a
1801+
func formatDescription(description string) string {
1802+
const (
1803+
// Reserve extra room for variable progress metadata such as [elapsed:remaining].
1804+
progressMetaWidth = 78
1805+
minDescription = 12
1806+
defaultTermWidth = 80
1807+
)
1808+
1809+
width, _, err := term.GetSize(int(os.Stderr.Fd()))
1810+
if err != nil || width <= 0 {
1811+
width, _, err = term.GetSize(int(os.Stdout.Fd()))
1812+
}
1813+
if err != nil || width <= 0 {
1814+
if envColumns, convErr := strconv.Atoi(os.Getenv("COLUMNS")); convErr == nil && envColumns > 0 {
1815+
width = envColumns
1816+
} else {
1817+
width = defaultTermWidth
1818+
}
18041819
}
1805-
return b
1806-
}
18071820

1808-
func formatDescription(description string) string {
1809-
width, _, err := term.GetSize(int(os.Stdout.Fd()))
1810-
width = max(20, width-60)
1811-
if err != nil {
1812-
return description
1821+
maxDescription := width - progressMetaWidth
1822+
if maxDescription < minDescription {
1823+
maxDescription = minDescription
18131824
}
1814-
if len(description) > width {
1815-
description = description[:(width-3)] + "..."
1825+
1826+
runes := []rune(description)
1827+
if len(runes) > maxDescription {
1828+
if maxDescription <= 3 {
1829+
return string(runes[:maxDescription])
1830+
}
1831+
return string(runes[:maxDescription-3]) + "..."
18161832
}
18171833
return description
18181834
}

src/install/default.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ main() {
554554
local autocomplete_install_rcode
555555

556556
croc_bin_name="croc"
557-
croc_version="10.4.1"
557+
croc_version="10.4.2"
558558
croc_dl_ext="tar.gz"
559559
croc_base_url="https://github.com/schollz/croc/releases/download"
560560
prefix="${1}"

0 commit comments

Comments
 (0)