From ffd4754cb2237718cec9d6b5697122bed6a3d7c8 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 3 Dec 2016 13:35:24 -0800 Subject: [PATCH] Don't show the pager on terminals of height less than 4 Prevents some potential overflow bugs and janky UI --- src/pager.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pager.cpp b/src/pager.cpp index 399d24566..0dcf13b93 100644 --- a/src/pager.cpp +++ b/src/pager.cpp @@ -26,6 +26,9 @@ typedef std::vector comp_info_list_t; /// The minimum width (in characters) the terminal must to show completions at all. #define PAGER_MIN_WIDTH 16 +/// Minimum height to show completions +#define PAGER_MIN_HEIGHT 4 + /// The maximum number of columns of completion to attempt to fit onto the screen. #define PAGER_MAX_COLS 6 @@ -379,9 +382,11 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co // The calculated preferred width of each column. size_t width_by_column[PAGER_MAX_COLS] = {0}; + // Skip completions on tiny terminals. + if (this->available_term_width < PAGER_MIN_WIDTH || this->available_term_height < PAGER_MIN_HEIGHT) return true; + // Compute the effective term width and term height, accounting for disclosure. size_t term_width = this->available_term_width; - // FIXME arithmetic size_t term_height = this->available_term_height - 1 - (search_field_shown ? 1 : 0); // we always subtract 1 to make room for a comment row if (!this->fully_disclosed) { term_height = mini(term_height, (size_t)PAGER_UNDISCLOSED_MAX_ROWS); @@ -404,9 +409,6 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co rendering->remaining_to_disclose = 0; } - // Skip completions on tiny terminals. - if (term_width < PAGER_MIN_WIDTH) return true; - // Calculate how wide the list would be. for (size_t col = 0; col < cols; col++) { for (size_t row = 0; row < row_count; row++) {