From adc5b0b16127049307283b9b59d7f0705ba8adc2 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 19 Jun 2013 08:47:09 +0000 Subject: print: move progress bar update logic to apk_print_progress - let the apk_print functions deal with the forced print itself. We avoid that the callbacks need to deal with the force flag. We can also get rid of the APK_PRINT_PROGRESS_* defines. - let the reader of --progress-fd decide how often things are updated rather than having a fixed granularity off 1/100 (percent) - avoid detect screen size and percent/bar calculations in case the --no-progress was given - track satistics for both the ascii bar and percent info and update bar only if either percent or bar changes. This makes the bar go smoother when width is wider than 100 chars and it makes the percent counter go smooth when screen width is less thann 100 chars. It also simplifies the callbacks as they no longer need to deal with update granularity. --- src/cache.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/cache.c') diff --git a/src/cache.c b/src/cache.c index 84b2786..3be5b6d 100644 --- a/src/cache.c +++ b/src/cache.c @@ -28,14 +28,12 @@ struct progress { size_t done, total; - int flags; }; static void progress_cb(void *ctx, size_t bytes_done) { struct progress *prog = (struct progress *) ctx; - apk_print_progress(muldiv(100, prog->done + bytes_done, prog->total) | prog->flags); - prog->flags = 0; + apk_print_progress(prog->done + bytes_done, prog->total); } static int cache_download(struct apk_database *db) @@ -68,7 +66,6 @@ static int cache_download(struct apk_database *db) if (repo == NULL) continue; - prog.flags = APK_PRINT_PROGRESS_FORCE; r = apk_cache_download(db, repo, pkg, APK_SIGN_VERIFY_IDENTITY, progress_cb, &prog); if (r) { -- cgit v1.2.3-70-g09d2