1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 05:11:06 +02:00

use term.GetSize

This commit is contained in:
Asuka Minato 2024-08-31 00:08:25 +09:00
parent 01609df902
commit bc9dbfd905

View file

@ -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"
@ -1735,8 +1736,9 @@ 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] + "..." 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 +1916,10 @@ func (c *Client) setBar() {
} else if !c.Options.IsSender { } else if !c.Options.IsSender {
description = " " + description description = " " + description
} }
if len(description) > 20 { width, _, _ := term.GetSize(int(os.Stdout.Fd()))
description = description[:17] + "..." 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,