diff --git a/src/include/pv.h b/src/include/pv.h index 8537b3b..031f1c2 100644 --- a/src/include/pv.h +++ b/src/include/pv.h @@ -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. */ diff --git a/src/main/main.c b/src/main/main.c index 98e9c28..dda3c55 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -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; } diff --git a/src/main/options.c b/src/main/options.c index f8877e7..ead226e 100644 --- a/src/main/options.c +++ b/src/main/options.c @@ -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. */ diff --git a/src/pv/state.c b/src/pv/state.c index 9229133..be226e7 100644 --- a/src/pv/state.c +++ b/src/pv/state.c @@ -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;