[PATCH 1/2] pacman: remove redundant argument
The fill_progress function is called from two locations, and both locations pass in the same percentage value twice. This patch modifies the function signature to to receive the percentage value just once. Signed-off-by: Alexander F. Rødseth <xyproto@archlinux.org> --- src/pacman/callback.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index a06f3bcc..df4032a4 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -150,12 +150,11 @@ static int64_t get_update_timediff(int first_call) } /* refactored from cb_trans_progress */ -static void fill_progress(const int bar_percent, const int disp_percent, - const int proglen) +static void fill_progress(const int percent, const int proglen) { /* 8 = 1 space + 1 [ + 1 ] + 5 for percent */ const int hashlen = proglen > 8 ? proglen - 8 : 0; - const int hash = bar_percent * hashlen / 100; + const int hash = percent * hashlen / 100; int i; if(hashlen > 0) { @@ -188,7 +187,7 @@ static void fill_progress(const int bar_percent, const int disp_percent, /* print display percent after progress bar */ /* 5 = 1 space + 3 digits + 1 % */ if(proglen >= 5) { - printf(" %3d%%", disp_percent); + printf(" %3d%%", percent); } putchar('\r'); @@ -677,7 +676,7 @@ void cb_progress(void *ctx, alpm_progress_t event, const char *pkgname, free(wcstr); /* call refactored fill progress function */ - fill_progress(percent, percent, cols - infolen); + fill_progress(percent, cols - infolen); if(percent == 100) { putchar('\n'); @@ -855,7 +854,7 @@ static void draw_pacman_progress_bar(struct pacman_progress_bar *bar) free(fname); free(wcfname); - fill_progress(file_percent, file_percent, cols - infolen); + fill_progress(file_percent, cols - infolen); return; } -- 2.37.1
For some terminal widths, the "C"/"c" character does not alternate at regular intervals, but may look like it is stuck at either lowercase or uppercase. The previous behavior toggled based on the character position, while this new behavior toggles the chomp alternation based on the progress percentage value. This leads to slightly improved chomping. Signed-off-by: Alexander F. Rødseth <xyproto@archlinux.org> --- src/pacman/callback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index df4032a4..aa6303bf 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -165,7 +165,7 @@ static void fill_progress(const int percent, const int proglen) if(i > hashlen - hash) { putchar('-'); } else if(i == hashlen - hash) { - if(i % 2 == 0) { + if(percent % 2 == 0) { fputs("\033[1;33mC\033[m", stdout); } else { fputs("\033[1;33mc\033[m", stdout); -- 2.37.1
On 23/7/22 06:27, Alexander F. Rødseth wrote:
For some terminal widths, the "C"/"c" character does not alternate at regular intervals, but may look like it is stuck at either lowercase or uppercase.
The previous behavior toggled based on the character position, while this new behavior toggles the chomp alternation based on the progress percentage value.
This leads to slightly improved chomping.
How I would love to remove this option, but I think I would suffer a revolt from users! This is fine.
Signed-off-by: Alexander F. Rødseth <xyproto@archlinux.org> --- src/pacman/callback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index df4032a4..aa6303bf 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -165,7 +165,7 @@ static void fill_progress(const int percent, const int proglen) if(i > hashlen - hash) { putchar('-'); } else if(i == hashlen - hash) { - if(i % 2 == 0) { + if(percent % 2 == 0) { fputs("\033[1;33mC\033[m", stdout); } else { fputs("\033[1;33mc\033[m", stdout);
On 23/7/22 06:27, Alexander F. Rødseth wrote:
The fill_progress function is called from two locations, and both locations pass in the same percentage value twice.
This patch modifies the function signature to to receive the percentage value just once.
Signed-off-by: Alexander F. Rødseth <xyproto@archlinux.org>
Looking through the history, the second parameter used to be used when the progress bar could display either package progress or total progress. That was make redundant with always having a total bar when parallel downloads were implemented. Thanks.
--- src/pacman/callback.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index a06f3bcc..df4032a4 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -150,12 +150,11 @@ static int64_t get_update_timediff(int first_call) }
/* refactored from cb_trans_progress */ -static void fill_progress(const int bar_percent, const int disp_percent, - const int proglen) +static void fill_progress(const int percent, const int proglen) { /* 8 = 1 space + 1 [ + 1 ] + 5 for percent */ const int hashlen = proglen > 8 ? proglen - 8 : 0; - const int hash = bar_percent * hashlen / 100; + const int hash = percent * hashlen / 100; int i;
if(hashlen > 0) { @@ -188,7 +187,7 @@ static void fill_progress(const int bar_percent, const int disp_percent, /* print display percent after progress bar */ /* 5 = 1 space + 3 digits + 1 % */ if(proglen >= 5) { - printf(" %3d%%", disp_percent); + printf(" %3d%%", percent); }
putchar('\r'); @@ -677,7 +676,7 @@ void cb_progress(void *ctx, alpm_progress_t event, const char *pkgname, free(wcstr);
/* call refactored fill progress function */ - fill_progress(percent, percent, cols - infolen); + fill_progress(percent, cols - infolen);
if(percent == 100) { putchar('\n'); @@ -855,7 +854,7 @@ static void draw_pacman_progress_bar(struct pacman_progress_bar *bar) free(fname); free(wcfname);
- fill_progress(file_percent, file_percent, cols - infolen); + fill_progress(file_percent, cols - infolen); return; }
participants (2)
-
Alexander F. Rødseth
-
Allan McRae