Teach screen how to render completion page. Correct spacing in

completion page contents.
This commit is contained in:
ridiculousfish
2014-01-14 15:39:53 -08:00
parent 4a20febe96
commit 295c8f48a6
5 changed files with 51 additions and 11 deletions

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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<completion_t> &comp)
wchar_t quote;
parse_util_get_parameter_info(data->command_line, data->buff_pos, &quote, 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;

View File

@@ -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);
}

View File

@@ -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