Commit 20775276 authored by Timo Teräs's avatar Timo Teräs

apk: show progress bar by default for tty controlled runs

and make the progress bar disappear on regular runs too.
parent 5d64bc5d
......@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/stat.h>
#include <openssl/crypto.h>
......@@ -45,6 +46,7 @@ static struct apk_option generic_options[] = {
{ 'f', "force", "Do what was asked even if it looks dangerous" },
{ 'U', "update-cache", "Update the repository cache" },
{ 0x101, "progress", "Show a progress bar" },
{ 0x110, "no-progress", "Disable progress bar even for TTYs" },
{ 0x102, "clean-protected", "Do not create .apk-new files to "
"configuration dirs" },
{ 0x106, "purge", "Delete also modified configuration files on "
......@@ -256,6 +258,9 @@ int main(int argc, char **argv)
apk_atom_init();
umask(0);
if (isatty(STDOUT_FILENO) && isatty(STDERR_FILENO) && isatty(STDIN_FILENO))
apk_flags |= APK_PROGRESS;
applet = deduce_applet(argc, argv);
num_options = ARRAY_SIZE(generic_options) + 1;
if (applet != NULL)
......@@ -326,6 +331,9 @@ int main(int argc, char **argv)
case 0x101:
apk_flags |= APK_PROGRESS;
break;
case 0x110:
apk_flags &= ~APK_PROGRESS;
break;
case 0x102:
apk_flags |= APK_CLEAN_PROTECTED;
break;
......
......@@ -655,7 +655,7 @@ static void apk_count_change(struct apk_change *change, struct apk_stats *stats)
stats->packages ++;
}
static inline void apk_draw_progress(int percent, int last)
static inline void apk_draw_progress(int percent)
{
char tmp[128];
char reset[128];
......@@ -666,10 +666,7 @@ static inline void apk_draw_progress(int percent, int last)
tmp[2+i] = '#';
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);
fwrite(reset, strlen(tmp), 1, stderr);
fflush(stderr);
}
......@@ -692,7 +689,7 @@ static void progress_cb(void *ctx, size_t progress)
prog->total.bytes + prog->total.packages);
if (prog->count != count)
apk_draw_progress(count, 0);
apk_draw_progress(count);
prog->count = count;
}
......@@ -961,7 +958,7 @@ int apk_state_commit(struct apk_state *state,
apk_count_change(change, &prog.done);
}
if (apk_flags & APK_PROGRESS)
apk_draw_progress(100, 1);
apk_draw_progress(100);
update_state:
apk_db_run_triggers(db);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment