summaryrefslogtreecommitdiff
path: root/src/apk.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2011-07-22 12:08:35 +0300
committerTimo Teräs <timo.teras@iki.fi>2011-07-22 12:08:35 +0300
commit6b24f3c3998a66b0e5baa4de89ed66f2b8688404 (patch)
treede0f574bf6d111e237867f5433e03728a241419f /src/apk.c
parent384eada8aff3e9aca3cb1c289e194aee85cbd6c2 (diff)
downloadapk-tools-6b24f3c3998a66b0e5baa4de89ed66f2b8688404.tar.gz
apk-tools-6b24f3c3998a66b0e5baa4de89ed66f2b8688404.tar.bz2
apk-tools-6b24f3c3998a66b0e5baa4de89ed66f2b8688404.tar.xz
apk-tools-6b24f3c3998a66b0e5baa4de89ed66f2b8688404.zip
apk: improve indented printing
* fixup the help messages to align up properly * refresh screen width on SIGWINCH
Diffstat (limited to 'src/apk.c')
-rw-r--r--src/apk.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/apk.c b/src/apk.c
index 3ec241e..fdd31a8 100644
--- a/src/apk.c
+++ b/src/apk.c
@@ -13,13 +13,13 @@
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
+#include <signal.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <openssl/crypto.h>
#ifndef OPENSSL_NO_ENGINE
@@ -130,8 +130,6 @@ static void print_options(int num_opts, struct apk_option *opts)
static int usage(struct apk_applet *applet)
{
- struct apk_indent indent = { 0, 2 };
-
version();
if (applet == NULL) {
struct apk_applet **a;
@@ -141,23 +139,27 @@ static int usage(struct apk_applet *applet)
printf("\nThe following commands are available:\n");
for (a = &__start_apkapplets; a < &__stop_apkapplets; a++) {
- struct apk_indent sub_indent = { 20, 26 };
+ struct apk_indent indent = { 0, 26 };
- printf(" %-*s", sub_indent.indent - 3, (*a)->name);
- apk_print_indented_words(&sub_indent, (*a)->help);
+ indent.x = printf(" %-*s", indent.indent - 3, (*a)->name);
+ apk_print_indented_words(&indent, (*a)->help);
printf("\n");
}
} else {
+ struct apk_indent indent = { 0, 2 };
+
print_usage(applet->name, applet->arguments,
applet->num_options, applet->options);
- printf("\ndescription:\n%*s", indent.indent - 1, "");
+ printf("\nDescription:\n%*s", indent.indent - 1, "");
+ indent.x = indent.indent - 1;
apk_print_indented_words(&indent, applet->help);
+ printf("\n");
}
printf("\nGeneric options:\n");
print_options(ARRAY_SIZE(generic_options), generic_options);
if (applet != NULL && applet->num_options > 0) {
- printf("\noptions for %s command:\n", applet->name);
+ printf("\nOptions for %s command:\n", applet->name);
print_options(applet->num_options, applet->options);
}
printf("\nThis apk has coffee making abilities.\n");
@@ -247,18 +249,17 @@ static void init_openssl(void)
#endif
}
-static void setup_terminal(void)
+static void on_sigwinch(int s)
{
- struct winsize w;
+ apk_reset_screen_width();
+}
+static void setup_terminal(void)
+{
setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
- if (ioctl(STDERR_FILENO,TIOCGWINSZ, &w) == 0)
- apk_screen_width = w.ws_col;
- if (apk_screen_width == 0)
- apk_screen_width = 70;
if (isatty(STDOUT_FILENO) && isatty(STDERR_FILENO) && isatty(STDIN_FILENO))
apk_flags |= APK_PROGRESS;
-
+ signal(SIGWINCH, on_sigwinch);
}
int main(int argc, char **argv)