From 03fb1dc6730fa39da4829c135055dd990e1fa30c Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Wed, 11 Oct 2023 22:22:53 +0100 Subject: [PATCH] Correct percentage formatting so it is always 3 characters wide. --- docs/ACKNOWLEDGEMENTS.md | 1 + docs/NEWS.md | 1 + src/pv/display.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/ACKNOWLEDGEMENTS.md b/docs/ACKNOWLEDGEMENTS.md index 65d23fb..cb2e401 100644 --- a/docs/ACKNOWLEDGEMENTS.md +++ b/docs/ACKNOWLEDGEMENTS.md @@ -88,5 +88,6 @@ is acknowledged and greatly appreciated: * Matějů Miroslav, Ing. - suggested fix for ETA and elapsed time faults when suspending and resuming a machine ([#13](https://codeberg.org/a-j-wood/pv/issues/13)) * Anthony DeRobertis - suggested the "`--error-skip-block`" option ([#37](https://codeberg.org/a-j-wood/pv/issues/37)) * Benoit Pierre - provided patches for compilation without IPC support, without HAVE_STRUCT_STAT_ST_BLKSIZE, and on MacOS + * [gustav-b](https://codeberg.org/gustav-b) - suggested percentage formatting correction ([#80](https://codeberg.org/a-j-wood/pv/issues/80)) --- diff --git a/docs/NEWS.md b/docs/NEWS.md index efcd268..246b086 100644 --- a/docs/NEWS.md +++ b/docs/NEWS.md @@ -2,6 +2,7 @@ * fix: replaced "`--remote`" mechanism, using a temporary file instead of SysV IPC, so it can work reliably even when there are multiple PV instances * fix: corrected compilation failure when without IPC support + * fix: corrected percentage formatting so it doesn't jump from 2 to 3 characters wide at 100% ([#80](https://codeberg.org/a-j-wood/pv/issues/80)) * cleanup: compilation warnings fixed on non-IPC and MacOS systems ### 1.8.0 - 24 September 2023 diff --git a/src/pv/display.c b/src/pv/display.c index d293d36..67d6adb 100644 --- a/src/pv/display.c +++ b/src/pv/display.c @@ -981,7 +981,7 @@ static const char *pv__format(pvstate_t state, state->percentage = 0; if (state->percentage > 100000) state->percentage = 100000; - (void) pv_snprintf(pct, sizeof(pct), "%2ld%%", state->percentage); + (void) pv_snprintf(pct, sizeof(pct), "%3ld%%", state->percentage); available_width = state->width - static_portion_size - strlen(pct) - 3;