[pacman-dev] [PATCH 1/1] make pacman even more candy-aware
From: Christian Hesse <mail@eworm.de> Signed-off-by: Christian Hesse <mail@eworm.de> --- src/pacman/callback.c | 15 +++++++++++++-- src/pacman/conf.c | 3 +++ src/pacman/conf.h | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 7f72b84..9cdd9a4 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -112,8 +112,19 @@ static void fill_progress(const int bar_percent, const int disp_percent, if(hashlen > 0) { fputs(" [", stdout); for(i = hashlen; i > 0; --i) { - /* if special progress bar enabled */ - if(config->chomp) { + /* progress bar with pacman in unicode: [ ᗧ••ᗣ••] */ + if(config->chomp_unicode) { + if(i > hashlen - hash) { + putchar(' '); + } else if(i == hashlen - hash) { + fputs("\033[1;33mᗧ\033[m", stdout); + } else if(i % 3 == 0) { + printf("\033[1;%dmᗣ\033[m", i % 5 + 31); + } else { + fputs("\033[0;37m•\033[m", stdout); + } + } /* progress bar with pacman in ascii: [--C o ] */ + else if(config->chomp) { if(i > hashlen - hash) { putchar('-'); } else if(i == hashlen - hash) { diff --git a/src/pacman/conf.c b/src/pacman/conf.c index d8d64fb..430bb81 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -479,6 +479,9 @@ static int _parse_options(const char *key, char *value, if(strcmp(key, "UseSyslog") == 0) { config->usesyslog = 1; pm_printf(ALPM_LOG_DEBUG, "config: usesyslog\n"); + } else if(strcmp(key, "ILoveSweetCandy") == 0) { + config->chomp_unicode = 1; + pm_printf(ALPM_LOG_DEBUG, "config: chomp_unicode\n"); } else if(strcmp(key, "ILoveCandy") == 0) { config->chomp = 1; pm_printf(ALPM_LOG_DEBUG, "config: chomp\n"); diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 945de7c..577f236 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -109,6 +109,8 @@ typedef struct __config_t { /* conf file options */ /* I Love Candy! */ unsigned short chomp; + /* I Love Sweet Candy! */ + unsigned short chomp_unicode; /* format target pkg lists as table */ unsigned short verbosepkglists; /* When downloading, display the amount downloaded, rate, ETA, and percent -- 2.10.2
From: Christian Hesse <mail@eworm.de> v2: automatically detect UTF-8 locale Signed-off-by: Christian Hesse <mail@eworm.de> --- src/pacman/callback.c | 58 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 7f72b84..06ea8e5 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -28,6 +28,7 @@ #include <unistd.h> #include <wchar.h> #include <limits.h> /* UINT_MAX */ +#include <langinfo.h> #include <alpm.h> @@ -102,8 +103,13 @@ static void fill_progress(const int bar_percent, const int disp_percent, const int hashlen = proglen > 8 ? proglen - 8 : 0; const int hash = bar_percent * hashlen / 100; static int lasthash = 0, mouth = 0; + uint8_t have_utf8 = 0; int i; + setlocale(LC_CTYPE, ""); + if(strcmp(nl_langinfo(CODESET), "UTF-8") == 0) + have_utf8 = 1; + if(bar_percent == 0) { lasthash = 0; mouth = 0; @@ -112,30 +118,44 @@ static void fill_progress(const int bar_percent, const int disp_percent, if(hashlen > 0) { fputs(" [", stdout); for(i = hashlen; i > 0; --i) { - /* if special progress bar enabled */ + /* progress bar with pacman... */ if(config->chomp) { - if(i > hashlen - hash) { - putchar('-'); - } else if(i == hashlen - hash) { - if(lasthash == hash) { - if(mouth) { - fputs("\033[1;33mC\033[m", stdout); - } else { - fputs("\033[1;33mc\033[m", stdout); - } + /* ... in unicode: [ ᗧ••ᗣ••] */ + if(have_utf8) { + if(i > hashlen - hash) { + putchar(' '); + } else if(i == hashlen - hash) { + fputs("\033[1;33mᗧ\033[m", stdout); + } else if(i % 3 == 0) { + printf("\033[1;%dmᗣ\033[m", i % 5 + 31); } else { - lasthash = hash; - mouth = mouth == 1 ? 0 : 1; - if(mouth) { - fputs("\033[1;33mC\033[m", stdout); + fputs("\033[0;37m•\033[m", stdout); + } + } /* ... in ascii: [--C o ] */ + else { + if(i > hashlen - hash) { + putchar('-'); + } else if(i == hashlen - hash) { + if(lasthash == hash) { + if(mouth) { + fputs("\033[1;33mC\033[m", stdout); + } else { + fputs("\033[1;33mc\033[m", stdout); + } } else { - fputs("\033[1;33mc\033[m", stdout); + lasthash = hash; + mouth = mouth == 1 ? 0 : 1; + if(mouth) { + fputs("\033[1;33mC\033[m", stdout); + } else { + fputs("\033[1;33mc\033[m", stdout); + } } + } else if(i % 3 == 0) { + fputs("\033[0;37mo\033[m", stdout); + } else { + fputs("\033[0;37m \033[m", stdout); } - } else if(i % 3 == 0) { - fputs("\033[0;37mo\033[m", stdout); - } else { - fputs("\033[0;37m \033[m", stdout); } } /* else regular progress bar */ else if(i > hashlen - hash) { -- 2.10.2
participants (1)
-
Christian Hesse