From 51fcc45a433cdc48aea1cecd18f2d27d476100fb Mon Sep 17 00:00:00 2001 From: Tuan Anh Date: Sun, 8 Sep 2024 11:16:44 +0700 Subject: [PATCH] Update download progress bar --- examples/go.mod | 2 +- examples/go.sum | 1 + go.mod | 3 ++- go.sum | 5 +++-- telegram/downloader/parallel.go | 21 ++++++++++++++------- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/examples/go.mod b/examples/go.mod index 2d6c7e76d5..bcf0e59b71 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -49,7 +49,7 @@ require ( golang.org/x/crypto v0.26.0 // indirect golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/net v0.28.0 // indirect - golang.org/x/sys v0.23.0 // indirect + golang.org/x/sys v0.25.0 // indirect golang.org/x/text v0.17.0 // indirect google.golang.org/protobuf v1.33.0 // indirect nhooyr.io/websocket v1.8.11 // indirect diff --git a/examples/go.sum b/examples/go.sum index 5f5ad1d0ea..75a0043683 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -132,6 +132,7 @@ golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= diff --git a/go.mod b/go.mod index 6ed09bcb92..e2762a68a7 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/gotd/ige v0.2.2 github.com/gotd/neo v0.1.5 github.com/gotd/tl v0.4.0 + github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 github.com/k0kubun/pp/v3 v3.2.0 github.com/klauspost/compress v1.17.9 github.com/rogpeppe/go-internal v1.12.0 @@ -46,7 +47,7 @@ require ( github.com/sergi/go-diff v1.1.0 // indirect go.uber.org/ratelimit v0.3.1 // indirect golang.org/x/mod v0.20.0 // indirect - golang.org/x/sys v0.23.0 // indirect + golang.org/x/sys v0.25.0 // indirect golang.org/x/term v0.23.0 // indirect golang.org/x/text v0.17.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/go.sum b/go.sum index 33c7443910..5c3ccedbe6 100644 --- a/go.sum +++ b/go.sum @@ -29,6 +29,7 @@ github.com/gotd/neo v0.1.5 h1:oj0iQfMbGClP8xI59x7fE/uHoTJD7NZH9oV1WNuPukQ= github.com/gotd/neo v0.1.5/go.mod h1:9A2a4bn9zL6FADufBdt7tZt+WMhvZoc5gWXihOPoiBQ= github.com/gotd/tl v0.4.0 h1:8k2z0drujiPyhpLDa9PRm/yU1Gwlfn3iUzeInPiXwMA= github.com/gotd/tl v0.4.0/go.mod h1:CMIcjPWFS4qxxJ+1Ce7U/ilbtPrkoVo/t8uhN5Y/D7c= +github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 h1:qGQQKEcAR99REcMpsXCp3lJ03zYT1PkRd3kQGPn9GVg= github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= github.com/k0kubun/pp/v3 v3.2.0 h1:h33hNTZ9nVFNP3u2Fsgz8JXiF5JINoZfFq4SvKJwNcs= github.com/k0kubun/pp/v3 v3.2.0/go.mod h1:ODtJQbQcIRfAD3N+theGCV1m/CBxweERz2dapdz1EwA= @@ -121,8 +122,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= -golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= diff --git a/telegram/downloader/parallel.go b/telegram/downloader/parallel.go index 5199375a0b..2b2b92adff 100644 --- a/telegram/downloader/parallel.go +++ b/telegram/downloader/parallel.go @@ -2,13 +2,12 @@ package downloader import ( "context" - "fmt" "io" - "os" "sync" "time" "github.com/go-faster/errors" + "github.com/k0kubun/go-ansi" "github.com/schollz/progressbar/v3" "github.com/gotd/td/syncio" @@ -86,17 +85,25 @@ func (d *Downloader) parallel( bar := progressbar.NewOptions64( d.fileSize, progressbar.OptionSetDescription("Downloading"), - progressbar.OptionSetWriter(os.Stderr), + progressbar.OptionSetWriter(ansi.NewAnsiStdout()), + // progressbar.OptionSetWriter(os.Stderr), progressbar.OptionShowBytes(true), progressbar.OptionSetWidth(10), progressbar.OptionThrottle(65*time.Millisecond), progressbar.OptionShowCount(), progressbar.OptionEnableColorCodes(true), - progressbar.OptionOnCompletion(func() { - fmt.Fprint(os.Stderr, "\n") - }), - progressbar.OptionSpinnerType(14), + // progressbar.OptionOnCompletion(func() { + // fmt.Fprint(os.Stderr, "\n") + // }), + progressbar.OptionSpinnerType(36), progressbar.OptionSetRenderBlankState(true), + progressbar.OptionSetTheme(progressbar.Theme{ + Saucer: "[green]=[reset]", + SaucerHead: "[green]>[reset]", + SaucerPadding: " ", + BarStart: "[", + BarEnd: "]", + }), ) defer bar.Close()