diff --git a/pager.cpp b/pager.cpp index fefe604ab..8eb729f8e 100644 --- a/pager.cpp +++ b/pager.cpp @@ -416,6 +416,7 @@ line_t pager_t::completion_print_item(const wcstring &prefix, const comp_t *c, s written += print_max(L" ", 0, 1, false, &line_data); } } + return line_data; } @@ -436,6 +437,8 @@ void pager_t::completion_print(int cols, int *width_per_column, int row_start, i size_t rows = (lst.size()-1)/cols+1; + fprintf(stderr, "prefix: %ls\n", prefix.c_str()); + for (size_t row = row_start; row < row_stop; row++) { for (size_t col = 0; col < cols; col++) @@ -450,6 +453,13 @@ void pager_t::completion_print(int cols, int *width_per_column, int row_start, i /* Print this completion on its own "line" */ line_t line = completion_print_item(prefix, el, row, col, width_per_column[col] - (is_last?0:2), row%2, rendering); + /* If there's more to come, append two spaces */ + if (col + 1 < cols) + { + line.append(L' ', 0); + line.append(L' ', 0); + } + /* Append this to the real line */ rendering->screen_data.create_line(row).append_line(line); } diff --git a/parse_productions.cpp b/parse_productions.cpp index 311d68086..4f40ce614 100644 --- a/parse_productions.cpp +++ b/parse_productions.cpp @@ -126,7 +126,7 @@ RESOLVE(statement) if (token1.type == parse_token_type_string) { // If we are a function, then look for help arguments - // Othewrise, if the next token looks like an option (starts with a dash), then parse it as a decorated statement + // Otherwise, if the next token looks like an option (starts with a dash), then parse it as a decorated statement if (token1.keyword == parse_keyword_function && token2.is_help_argument) { return 4; diff --git a/reader.cpp b/reader.cpp index 6cf77ae41..5a45cd9e3 100644 --- a/reader.cpp +++ b/reader.cpp @@ -100,6 +100,7 @@ commence. #include "parse_util.h" #include "parser_keywords.h" #include "parse_tree.h" +#include "pager.h" /** Maximum length of prefix string when printing completion @@ -199,6 +200,9 @@ public: /** String containing the autosuggestion */ wcstring autosuggestion; + + /** Current completions */ + page_rendering_t completion_page_rendering; /** Whether autosuggesting is allowed at all */ bool allow_autosuggestion; @@ -541,7 +545,8 @@ static void reader_repaint() data->command_length(), &colors[0], &indents[0], - data->buff_pos); + data->buff_pos, + &data->completion_page_rendering.screen_data); data->repaint_needed = false; } @@ -1852,14 +1857,25 @@ static bool handle_completions(const std::vector &comp) wchar_t quote; parse_util_get_parameter_info(data->command_line, data->buff_pos, "e, NULL, NULL); is_quoted = (quote != L'\0'); + + if (1) + { + pager_t pager; + pager.set_term_size(common_get_width(), common_get_height()); + pager.prefix = prefix; + pager.set_completions(surviving_completions); + data->completion_page_rendering = pager.render(); + } + else + { + /* Clear the autosuggestion from the old commandline before abandoning it (see #561) */ + if (! data->autosuggestion.empty()) + reader_repaint_without_autosuggestion(); - /* Clear the autosuggestion from the old commandline before abandoning it (see #561) */ - if (! data->autosuggestion.empty()) - reader_repaint_without_autosuggestion(); + write_loop(1, "\n", 1); - write_loop(1, "\n", 1); - - run_pager(prefix, is_quoted, surviving_completions); + run_pager(prefix, is_quoted, surviving_completions); + } } s_reset(&data->screen, screen_reset_abandon_line); reader_repaint(); @@ -3189,7 +3205,7 @@ const wchar_t *reader_readline(void) /* Munge our completions */ sort_and_make_unique(comp); prioritize_completions(comp); - + /* Record our cycle_command_line */ cycle_command_line = data->command_line; cycle_cursor_pos = data->buff_pos; diff --git a/screen.cpp b/screen.cpp index 711aebabd..fe283ac84 100644 --- a/screen.cpp +++ b/screen.cpp @@ -1234,7 +1234,8 @@ void s_write(screen_t *s, size_t explicit_len, const int *colors, const int *indent, - size_t cursor_pos) + size_t cursor_pos, + const screen_data_t *pager_data) { screen_data_t::cursor_t cursor_arr; @@ -1321,6 +1322,13 @@ void s_write(screen_t *s, } s->desired.cursor = cursor_arr; + + /* append pager_data */ + if (pager_data != NULL) + { + s->desired.append_lines(*pager_data); + } + s_update(s, layout.left_prompt.c_str(), layout.right_prompt.c_str()); s_save_status(s); } diff --git a/screen.h b/screen.h index 8e23002eb..7ff8fb0f5 100644 --- a/screen.h +++ b/screen.h @@ -109,6 +109,11 @@ class screen_data_t { return line_datas.size(); } + + void append_lines(const screen_data_t &d) + { + this->line_datas.insert(this->line_datas.end(), d.line_datas.begin(), d.line_datas.end()); + } }; /** @@ -196,7 +201,8 @@ void s_write(screen_t *s, size_t explicit_len, const int *colors, const int *indent, - size_t cursor_pos); + size_t cursor_pos, + const screen_data_t *pager_data); /** This function resets the screen buffers internal knowledge about