From a87970fbb5061360d9f0168bfc5ecbd9abca9fdc Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 4 Feb 2018 14:14:37 -0800 Subject: [PATCH] Have the pager use a simple newline count to determine reserved lines When the pager wants to use the full screen to show many options, it reserves space at the top to see the command. Previously it pretended the command was a prompt and engaged the prompt layout mechanism to compute these lines. Instead let's juts count newlines since escape sequences within commands are very rare. --- src/reader.cpp | 9 +++++---- src/screen.cpp | 2 +- src/screen.h | 3 --- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index 90fa55733..6c86c786d 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -434,11 +434,12 @@ static void reader_repaint() { std::vector indents = data->indents; indents.resize(len); - // Re-render our completions page if necessary. We set the term size to less than the true - // term height by the number of prompt lines. This means we will always show the entire line of - // the prompt. + // Re-render our completions page if necessary. Limit the term size of the pager to the true + // term size, minus the number of lines consumed by our string. (Note this doesn't yet consider + // wrapping). + int full_line_count = 1 + std::count(full_line.begin(), full_line.end(), '\n'); data->pager.set_term_size(maxi(1, common_get_width()), - maxi(1, common_get_height() - (int)calc_prompt_lines(full_line))); + maxi(1, common_get_height() - full_line_count)); data->pager.update_rendering(&data->current_page_rendering); bool focused_on_pager = data->active_edit_line() == &data->pager.search_field_line; diff --git a/src/screen.cpp b/src/screen.cpp index c26142fff..3b5950e01 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -346,7 +346,7 @@ static prompt_layout_t calc_prompt_layout(const wchar_t *prompt, prompt_type_t w return prompt_layout; } -size_t calc_prompt_lines(const wcstring &prompt) { +static size_t calc_prompt_lines(const wcstring &prompt) { // Hack for the common case where there's no newline at all. I don't know if a newline can // appear in an escape sequence, so if we detect a newline we have to defer to // calc_prompt_width_and_lines. diff --git a/src/screen.h b/src/screen.h index 11eb607e4..b7897bf5f 100644 --- a/src/screen.h +++ b/src/screen.h @@ -240,7 +240,4 @@ class cached_esc_sequences_t { // change by calling `cached_esc_sequences.clear()`. extern cached_esc_sequences_t cached_esc_sequences; -// Calculates the number of prompt lines. -size_t calc_prompt_lines(const wcstring &prompt); - #endif