pacman: support multiple chomps at the same time

When two progressbars are present, one of them always had c while the
other always had C as the mouth

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Sefa Eyeoglu 2021-10-24 13:08:27 +02:00 committed by Allan McRae
parent 2fe1ba5d81
commit e654aa8ac6

View file

@ -156,12 +156,11 @@ static void fill_progress(const int bar_percent, const int disp_percent,
/* 8 = 1 space + 1 [ + 1 ] + 5 for percent */ /* 8 = 1 space + 1 [ + 1 ] + 5 for percent */
const int hashlen = proglen > 8 ? proglen - 8 : 0; const int hashlen = proglen > 8 ? proglen - 8 : 0;
const int hash = bar_percent * hashlen / 100; const int hash = bar_percent * hashlen / 100;
static int lasthash = 0, mouth = 0; static int lasthash = 0;
int i; int i;
if(bar_percent == 0) { if(bar_percent == 0) {
lasthash = 0; lasthash = 0;
mouth = 0;
} }
if(hashlen > 0) { if(hashlen > 0) {
@ -173,15 +172,14 @@ static void fill_progress(const int bar_percent, const int disp_percent,
putchar('-'); putchar('-');
} else if(i == hashlen - hash) { } else if(i == hashlen - hash) {
if(lasthash == hash) { if(lasthash == hash) {
if(mouth) { if(i % 2 == 0) {
fputs("\033[1;33mC\033[m", stdout); fputs("\033[1;33mC\033[m", stdout);
} else { } else {
fputs("\033[1;33mc\033[m", stdout); fputs("\033[1;33mc\033[m", stdout);
} }
} else { } else {
lasthash = hash; lasthash = hash;
mouth = mouth == 1 ? 0 : 1; if(i % 2 == 0) {
if(mouth) {
fputs("\033[1;33mC\033[m", stdout); fputs("\033[1;33mC\033[m", stdout);
} else { } else {
fputs("\033[1;33mc\033[m", stdout); fputs("\033[1;33mc\033[m", stdout);