Rather than setting an option flag for ratio, add it to the default format string on the "out" side (#67).

This commit is contained in:
Andrew Wood
2026-04-03 20:20:50 +01:00
parent d7327aaf95
commit 7892e54d7e
4 changed files with 23 additions and 7 deletions
+3
View File
@@ -209,6 +209,9 @@ typedef struct {
} pvformatoptions_s;
extern void pv_state_set_format_options(pvstate_t, pvformatoptions_s);
/* Append a string to the default format. */
void pv_state_append_to_default_format(pvstate_t, /*@null@ */ const char *);
/*
* Set the various options.
*/
+9 -3
View File
@@ -341,7 +341,7 @@ static int pv__run_monitor(const char *program_name, pvstate_t state, pvside_t s
* other side has transferred. This is what allows the in:out ratio to be
* displayed.
*/
static int pv__monitor(pvstate_t state, opts_t opts)
static int pv__monitor(pvstate_t state, opts_t opts, pvformatoptions_s format_options)
{
int pipefd_cmd_in[2]; /* pipe from the monitor to the command */
int pipefd_cmd_out[2]; /* pipe from the command to the monitor */
@@ -520,6 +520,11 @@ x = 1; \
/* Close the read end of the out-to-in pipe. */
close_if_open(pipefd_out_to_in[0]);
/* Add ratio to the default format on the out side. */
if (PV_SIDE_BOTH == opts->side) {
pv_state_append_to_default_format(state, "%{ratio}");
}
retcode =
pv__run_monitor(opts->program_name, state, PV_SIDE_OUT, pipefd_cmd_out[0], in_monitor_pid,
pipefd_in_to_out[0], pipefd_out_to_in[1]);
@@ -553,7 +558,8 @@ x = 1; \
if (NULL != opts->format1) {
pv_state_format_string_set(state, opts->format1);
}
/* TODO: call pv_state_set_format_options(). */
/* Trigger a format reparse. */
pv_state_set_format_options(state, format_options);
/*@fallthrough@ */
/* falling through as "out" is in another process (above). */
#ifndef SPLINT
@@ -925,7 +931,7 @@ int main(int argc, char **argv)
break;
case PV_ACTION_MONITOR:
/* Run a process and monitor its input and output. */
retcode = pv__monitor(state, opts);
retcode = pv__monitor(state, opts, format_options);
break;
}
-2
View File
@@ -1290,8 +1290,6 @@ opts_t opts_parse(unsigned int argc, char **argv)
opts->eta = true;
opts->rate = true;
opts->bytes = true;
if (PV_SIDE_BOTH == opts->side)
opts->ratio = true;
}
/* If -Z was given but not -E, pretend one -E was given too. */
+11 -2
View File
@@ -416,8 +416,6 @@ void pv_state_free(pvstate_t state)
*
* Call this *after* setting a name, so it can determine whether there
* should be a name in the default format.
*
* TODO: allow opts->ratio to be passed here as well.
*/
void pv_state_set_format_options(pvstate_t state, pvformatoptions_s format)
{
@@ -485,6 +483,17 @@ void pv_state_set_format_options(pvstate_t state, pvformatoptions_s format)
}
/*
* Append the given string to the default format, and trigger a format
* reparse.
*/
void pv_state_append_to_default_format(pvstate_t state, /*@null@ */ const char *val)
{
PV_ADDFORMAT(NULL != val, val);
state->flags.reparse_display = 1;
}
void pv_state_force_set(pvstate_t state, bool val)
{
state->control.force = val;