aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2011-03-16 15:22:05 +0200
committerTimo Teräs <timo.teras@iki.fi>2011-03-16 15:22:05 +0200
commit20775276b934418ba451f76c9c8a24418201fa66 (patch)
treebf5551aded838ae3a8c739e7d990a29dfb012d1d
parent5d64bc5d8c7cdd2759e970f848e948fac9cc9577 (diff)
downloadaports-20775276b934418ba451f76c9c8a24418201fa66.tar.bz2
aports-20775276b934418ba451f76c9c8a24418201fa66.tar.xz
apk: show progress bar by default for tty controlled runs
and make the progress bar disappear on regular runs too.
-rw-r--r--src/apk.c8
-rw-r--r--src/state.c11
2 files changed, 12 insertions, 7 deletions
diff --git a/src/apk.c b/src/apk.c
index 4b97be5005..e8b8b12814 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -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;
diff --git a/src/state.c b/src/state.c
index 4a4641d87d..7991802778 100644
--- a/src/state.c
+++ b/src/state.c
@@ -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);