File tree 4 files changed +26
-6
lines changed
4 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,10 @@ import (
4
4
"flag"
5
5
"fmt"
6
6
"log"
7
+ "os"
7
8
"time"
8
9
10
+ "github.com/apoorvam/goterminal"
9
11
"github.com/dustin/go-humanize"
10
12
"github.com/melbahja/got"
11
13
)
@@ -58,24 +60,33 @@ func main() {
58
60
log .Fatal (err )
59
61
}
60
62
63
+ // Goterm writer.
64
+ writer := goterminal .New (os .Stdout )
65
+
61
66
// Set progress func to update cli output.
62
67
d .Progress .ProgressFunc = func (p * got.Progress , d * got.Download ) {
63
68
64
- fmt . Printf (
65
- " \r \r \b Total: %s | Chunk: %s | Concurrency: %d | Received: %s | Time: %s | Avg: %s/s | Speed: %s/s" ,
66
- humanize . Bytes ( p . TotalSize ),
67
- humanize . Bytes ( d . ChunkSize ) ,
68
- d . Concurrency ,
69
+ writer . Clear ()
70
+
71
+ fmt . Fprintf (
72
+ writer ,
73
+ "Downloading: (%s/%s) | Time: %s | Avg: %s/s | Speed: %s/s | Chunk: %s | Concurrency: %d \n " ,
69
74
humanize .Bytes (p .Size ),
75
+ humanize .Bytes (p .TotalSize ),
70
76
p .TotalCost ().Round (time .Second ),
71
77
humanize .Bytes (p .AvgSpeed ()),
72
78
humanize .Bytes (p .Speed ()),
79
+ humanize .Bytes (d .ChunkSize ),
80
+ d .Concurrency ,
73
81
)
82
+
83
+ writer .Print ()
74
84
}
75
85
76
86
if err := d .Start (); err != nil {
77
87
log .Fatal (err )
78
88
}
79
89
80
- fmt .Println (" | Done!" )
90
+ writer .Reset ()
91
+ fmt .Println ("Done!" )
81
92
}
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ module github.com/melbahja/got
3
3
go 1.14
4
4
5
5
require (
6
+ github.com/apoorvam/goterminal v0.0.0-20180523175556-614d345c47e5
6
7
github.com/dustin/go-humanize v1.0.0
8
+ github.com/mattn/go-isatty v0.0.12 // indirect
7
9
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
8
10
)
Original file line number Diff line number Diff line change
1
+ github.com/apoorvam/goterminal v0.0.0-20180523175556-614d345c47e5 h1:VYqcjykqpcq262cDxBAkAelSdg6HETkxgwzQRTS40Aw =
2
+ github.com/apoorvam/goterminal v0.0.0-20180523175556-614d345c47e5 /go.mod h1:E7x8aDc3AQzDKjEoIZCt+XYheHk2OkP+p2UgeNjecH8 =
1
3
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo =
2
4
github.com/dustin/go-humanize v1.0.0 /go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk =
5
+ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY =
6
+ github.com/mattn/go-isatty v0.0.12 /go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU =
3
7
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA =
4
8
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 /go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM =
9
+ golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg =
10
+ golang.org/x/sys v0.0.0-20200116001909-b77594299b42 /go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs =
Original file line number Diff line number Diff line change @@ -287,6 +287,7 @@ func (d *Download) GetInfo() (Info, error) {
287
287
288
288
// Merge downloaded chunks.
289
289
func (d * Download ) merge (ctx context.Context ) error {
290
+
290
291
file , err := os .Create (d .Dest )
291
292
if err != nil {
292
293
return err
You can’t perform that action at this time.
0 commit comments