diff --git a/src/include/pv-internal.h b/src/include/pv-internal.h index 28a9752..971c116 100644 --- a/src/include/pv-internal.h +++ b/src/include/pv-internal.h @@ -119,6 +119,19 @@ struct pvbarstyle_s { typedef struct pvbarstyle_s *pvbarstyle_t; +/* Display format component type, -1 for static string. */ +typedef int8_t pvdisplay_component_t; +#define PVDISPLAY_COMPONENT_MAX (127) /* INT8_MAX */ + +/* Byte count of a part of the display. */ +typedef uint16_t pvdisplay_bytecount_t; +#define PVDISPLAY_BYTECOUNT_MAX (65535) /* UINT16_MAX */ + +/* Width of a part of the display. */ +typedef uint16_t pvdisplay_width_t; +#define PVDISPLAY_WIDTH_MAX (65535) /* UINT16_MAX */ + + /* * Structure for holding PV internal state. Opaque outside the PV library. * @@ -165,7 +178,7 @@ struct pvstate_s { int output_fd; /* fd to write output to */ unsigned int average_rate_window; /* time window in seconds for average rate calculations */ unsigned int history_interval; /* seconds between each average rate calc history entry */ - unsigned int width; /* screen width */ + pvdisplay_width_t width; /* screen width */ unsigned int height; /* screen height */ unsigned int extra_displays; /* bitmask of extra display destinations */ bool force; /* display even if not on terminal */ @@ -237,14 +250,14 @@ struct pvstate_s { struct pvdisplay_segment_s { /* format string broken into segments */ /* See pv__format_init() for more details. */ - int type; /* component type, -1 for static string */ - int parameter; /* component parameter, such as bar style index */ - uint8_t string_parameter_bytes; /* number of bytes in string_parameter */ - size_t chosen_size; /* "n" from %A, or 0 */ - size_t offset; /* start offset of this segment in the build buffer */ - size_t bytes; /* length of segment in bytes in the build buffer */ - size_t width; /* displayed width of segment */ /*@dependent@*/ /*@null@*/ const char *string_parameter; /* parameter after colon in %{x:} */ + pvdisplay_bytecount_t string_parameter_bytes; /* number of bytes in string_parameter */ + pvdisplay_component_t type; /* component type, -1 for static string */ + int8_t parameter; /* component parameter, such as bar style index */ + pvdisplay_width_t chosen_size; /* "n" from %A, or 0 */ + pvdisplay_bytecount_t offset; /* start offset of this segment in the build buffer */ + pvdisplay_bytecount_t bytes; /* length of segment in bytes in the build buffer */ + pvdisplay_width_t width; /* displayed width of segment */ } format[PV_FORMAT_ARRAY_MAX]; struct pvbarstyle_s barstyle[PV_BARSTYLE_MAX]; @@ -258,18 +271,19 @@ struct pvstate_s { char next_line[PV_SIZEOF_PREVLINE_BUFFER]; /*@only@*/ /*@null@*/ char *display_buffer; /* buffer for display string */ - size_t display_buffer_size; /* size allocated to display buffer */ - size_t display_string_bytes; /* byte length of string in display buffer */ - size_t display_string_width; /* displayed width of string in display buffer */ - off_t initial_offset; /* offset when first opened (when watching fds) */ - size_t lastwritten_bytes; /* largest number of last-written bytes to show */ - size_t next_line_len; /* length of currently receiving line so far */ + off_t initial_offset; /* offset when first opened (when watching fds) */ + size_t next_line_len; /* length of currently receiving line so far */ size_t format_segment_count; /* number of format string segments */ pvtransfercount_t count_type; /* type of count for transfer, rate, etc */ - unsigned int prev_screen_width; /* screen width last time we were called */ + pvdisplay_width_t prev_screen_width; /* screen width last time we were called */ + + pvdisplay_bytecount_t display_buffer_size; /* size allocated to display buffer */ + pvdisplay_bytecount_t display_string_bytes; /* byte length of string in display buffer */ + pvdisplay_width_t display_string_width; /* displayed width of string in display buffer */ + pvdisplay_bytecount_t lastwritten_bytes; /* largest number of last-written bytes to show */ bool showing_timer; /* set if showing timer */ bool showing_bytes; /* set if showing byte/line count */ @@ -426,14 +440,14 @@ struct pvformatter_args_s { /*@dependent@*/ pvdisplay_t display; /* the display being updated */ /*@dependent@*/ pvdisplay_segment_t segment; /* the segment of the display */ /*@dependent@*/ char *buffer; /* buffer to write formatted segments into */ - size_t buffer_size; /* size of the buffer */ - size_t offset; /* current write position in the buffer */ + pvdisplay_bytecount_t buffer_size; /* size of the buffer */ + pvdisplay_bytecount_t offset; /* current write position in the buffer */ }; typedef struct pvformatter_args_s *pvformatter_args_t; /* Pointer to a formatter function. */ -typedef size_t (*pvdisplay_formatter_t)(pvformatter_args_t); +typedef pvdisplay_bytecount_t (*pvdisplay_formatter_t)(pvformatter_args_t); /* @@ -475,9 +489,9 @@ long pv_seconds_remaining(const off_t, const off_t, const long double); void pv_si_prefix(long double *, char *, const long double, pvtransfercount_t); void pv_describe_amount(char *, size_t, char *, long double, char *, char *, pvtransfercount_t); -int pv_display_barstyle_index(pvformatter_args_t, const char *); +int8_t pv_display_barstyle_index(pvformatter_args_t, const char *); -size_t pv_formatter_segmentcontent(char *, pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_segmentcontent(char *, pvformatter_args_t); /* * Formatting functions. @@ -500,25 +514,25 @@ size_t pv_formatter_segmentcontent(char *, pvformatter_args_t); * If called with a buffer size of 0, only the side effects occur (such as * setting flags like display->showing_timer). */ -size_t pv_formatter_progress(pvformatter_args_t); -size_t pv_formatter_progress_bar_only(pvformatter_args_t); -size_t pv_formatter_progress_amount_only(pvformatter_args_t); -size_t pv_formatter_bar_default(pvformatter_args_t); -size_t pv_formatter_bar_plain(pvformatter_args_t); -size_t pv_formatter_bar_block(pvformatter_args_t); -size_t pv_formatter_bar_granular(pvformatter_args_t); -size_t pv_formatter_bar_shaded(pvformatter_args_t); -size_t pv_formatter_timer(pvformatter_args_t); -size_t pv_formatter_eta(pvformatter_args_t); -size_t pv_formatter_fineta(pvformatter_args_t); -size_t pv_formatter_rate(pvformatter_args_t); -size_t pv_formatter_average_rate(pvformatter_args_t); -size_t pv_formatter_bytes(pvformatter_args_t); -size_t pv_formatter_buffer_percent(pvformatter_args_t); -size_t pv_formatter_last_written(pvformatter_args_t); -size_t pv_formatter_previous_line(pvformatter_args_t); -size_t pv_formatter_name(pvformatter_args_t); -size_t pv_formatter_sgr(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_progress(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_progress_bar_only(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_progress_amount_only(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_bar_default(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_bar_plain(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_bar_block(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_bar_granular(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_bar_shaded(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_timer(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_eta(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_fineta(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_rate(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_average_rate(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_bytes(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_buffer_percent(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_last_written(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_previous_line(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_name(pvformatter_args_t); +pvdisplay_bytecount_t pv_formatter_sgr(pvformatter_args_t); bool pv_format(pvstate_t, /*@null@*/ const char *, pvdisplay_t, bool, bool); void pv_display(pvstate_t, bool); diff --git a/src/pv/display.c b/src/pv/display.c index b70834b..4d9b6c4 100644 --- a/src/pv/display.c +++ b/src/pv/display.c @@ -446,9 +446,9 @@ void pv_describe_amount(char *buffer, size_t bufsize, char *format, * updating the segment's offset and bytes values and returning the bytes * value, or treating the byte count as zero if there's insufficient space. */ -size_t pv_formatter_segmentcontent(char *content, pvformatter_args_t formatter_info) +pvdisplay_bytecount_t pv_formatter_segmentcontent(char *content, pvformatter_args_t formatter_info) { - size_t bytes; + pvdisplay_bytecount_t bytes; bytes = strlen(content); /* flawfinder: ignore */ /* flawfinder - caller is required to null-terminate the string. */ @@ -683,7 +683,7 @@ static void pv__format_init(pvstate_t state, /*@null@ */ const char *format_supp */ segment = 0; for (strpos = 0; display_format[strpos] != '\0' && segment < PV_FORMAT_ARRAY_MAX; strpos++, segment++) { - int component_type, component_idx; + pvdisplay_component_t component_type, component_idx; size_t str_start, str_bytes, chosen_size; const char *string_parameter = NULL; size_t string_parameter_bytes = 0; @@ -915,7 +915,7 @@ static void pv__format_init(pvstate_t state, /*@null@ */ const char *format_supp } } #else /* ! ENABLE_NCURSES */ -# ifdef USE_POPEN_TPUTS /* (! ENABLE_NCURSES) && (USE_POPEN_TPUTS) */ +#ifdef USE_POPEN_TPUTS /* (! ENABLE_NCURSES) && (USE_POPEN_TPUTS) */ /* * Without terminal info support, try running "tput colors" * to determine whether colour is available, unless --force @@ -960,14 +960,14 @@ static void pv__format_init(pvstate_t state, /*@null@ */ const char *format_supp /*@+unrecog@ */ } } -# else /* (! ENABLE_NCURSES) && (! USE_POPEN_TPUTS) */ +#else /* (! ENABLE_NCURSES) && (! USE_POPEN_TPUTS) */ /* * Without terminal info support, just assume colour is * available. */ state->control.can_display_colour = true; debug("%s", "terminal info support not compiled in - assuming colour support"); -# endif /* (! ENABLE_NCURSES) && (! USE_POPEN_TPUTS) */ +#endif /* (! ENABLE_NCURSES) && (! USE_POPEN_TPUTS) */ #endif /* ! ENABLE_NCURSES */ } } diff --git a/src/pv/format/averagerate.c b/src/pv/format/averagerate.c index 906ec26..7787c1e 100644 --- a/src/pv/format/averagerate.c +++ b/src/pv/format/averagerate.c @@ -14,7 +14,7 @@ /* * Average transfer rate. */ -size_t pv_formatter_average_rate(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_average_rate(pvformatter_args_t args) { char content[128]; /* flawfinder: ignore - always bounded */ diff --git a/src/pv/format/barstyle.c b/src/pv/format/barstyle.c index f7b8450..1c83287 100644 --- a/src/pv/format/barstyle.c +++ b/src/pv/format/barstyle.c @@ -122,10 +122,10 @@ static bool pv_barstyle(pvformatter_args_t args, pvbarstyle_t style, const char * * If there is no room, returns zero, so the first style is re-used. */ -int pv_display_barstyle_index(pvformatter_args_t args, const char *name) +int8_t pv_display_barstyle_index(pvformatter_args_t args, const char *name) { struct pvbarstyle_s style; - int barstyle_index; + int8_t barstyle_index; #ifdef ENABLE_DEBUGGING bool found; #endif @@ -160,7 +160,7 @@ int pv_display_barstyle_index(pvformatter_args_t args, const char *name) } -size_t pv_formatter_bar_default(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_bar_default(pvformatter_args_t args) { if (0 == args->segment->parameter) { const char *default_name; @@ -175,28 +175,28 @@ size_t pv_formatter_bar_default(pvformatter_args_t args) return pv_formatter_progress_bar_only(args); } -size_t pv_formatter_bar_plain(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_bar_plain(pvformatter_args_t args) { if (0 == args->segment->parameter) args->segment->parameter = 1 + pv_display_barstyle_index(args, "plain"); return pv_formatter_progress_bar_only(args); } -size_t pv_formatter_bar_block(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_bar_block(pvformatter_args_t args) { if (0 == args->segment->parameter) args->segment->parameter = 1 + pv_display_barstyle_index(args, "block"); return pv_formatter_progress_bar_only(args); } -size_t pv_formatter_bar_granular(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_bar_granular(pvformatter_args_t args) { if (0 == args->segment->parameter) args->segment->parameter = 1 + pv_display_barstyle_index(args, "granular"); return pv_formatter_progress_bar_only(args); } -size_t pv_formatter_bar_shaded(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_bar_shaded(pvformatter_args_t args) { if (0 == args->segment->parameter) args->segment->parameter = 1 + pv_display_barstyle_index(args, "shaded"); diff --git a/src/pv/format/bufferpercent.c b/src/pv/format/bufferpercent.c index 4bb4db6..af523fc 100644 --- a/src/pv/format/bufferpercent.c +++ b/src/pv/format/bufferpercent.c @@ -14,7 +14,7 @@ /* * Percentage transfer buffer utilisation. */ -size_t pv_formatter_buffer_percent(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_buffer_percent(pvformatter_args_t args) { char content[16]; /* flawfinder: ignore - always bounded */ diff --git a/src/pv/format/bytes.c b/src/pv/format/bytes.c index f8c962a..865d481 100644 --- a/src/pv/format/bytes.c +++ b/src/pv/format/bytes.c @@ -14,7 +14,7 @@ /* * Number of bytes or lines transferred. */ -size_t pv_formatter_bytes(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_bytes(pvformatter_args_t args) { char content[128]; /* flawfinder: ignore - always bounded */ diff --git a/src/pv/format/eta.c b/src/pv/format/eta.c index 3e39bfa..4b1fcd1 100644 --- a/src/pv/format/eta.c +++ b/src/pv/format/eta.c @@ -14,7 +14,7 @@ /* * Estimated time until completion. */ -size_t pv_formatter_eta(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_eta(pvformatter_args_t args) { char content[128]; /* flawfinder: ignore - always bounded */ long eta; diff --git a/src/pv/format/fineta.c b/src/pv/format/fineta.c index 6581049..704ed60 100644 --- a/src/pv/format/fineta.c +++ b/src/pv/format/fineta.c @@ -18,7 +18,7 @@ /* * Estimated local time of completion. */ -size_t pv_formatter_fineta(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_fineta(pvformatter_args_t args) { char content[128]; /* flawfinder: ignore - always bounded */ time_t now, then; diff --git a/src/pv/format/lastwritten.c b/src/pv/format/lastwritten.c index 953cd09..b31d43f 100644 --- a/src/pv/format/lastwritten.c +++ b/src/pv/format/lastwritten.c @@ -17,9 +17,9 @@ * As a side effect, this sets args->display->lastwritten_bytes to * the segment's chosen_size, if it was previously smaller than that. */ -size_t pv_formatter_last_written(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_last_written(pvformatter_args_t args) { - size_t bytes_to_show, read_offset, write_offset, remaining; + pvdisplay_bytecount_t bytes_to_show, read_offset, write_offset, remaining; args->display->showing_last_written = true; diff --git a/src/pv/format/name.c b/src/pv/format/name.c index ed636a2..74a3caa 100644 --- a/src/pv/format/name.c +++ b/src/pv/format/name.c @@ -16,11 +16,11 @@ /* * Display the transfer's name. */ -size_t pv_formatter_name(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_name(pvformatter_args_t args) { char string_format[32]; /* flawfinder: ignore - always bounded */ char content[512]; /* flawfinder: ignore - always bounded */ - size_t field_width; + pvdisplay_bytecount_t field_width; if (0 == args->buffer_size) return 0; diff --git a/src/pv/format/previousline.c b/src/pv/format/previousline.c index 527d492..cdbc8be 100644 --- a/src/pv/format/previousline.c +++ b/src/pv/format/previousline.c @@ -14,9 +14,9 @@ /* * Display the previously written line. */ -size_t pv_formatter_previous_line(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_previous_line(pvformatter_args_t args) { - size_t bytes_to_show, read_offset, write_offset, remaining; + pvdisplay_bytecount_t bytes_to_show, read_offset, write_offset, remaining; args->display->showing_previous_line = true; diff --git a/src/pv/format/progressbar.c b/src/pv/format/progressbar.c index 4249138..803442e 100644 --- a/src/pv/format/progressbar.c +++ b/src/pv/format/progressbar.c @@ -41,15 +41,17 @@ * * This is only called by pv_formatter_progress(). */ -static size_t pv_formatter_progress_knownsize(pvformatter_args_t args, char *buffer, size_t buffer_size, bool bar_sides, - bool include_bar, bool include_amount) +static pvdisplay_bytecount_t pv_formatter_progress_knownsize(pvformatter_args_t args, char *buffer, + pvdisplay_bytecount_t buffer_size, bool bar_sides, + bool include_bar, bool include_amount) { char after_bar[32]; /* flawfinder: ignore - only populated by pv_snprintf(). */ - size_t after_bar_bytes, after_bar_width; - size_t bar_area_width, filled_bar_width, buffer_offset, pad_count; + pvdisplay_bytecount_t after_bar_bytes, buffer_offset; + pvdisplay_width_t after_bar_width; + pvdisplay_width_t bar_area_width, filled_bar_width, pad_count; double bar_percentage; pvbarstyle_t style; - size_t full_cell_index; + pvdisplay_bytecount_t full_cell_index; bool has_tip = false; buffer[0] = '\0'; @@ -127,7 +129,7 @@ static size_t pv_formatter_progress_knownsize(pvformatter_args_t args, char *buf bar_area_width = args->segment->width - after_bar_width; } - filled_bar_width = (size_t) ((bar_area_width * bar_percentage) / 100); + filled_bar_width = (pvdisplay_width_t) ((bar_area_width * bar_percentage) / 100); /* Leave room for the tip of the bar. */ if (has_tip && filled_bar_width > 0) filled_bar_width -= style->tip.width; @@ -209,11 +211,11 @@ static size_t pv_formatter_progress_knownsize(pvformatter_args_t args, char *buf * * This is only called by pv_formatter_progress(). */ -static size_t pv_formatter_progress_unknownsize(pvformatter_args_t args, char *buffer, - size_t buffer_size, bool bar_sides) +static pvdisplay_bytecount_t pv_formatter_progress_unknownsize(pvformatter_args_t args, char *buffer, + pvdisplay_bytecount_t buffer_size, bool bar_sides) { - size_t bar_area_width, buffer_offset, pad_count; - size_t indicator_position; + pvdisplay_bytecount_t buffer_offset; + pvdisplay_width_t bar_area_width, pad_count, indicator_position; pvbarstyle_t style; buffer[0] = '\0'; @@ -240,7 +242,7 @@ static size_t pv_formatter_progress_unknownsize(pvformatter_args_t args, char *b * here we make values above 100 send the indicator back down again, * so it moves back and forth. */ - indicator_position = (size_t) (args->state->calc.percentage); + indicator_position = (pvdisplay_width_t) (args->state->calc.percentage); if (indicator_position > 200) indicator_position = indicator_position % 200; if (indicator_position > 100 && indicator_position <= 200) @@ -290,10 +292,10 @@ static size_t pv_formatter_progress_unknownsize(pvformatter_args_t args, char *b /* * Progress bar. */ -size_t pv_formatter_progress(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_progress(pvformatter_args_t args) { char content[4096]; /* flawfinder: ignore - always bounded */ - size_t bytes; + pvdisplay_bytecount_t bytes; content[0] = '\0'; @@ -328,10 +330,10 @@ size_t pv_formatter_progress(pvformatter_args_t args) /* * Progress bar, without sides and without a number afterwards. */ -size_t pv_formatter_progress_bar_only(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_progress_bar_only(pvformatter_args_t args) { char content[4096]; /* flawfinder: ignore - always bounded */ - size_t bytes; + pvdisplay_bytecount_t bytes; content[0] = '\0'; @@ -366,10 +368,10 @@ size_t pv_formatter_progress_bar_only(pvformatter_args_t args) /* * The number after the progress bar. */ -size_t pv_formatter_progress_amount_only(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_progress_amount_only(pvformatter_args_t args) { char content[256]; /* flawfinder: ignore - always bounded */ - size_t bytes; + pvdisplay_bytecount_t bytes; content[0] = '\0'; diff --git a/src/pv/format/rate.c b/src/pv/format/rate.c index f2ea141..a255cb3 100644 --- a/src/pv/format/rate.c +++ b/src/pv/format/rate.c @@ -14,7 +14,7 @@ /* * Transfer rate. */ -size_t pv_formatter_rate(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_rate(pvformatter_args_t args) { char content[128]; /* flawfinder: ignore - always bounded */ diff --git a/src/pv/format/sgr.c b/src/pv/format/sgr.c index 35cf1e6..b43bcce 100644 --- a/src/pv/format/sgr.c +++ b/src/pv/format/sgr.c @@ -95,11 +95,11 @@ struct sgr_keyword_map_s { /* * Display SGR codes if colour output is supported. */ -size_t pv_formatter_sgr(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_sgr(pvformatter_args_t args) { /*@keep@ */ static struct sgr_keyword_map_s *keywords; char content[1024]; /* flawfinder: ignore */ - size_t write_position, read_position, keyword_start, keyword_length; + pvdisplay_bytecount_t write_position, read_position, keyword_start, keyword_length; int numeric_value, code_count, most_recent_code; /* flawfinder - null-terminated and bounded with pv_snprintf(). */ diff --git a/src/pv/format/timer.c b/src/pv/format/timer.c index eda6c04..3297d09 100644 --- a/src/pv/format/timer.c +++ b/src/pv/format/timer.c @@ -14,7 +14,7 @@ /* * Elapsed time. */ -size_t pv_formatter_timer(pvformatter_args_t args) +pvdisplay_bytecount_t pv_formatter_timer(pvformatter_args_t args) { char content[128]; /* flawfinder: ignore - always bounded */ diff --git a/src/pv/loop.c b/src/pv/loop.c index cb454d1..9d71f57 100644 --- a/src/pv/loop.c +++ b/src/pv/loop.c @@ -481,12 +481,14 @@ int pv_main_loop(pvstate_t state) state->flag.terminal_resized = 0; - new_width = state->control.width; + new_width = (unsigned int) (state->control.width); new_height = state->control.height; pv_screensize(&new_width, &new_height); + if (new_width > PVDISPLAY_WIDTH_MAX) + new_width = PVDISPLAY_WIDTH_MAX; if (!state->control.width_set_manually) - state->control.width = new_width; + state->control.width = (pvdisplay_width_t) new_width; if (!state->control.height_set_manually) state->control.height = new_height; } @@ -695,12 +697,15 @@ int pv_watchfd_loop(pvstate_t state) state->flag.terminal_resized = 0; - new_width = state->control.width; + new_width = (unsigned int) (state->control.width); new_height = state->control.height; pv_screensize(&new_width, &new_height); + if (new_width > PVDISPLAY_WIDTH_MAX) + new_width = PVDISPLAY_WIDTH_MAX; + if (!state->control.width_set_manually) - state->control.width = new_width; + state->control.width = (pvdisplay_width_t) new_width; if (!state->control.height_set_manually) state->control.height = new_height; } @@ -841,8 +846,20 @@ int pv_watchpid_loop(pvstate_t state) /* Resize the display, if a resize signal was received. */ if (1 == state->flag.terminal_resized) { + unsigned int new_width, new_height; + state->flag.terminal_resized = 0; - pv_screensize(&(state->control.width), &(state->control.height)); + + new_width = (unsigned int) (state->control.width); + new_height = state->control.height; + pv_screensize(&new_width, &new_height); + + if (new_width > PVDISPLAY_WIDTH_MAX) + new_width = PVDISPLAY_WIDTH_MAX; + + state->control.width = (pvdisplay_width_t) new_width; + state->control.height = new_height; + for (idx = 0; NULL != info_array && idx < array_length; idx++) { if (NULL == info_array[idx].state) continue; @@ -974,10 +991,10 @@ int pv_watchpid_loop(pvstate_t state) debug("%s: %d", "adding blank lines", blank_lines); while (blank_lines > 0) { - unsigned int x; + pvdisplay_width_t blank_count; if (displayed_lines > 0) pv_tty_write(state, "\n", 1); - for (x = 0; x < state->control.width; x++) + for (blank_count = 0; blank_count < state->control.width; blank_count++) pv_tty_write(state, " ", 1); pv_tty_write(state, "\r", 1); blank_lines--; @@ -997,8 +1014,8 @@ int pv_watchpid_loop(pvstate_t state) */ blank_lines = prev_displayed_lines; while (blank_lines > 0) { - unsigned int x; - for (x = 0; x < state->control.width; x++) + pvdisplay_width_t blank_count; + for (blank_count = 0; blank_count < state->control.width; blank_count++) pv_tty_write(state, " ", 1); pv_tty_write(state, "\r", 1); blank_lines--; diff --git a/src/pv/state.c b/src/pv/state.c index 4f76fd7..0de6e0c 100644 --- a/src/pv/state.c +++ b/src/pv/state.c @@ -414,7 +414,9 @@ void pv_state_interval_set(pvstate_t state, double val) void pv_state_width_set(pvstate_t state, unsigned int val, bool was_set_manually) { - state->control.width = val; + if (val > PVDISPLAY_WIDTH_MAX) + val = PVDISPLAY_WIDTH_MAX; + state->control.width = (pvdisplay_width_t) val; state->control.width_set_manually = was_set_manually; }