Format the average rate, byte/line count, percentage completion, transfer rate, and elapsed time as just a number on its own in numeric mode.

This commit is contained in:
Andrew Wood
2025-01-24 23:10:59 +00:00
parent efb115c2aa
commit 0d3b678800
5 changed files with 36 additions and 22 deletions
+6 -3
View File
@@ -13,8 +13,6 @@
/*
* Average transfer rate.
*
* TODO: show exact number without suffix if --numeric is active.
*/
pvdisplay_bytecount_t pv_formatter_average_rate(pvformatter_args_t args)
{
@@ -26,7 +24,12 @@ pvdisplay_bytecount_t pv_formatter_average_rate(pvformatter_args_t args)
return 0;
/*@-mustfreefresh@ */
if (args->state->control.bits && !args->state->control.linemode) {
if (args->state->control.numeric) {
/* numeric - raw value without suffix. */
(void) pv_snprintf(content, sizeof(content),
"%.4Lf",
((args->state->control.bits ? 8.0 : 1.0) * args->state->calc.average_rate));
} else if (args->state->control.bits && !args->state->control.linemode) {
/* bits per second */
pv_describe_amount(content, sizeof(content),
"(%s)", 8 * args->state->calc.average_rate, "", _("b/s"), args->display->count_type);
+8 -5
View File
@@ -13,8 +13,6 @@
/*
* Number of bytes or lines transferred.
*
* TODO: show exact number without suffix if --numeric is active.
*/
pvdisplay_bytecount_t pv_formatter_bytes(pvformatter_args_t args)
{
@@ -22,13 +20,18 @@ pvdisplay_bytecount_t pv_formatter_bytes(pvformatter_args_t args)
args->display->showing_bytes = true;
content[0] = '\0';
if (0 == args->buffer_size)
return 0;
content[0] = '\0';
/*@-mustfreefresh@ */
if (args->state->control.bits && !args->state->control.linemode) {
if (args->state->control.numeric) {
/* Numeric mode - raw values only, no suffix. */
(void) pv_snprintf(content, sizeof(content),
"%lld",
(long long) ((args->state->control.bits ? 8 : 1) * args->state->transfer.transferred));
} else if (args->state->control.bits && !args->state->control.linemode) {
pv_describe_amount(content, sizeof(content), "%s",
(long double) (args->state->transfer.transferred * 8), "", _("b"),
args->display->count_type);
+7 -4
View File
@@ -382,20 +382,23 @@ pvdisplay_bytecount_t pv_formatter_progress_bar_only(pvformatter_args_t args)
/*
* The number after the progress bar.
*
* TODO: show percentage without adornment if --numeric is active.
*/
pvdisplay_bytecount_t pv_formatter_progress_amount_only(pvformatter_args_t args)
{
char content[256]; /* flawfinder: ignore - always bounded */
pvdisplay_bytecount_t bytes;
content[0] = '\0';
memset(content, 0, sizeof(content));
if (0 == args->buffer_size)
return 0;
if (args->state->control.size > 0 || args->state->control.rate_gauge) {
if (args->state->control.numeric) {
/* Numeric mode - percentage as a rounded integer with no suffix. */
(void) pv_snprintf(content, sizeof(content), "%.0f", args->state->calc.percentage);
bytes = strlen(content); /* flawfinder: ignore */
/* flawfinder: always \0-terminated by pv_snprintf() and the earlier memset(). */
} else if (args->state->control.size > 0 || args->state->control.rate_gauge) {
/* Known size or rate gauge - percentage or rate. */
bytes = pv_formatter_progress_knownsize(args, content, sizeof(content), false, false, true);
} else {
+6 -3
View File
@@ -13,8 +13,6 @@
/*
* Transfer rate.
*
* TODO: show exact number without suffix if --numeric is active.
*/
pvdisplay_bytecount_t pv_formatter_rate(pvformatter_args_t args)
{
@@ -28,7 +26,12 @@ pvdisplay_bytecount_t pv_formatter_rate(pvformatter_args_t args)
return 0;
/*@-mustfreefresh@ */
if (args->state->control.bits && !args->state->control.linemode) {
if (args->state->control.numeric) {
/* numeric - raw value without suffix. */
(void) pv_snprintf(content, sizeof(content),
"%.4Lf",
((args->state->control.bits ? 8.0 : 1.0) * args->state->calc.transfer_rate));
} else if (args->state->control.bits && !args->state->control.linemode) {
/* bits per second */
pv_describe_amount(content, sizeof(content), "[%s]",
8 * args->state->calc.transfer_rate, "", _("b/s"), args->display->count_type);
+9 -7
View File
@@ -13,8 +13,6 @@
/*
* Elapsed time.
*
* TODO: show as a number if --numeric is active.
*/
pvdisplay_bytecount_t pv_formatter_timer(pvformatter_args_t args)
{
@@ -39,11 +37,15 @@ pvdisplay_bytecount_t pv_formatter_timer(pvformatter_args_t args)
if (args->state->transfer.elapsed_seconds < 0.0)
args->state->transfer.elapsed_seconds = 0.0;
/*
* If the elapsed time is more than a day, include a day count as
* well as hours, minutes, and seconds.
*/
if (args->state->transfer.elapsed_seconds > (long double) 86400.0L) {
if (args->state->control.numeric) {
/* Numeric mode - show the number of seconds, unformatted. */
(void) pv_snprintf(content, sizeof(content), "%.4Lf",
args->state->transfer.elapsed_seconds);
} else if (args->state->transfer.elapsed_seconds > (long double) 86400.0L) {
/*
* If the elapsed time is more than a day, include a day count as
* well as hours, minutes, and seconds.
*/
(void) pv_snprintf(content,
sizeof(content),
"%ld:%02ld:%02ld:%02ld",