diff --git a/app/chat/export.go b/app/chat/export.go index 384dd1bac8..a8a5387993 100644 --- a/app/chat/export.go +++ b/app/chat/export.go @@ -9,7 +9,6 @@ import ( "github.com/antonmedv/expr" "github.com/fatih/color" - "github.com/go-faster/errors" "github.com/go-faster/jx" "github.com/gotd/contrib/middleware/ratelimit" "github.com/gotd/td/telegram/peers" @@ -104,10 +103,7 @@ func Export(ctx context.Context, opts *ExportOptions) error { color.Blue("Type: %s | Input: %v", opts.Type, opts.Input) - pw, err := prog.New(progress.FormatNumber) - if err != nil { - return errors.Wrap(err, "create progress") - } + pw := prog.New(progress.FormatNumber) pw.SetUpdateFrequency(200 * time.Millisecond) pw.Style().Visibility.TrackerOverall = false pw.Style().Visibility.ETA = false diff --git a/app/chat/users.go b/app/chat/users.go index 0078503d77..8205571c32 100644 --- a/app/chat/users.go +++ b/app/chat/users.go @@ -77,10 +77,7 @@ func Users(ctx context.Context, opts UsersOptions) error { defer enc.ObjEnd() enc.Field("id", func(e *jx.Encoder) { e.Int64(peer.ID()) }) - pw, err := prog.New(progress.FormatNumber) - if err != nil { - return errors.Wrap(err, "create progress") - } + pw := prog.New(progress.FormatNumber) pw.SetUpdateFrequency(200 * time.Millisecond) pw.Style().Visibility.TrackerOverall = false pw.Style().Visibility.ETA = true diff --git a/pkg/downloader/downloader.go b/pkg/downloader/downloader.go index e1b9c89aa7..7758f4431f 100644 --- a/pkg/downloader/downloader.go +++ b/pkg/downloader/downloader.go @@ -43,13 +43,8 @@ type Options struct { } func New(opts Options) (*Downloader, error) { - pw, err := prog.New(formatter) - if err != nil { - return nil, errors.Wrap(err, "create progress") - } - return &Downloader{ - pw: pw, + pw: prog.New(formatter), opts: opts, }, nil } diff --git a/pkg/prog/prog.go b/pkg/prog/prog.go index 5decb86b25..9be277fd65 100644 --- a/pkg/prog/prog.go +++ b/pkg/prog/prog.go @@ -4,21 +4,19 @@ import ( "time" "github.com/fatih/color" - "github.com/go-faster/errors" "github.com/jedib0t/go-pretty/v6/progress" "github.com/jedib0t/go-pretty/v6/text" tsize "github.com/kopoli/go-terminal-size" ) -func New(formatter progress.UnitsFormatter) (progress.Writer, error) { +func New(formatter progress.UnitsFormatter) progress.Writer { pw := progress.NewWriter() pw.SetAutoStop(false) - size, err := tsize.GetSize() - if err != nil { - return nil, errors.Wrap(err, "get terminal size") + width := 50 + if size, err := tsize.GetSize(); err == nil { + width = size.Width } - width := size.Width if width > 100 { width = 100 } @@ -41,7 +39,7 @@ func New(formatter progress.UnitsFormatter) (progress.Writer, error) { pw.Style().Options.ErrorString = color.RedString("failed!") pw.Style().Options.DoneString = color.GreenString("done!") - return pw, nil + return pw } func Wait(pw progress.Writer) { diff --git a/pkg/uploader/uploader.go b/pkg/uploader/uploader.go index d426f2627d..899a575fc1 100644 --- a/pkg/uploader/uploader.go +++ b/pkg/uploader/uploader.go @@ -39,10 +39,7 @@ type Options struct { } func New(o Options) (*Uploader, error) { - pw, err := prog.New(formatter) - if err != nil { - return nil, errors.Wrap(err, "create progress") - } + pw := prog.New(formatter) return &Uploader{ pw: pw,