summaryrefslogtreecommitdiff
path: root/src/apk.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2011-03-19 15:20:47 +0200
committerTimo Teräs <timo.teras@iki.fi>2011-03-19 15:20:47 +0200
commit116d9a0ea7a5e903a344f7e6044dd019349bc01c (patch)
tree01eca1b5db71ffca39bc07951f9e0eaf17cc34e8 /src/apk.c
parent7b6e44b11b4b419a6af91555270b1ddc981c5a74 (diff)
downloadapk-tools-116d9a0ea7a5e903a344f7e6044dd019349bc01c.tar.gz
apk-tools-116d9a0ea7a5e903a344f7e6044dd019349bc01c.tar.bz2
apk-tools-116d9a0ea7a5e903a344f7e6044dd019349bc01c.tar.xz
apk-tools-116d9a0ea7a5e903a344f7e6044dd019349bc01c.zip
apk: improve progress bar
* make it as wide as the screen * make sure it's drawn after package change * and draw it using ansi escapes in line buffered stderr
Diffstat (limited to 'src/apk.c')
-rw-r--r--src/apk.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/apk.c b/src/apk.c
index e8b8b12..55963b0 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -19,6 +19,7 @@
#include <getopt.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <sys/ioctl.h>
#include <openssl/crypto.h>
#ifndef OPENSSL_NO_ENGINE
@@ -32,6 +33,7 @@
#include "apk_print.h"
char **apk_argv;
+int apk_screen_width;
static struct apk_option generic_options[] = {
{ 'h', "help", "Show generic help or applet specific help" },
@@ -238,6 +240,20 @@ static void init_openssl(void)
#endif
}
+static void setup_terminal(void)
+{
+ struct winsize w;
+
+ setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
+ if (ioctl(STDERR_FILENO,TIOCGWINSZ, &w) == 0)
+ apk_screen_width = w.ws_col;
+ else
+ apk_screen_width = 70;
+ if (isatty(STDOUT_FILENO) && isatty(STDERR_FILENO) && isatty(STDIN_FILENO))
+ apk_flags |= APK_PROGRESS;
+
+}
+
int main(int argc, char **argv)
{
struct apk_applet *applet;
@@ -257,9 +273,7 @@ int main(int argc, char **argv)
list_init(&dbopts.repository_list);
apk_atom_init();
umask(0);
-
- if (isatty(STDOUT_FILENO) && isatty(STDERR_FILENO) && isatty(STDIN_FILENO))
- apk_flags |= APK_PROGRESS;
+ setup_terminal();
applet = deduce_applet(argc, argv);
num_options = ARRAY_SIZE(generic_options) + 1;