Use standalone flags to indicate whether we are tracking the last bytes output or the previous line written, so that the component array is not needed outside of display.c.

This commit is contained in:
Andrew Wood
2024-12-08 10:23:24 +00:00
parent 3d52919411
commit cfea00b200
11 changed files with 83 additions and 76 deletions
+2
View File
@@ -222,6 +222,8 @@ struct pvstate_s {
size_t format_segment_count; /* number of format string segments */
unsigned int prev_screen_width; /* screen width last time we were called */
bool tracking_last_output; /* set if displaying the last few bytes output */
bool tracking_previous_line; /* set if displaying the previously output line */
bool display_visible; /* set once anything written to terminal */
} display;
+5
View File
@@ -443,6 +443,9 @@ static void pv__format_init(pvstate_t state, /*@null@ */ const char *format_supp
memset(display->format, 0, PV_FORMAT_ARRAY_MAX * sizeof(display->format[0]));
memset(display->component, 0, PV_COMPONENT__MAX * sizeof(display->component[0]));
display->tracking_last_output = false;
display->tracking_previous_line = false;
if (state->control.name) {
(void) pv_snprintf(display->component[PV_COMPONENT_NAME].content, PV_SIZEOF_COMPONENT_STR,
"%9.500s:", state->control.name);
@@ -535,12 +538,14 @@ static void pv__format_init(pvstate_t state, /*@null@ */ const char *format_supp
chosen_size = (size_t) number_prefix;
if (display->lastoutput_bytes < chosen_size)
display->lastoutput_bytes = chosen_size;
display->tracking_last_output = true;
break;
case 'L':
seg_type = PV_COMPONENT_PREVLINE;
if (number_prefix > PV_SIZEOF_PREVLINE_BUFFER)
number_prefix = PV_SIZEOF_PREVLINE_BUFFER;
chosen_size = (size_t) number_prefix;
display->tracking_previous_line = true;
break;
case 'r':
seg_type = PV_COMPONENT_RATE;
+4 -4
View File
@@ -722,7 +722,7 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
if ((state->control.linemode) && (lineswritten != NULL))
tracking_lines = true;
else if (state->display.component[PV_COMPONENT_PREVLINE].required)
else if (state->display.tracking_previous_line)
tracking_lines = true;
/*
@@ -772,7 +772,7 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
* line ("%L"), add to our line
* buffer.
*/
if (state->display.component[PV_COMPONENT_PREVLINE].required
if (state->display.tracking_previous_line
&& state->display.next_line_len < PV_SIZEOF_PREVLINE_BUFFER - 1) {
state->display.next_line[state->display.next_line_len] = *ptr;
state->display.next_line_len++;
@@ -789,7 +789,7 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
* with the line we just completed, and
* start a new one.
*/
if (state->display.component[PV_COMPONENT_PREVLINE].required) {
if (state->display.tracking_previous_line) {
memset(state->display.previous_line, 0, PV_SIZEOF_PREVLINE_BUFFER);
if (state->display.next_line_len > PV_SIZEOF_PREVLINE_BUFFER - 1)
state->display.next_line_len = PV_SIZEOF_PREVLINE_BUFFER - 1;
@@ -840,7 +840,7 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
* If we're monitoring the output, update our copy of the
* last few bytes we've written.
*/
if (state->display.component[PV_COMPONENT_OUTPUTBUF].required && (nwritten > 0)) {
if (state->display.tracking_last_output && (nwritten > 0)) {
size_t new_portion_size, old_portion_size;
new_portion_size = (size_t) nwritten;