summaryrefslogtreecommitdiff
path: root/src/state.c
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2009-12-25 15:00:00 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2010-02-26 13:26:16 +0000
commit69b53573907760f9ce7026ddb71e45b81eaf6af4 (patch)
tree8486a6c8c8f754c92dea2ac72880bba80a88a6ea /src/state.c
parent3f9fe4c28be7987bd404f06e27ed03aafd8e8b52 (diff)
downloadapk-tools-69b53573907760f9ce7026ddb71e45b81eaf6af4.tar.gz
apk-tools-69b53573907760f9ce7026ddb71e45b81eaf6af4.tar.bz2
apk-tools-69b53573907760f9ce7026ddb71e45b81eaf6af4.tar.xz
apk-tools-69b53573907760f9ce7026ddb71e45b81eaf6af4.zip
state: show percent in progress bar
This makes things a little bit nicer when installing from network with slow lines.
Diffstat (limited to 'src/state.c')
-rw-r--r--src/state.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/state.c b/src/state.c
index 1bd29bf..1d95f53 100644
--- a/src/state.c
+++ b/src/state.c
@@ -580,18 +580,21 @@ static void apk_count_change(struct apk_change *change, struct apk_stats *stats)
stats->packages ++;
}
-static inline void apk_draw_progress(int x, int last)
+static inline void apk_draw_progress(int percent, int last)
{
- char tmp[] =
- "-[ ]- "
- "\b\b\b\b\b\b\b\b\b\b\b\b\b"
- "\b\b\b\b\b\b\b\b\b\b\b\b";
+ char tmp[128];
+ char reset[128];
int i;
- for (i = 0; i < x; i++)
+ snprintf(tmp, sizeof(tmp), "-[ ]- %3i%%", percent);
+ for (i = 0; (i < (percent/5)) && (i < (sizeof(tmp)-2)); i++)
tmp[2+i] = '#';
-
- fwrite(tmp, last ? 25 : sizeof(tmp)-1, 1, stderr);
+ memset(reset, '\b', strlen(tmp));
+ fwrite(tmp, strlen(tmp), 1, stderr);
+ if (!last)
+ fwrite(reset, strlen(tmp), 1, stderr);
+ else if (apk_verbosity > 0)
+ fwrite("\n", 1, 1, stderr);
fflush(stderr);
}
@@ -610,7 +613,7 @@ static void progress_cb(void *ctx, size_t progress)
if (prog->pkg != NULL)
partial = muldiv(progress, prog->pkg->installed_size, APK_PROGRESS_SCALE);
- count = muldiv(20, prog->done.bytes + prog->done.packages + partial,
+ count = muldiv(100, prog->done.bytes + prog->done.packages + partial,
prog->total.bytes + prog->total.packages);
if (prog->count != count)
@@ -801,7 +804,7 @@ int apk_state_commit(struct apk_state *state,
apk_count_change(change, &prog.done);
}
if (apk_flags & APK_PROGRESS)
- apk_draw_progress(20, 1);
+ apk_draw_progress(100, 1);
update_state:
apk_db_run_triggers(db);