[1/2] pacman: support multiple chomps at the same time

Message ID 20211024110828.66471-1-contact@scrumplex.net
State New
Headers show
Series [1/2] pacman: support multiple chomps at the same time | expand

Commit Message

Sefa Eyeoglu Oct. 24, 2021, 11:08 a.m. UTC
When two progressbars are present, one of them always had c while the
other always had C as the mouth
---
 src/pacman/callback.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Allan McRae Jan. 2, 2022, 10:54 a.m. UTC | #1
On 24/10/21 21:08, Sefa Eyeoglu wrote:
> When two progressbars are present, one of them always had c while the
> other always had C as the mouth
> ---

Looks good.

A white space fix slipped in at the end there, but I'll let that slide!

A

>   src/pacman/callback.c | 10 ++++------
>   1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/src/pacman/callback.c b/src/pacman/callback.c
> index 2579b98a..cb8f4302 100644
> --- a/src/pacman/callback.c
> +++ b/src/pacman/callback.c
> @@ -156,12 +156,11 @@ static void fill_progress(const int bar_percent, const int disp_percent,
>   	/* 8 = 1 space + 1 [ + 1 ] + 5 for percent */
>   	const int hashlen = proglen > 8 ? proglen - 8 : 0;
>   	const int hash = bar_percent * hashlen / 100;
> -	static int lasthash = 0, mouth = 0;
> +	static int lasthash = 0;
>   	int i;
>   
>   	if(bar_percent == 0) {
>   		lasthash = 0;
> -		mouth = 0;
>   	}
>   
>   	if(hashlen > 0) {
> @@ -173,15 +172,14 @@ static void fill_progress(const int bar_percent, const int disp_percent,
>   					putchar('-');
>   				} else if(i == hashlen - hash) {
>   					if(lasthash == hash) {
> -						if(mouth) {
> +						if(i % 2 == 0) {
>   							fputs("\033[1;33mC\033[m", stdout);
>   						} else {
>   							fputs("\033[1;33mc\033[m", stdout);
>   						}
>   					} else {
>   						lasthash = hash;
> -						mouth = mouth == 1 ? 0 : 1;
> -						if(mouth) {
> +						if(i % 2 == 0) {
>   							fputs("\033[1;33mC\033[m", stdout);
>   						} else {
>   							fputs("\033[1;33mc\033[m", stdout);
> @@ -252,7 +250,7 @@ void cb_event(void *ctx, alpm_event_t *event)
>   				alpm_event_hook_run_t *e = &event->hook_run;
>   				int digits = number_length(e->total);
>   				printf("(%*zu/%*zu) %s\n", digits, e->position,
> -						digits, e->total,
> +						digits, e->total,
>   						e->desc ? e->desc : e->name);
>   			}
>   			break;

Patch

diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 2579b98a..cb8f4302 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -156,12 +156,11 @@  static void fill_progress(const int bar_percent, const int disp_percent,
 	/* 8 = 1 space + 1 [ + 1 ] + 5 for percent */
 	const int hashlen = proglen > 8 ? proglen - 8 : 0;
 	const int hash = bar_percent * hashlen / 100;
-	static int lasthash = 0, mouth = 0;
+	static int lasthash = 0;
 	int i;
 
 	if(bar_percent == 0) {
 		lasthash = 0;
-		mouth = 0;
 	}
 
 	if(hashlen > 0) {
@@ -173,15 +172,14 @@  static void fill_progress(const int bar_percent, const int disp_percent,
 					putchar('-');
 				} else if(i == hashlen - hash) {
 					if(lasthash == hash) {
-						if(mouth) {
+						if(i % 2 == 0) {
 							fputs("\033[1;33mC\033[m", stdout);
 						} else {
 							fputs("\033[1;33mc\033[m", stdout);
 						}
 					} else {
 						lasthash = hash;
-						mouth = mouth == 1 ? 0 : 1;
-						if(mouth) {
+						if(i % 2 == 0) {
 							fputs("\033[1;33mC\033[m", stdout);
 						} else {
 							fputs("\033[1;33mc\033[m", stdout);
@@ -252,7 +250,7 @@  void cb_event(void *ctx, alpm_event_t *event)
 				alpm_event_hook_run_t *e = &event->hook_run;
 				int digits = number_length(e->total);
 				printf("(%*zu/%*zu) %s\n", digits, e->position,
-						digits, e->total, 
+						digits, e->total,
 						e->desc ? e->desc : e->name);
 			}
 			break;