[2/2] pacman: simplify chomp mouth logic

Message ID 20211024110828.66471-2-contact@scrumplex.net
State Accepted, archived
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
---
 src/pacman/callback.c | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)

Comments

Allan McRae Jan. 2, 2022, 10:57 a.m. UTC | #1
On 24/10/21 21:08, Sefa Eyeoglu wrote:
> ---
>   src/pacman/callback.c | 20 +++-----------------
>   1 file changed, 3 insertions(+), 17 deletions(-)
> 
> diff --git a/src/pacman/callback.c b/src/pacman/callback.c
> index cb8f4302..a97729ac 100644
> --- a/src/pacman/callback.c
> +++ b/src/pacman/callback.c
> @@ -156,13 +156,8 @@ 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;
>   	int i;
>   
> -	if(bar_percent == 0) {
> -		lasthash = 0;
> -	}
> -
>   	if(hashlen > 0) {
>   		fputs(" [", stdout);
>   		for(i = hashlen; i > 0; --i) {
> @@ -171,19 +166,10 @@ static void fill_progress(const int bar_percent, const int disp_percent,
>   				if(i > hashlen - hash) {
>   					putchar('-');
>   				} else if(i == hashlen - hash) {
> -					if(lasthash == hash) {
> -						if(i % 2 == 0) {
> -							fputs("\033[1;33mC\033[m", stdout);
> -						} else {
> -							fputs("\033[1;33mc\033[m", stdout);
> -						}
> +					if(i % 2 == 0) {
> +						fputs("\033[1;33mC\033[m", stdout);
>   					} else {
> -						lasthash = hash;
> -						if(i % 2 == 0) {
> -							fputs("\033[1;33mC\033[m", stdout);
> -						} else {
> -							fputs("\033[1;33mc\033[m", stdout);
> -						}
> +						fputs("\033[1;33mc\033[m", stdout);
>   					}

I had a look into this - the two blocks looked weird.  It appears this 
was purely to avoid doing a 0/1 switch if the hash did not move.  So not 
needed not that i%2 is happening.  Looks fine to me.

Allan

>   				} else if(i % 3 == 0) {
>   					fputs("\033[0;37mo\033[m", stdout);

Patch

diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index cb8f4302..a97729ac 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -156,13 +156,8 @@  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;
 	int i;
 
-	if(bar_percent == 0) {
-		lasthash = 0;
-	}
-
 	if(hashlen > 0) {
 		fputs(" [", stdout);
 		for(i = hashlen; i > 0; --i) {
@@ -171,19 +166,10 @@  static void fill_progress(const int bar_percent, const int disp_percent,
 				if(i > hashlen - hash) {
 					putchar('-');
 				} else if(i == hashlen - hash) {
-					if(lasthash == hash) {
-						if(i % 2 == 0) {
-							fputs("\033[1;33mC\033[m", stdout);
-						} else {
-							fputs("\033[1;33mc\033[m", stdout);
-						}
+					if(i % 2 == 0) {
+						fputs("\033[1;33mC\033[m", stdout);
 					} else {
-						lasthash = hash;
-						if(i % 2 == 0) {
-							fputs("\033[1;33mC\033[m", stdout);
-						} else {
-							fputs("\033[1;33mc\033[m", stdout);
-						}
+						fputs("\033[1;33mc\033[m", stdout);
 					}
 				} else if(i % 3 == 0) {
 					fputs("\033[0;37mo\033[m", stdout);