Skip to content

Commit

Permalink
customize download bar
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewedy committed May 8, 2020
1 parent a1de3c6 commit ec9f2c9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ func download(r *dbImage) error {
}
defer resp.Body.Close()

bar := progressbar.DefaultBytes(
resp.ContentLength,
"Downloading",
)
bar := buildDownloadBar(resp)

if _, err = io.Copy(io.MultiWriter(tmpFile, bar), resp.Body); err != nil {
return err
}
Expand All @@ -131,6 +129,16 @@ func download(r *dbImage) error {
return nil
}

func buildDownloadBar(resp *http.Response) *progressbar.ProgressBar {
bar := progressbar.DefaultBytes(
resp.ContentLength,
"Downloading",
)
progressbar.OptionSetTheme(progressbar.Theme{
Saucer: "#", SaucerPadding: ".", BarStart: "[", BarEnd: "]"})(bar)
return bar
}

func contains(a []string, s string) bool {
for i := range a {
if a[i] == s {
Expand Down

0 comments on commit ec9f2c9

Please sign in to comment.