mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-07 01:51:14 -03:00
Teach screen how to render completion page. Correct spacing in
completion page contents.
This commit is contained in:
10
pager.cpp
10
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);
|
written += print_max(L" ", 0, 1, false, &line_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 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;
|
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 row = row_start; row < row_stop; row++)
|
||||||
{
|
{
|
||||||
for (size_t col = 0; col < cols; col++)
|
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" */
|
/* 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);
|
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 */
|
/* Append this to the real line */
|
||||||
rendering->screen_data.create_line(row).append_line(line);
|
rendering->screen_data.create_line(row).append_line(line);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ RESOLVE(statement)
|
|||||||
if (token1.type == parse_token_type_string)
|
if (token1.type == parse_token_type_string)
|
||||||
{
|
{
|
||||||
// If we are a function, then look for help arguments
|
// 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)
|
if (token1.keyword == parse_keyword_function && token2.is_help_argument)
|
||||||
{
|
{
|
||||||
return 4;
|
return 4;
|
||||||
|
|||||||
32
reader.cpp
32
reader.cpp
@@ -100,6 +100,7 @@ commence.
|
|||||||
#include "parse_util.h"
|
#include "parse_util.h"
|
||||||
#include "parser_keywords.h"
|
#include "parser_keywords.h"
|
||||||
#include "parse_tree.h"
|
#include "parse_tree.h"
|
||||||
|
#include "pager.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Maximum length of prefix string when printing completion
|
Maximum length of prefix string when printing completion
|
||||||
@@ -199,6 +200,9 @@ public:
|
|||||||
|
|
||||||
/** String containing the autosuggestion */
|
/** String containing the autosuggestion */
|
||||||
wcstring autosuggestion;
|
wcstring autosuggestion;
|
||||||
|
|
||||||
|
/** Current completions */
|
||||||
|
page_rendering_t completion_page_rendering;
|
||||||
|
|
||||||
/** Whether autosuggesting is allowed at all */
|
/** Whether autosuggesting is allowed at all */
|
||||||
bool allow_autosuggestion;
|
bool allow_autosuggestion;
|
||||||
@@ -541,7 +545,8 @@ static void reader_repaint()
|
|||||||
data->command_length(),
|
data->command_length(),
|
||||||
&colors[0],
|
&colors[0],
|
||||||
&indents[0],
|
&indents[0],
|
||||||
data->buff_pos);
|
data->buff_pos,
|
||||||
|
&data->completion_page_rendering.screen_data);
|
||||||
|
|
||||||
data->repaint_needed = false;
|
data->repaint_needed = false;
|
||||||
}
|
}
|
||||||
@@ -1852,14 +1857,25 @@ static bool handle_completions(const std::vector<completion_t> &comp)
|
|||||||
wchar_t quote;
|
wchar_t quote;
|
||||||
parse_util_get_parameter_info(data->command_line, data->buff_pos, "e, NULL, NULL);
|
parse_util_get_parameter_info(data->command_line, data->buff_pos, "e, NULL, NULL);
|
||||||
is_quoted = (quote != L'\0');
|
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) */
|
write_loop(1, "\n", 1);
|
||||||
if (! data->autosuggestion.empty())
|
|
||||||
reader_repaint_without_autosuggestion();
|
|
||||||
|
|
||||||
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);
|
s_reset(&data->screen, screen_reset_abandon_line);
|
||||||
reader_repaint();
|
reader_repaint();
|
||||||
@@ -3189,7 +3205,7 @@ const wchar_t *reader_readline(void)
|
|||||||
/* Munge our completions */
|
/* Munge our completions */
|
||||||
sort_and_make_unique(comp);
|
sort_and_make_unique(comp);
|
||||||
prioritize_completions(comp);
|
prioritize_completions(comp);
|
||||||
|
|
||||||
/* Record our cycle_command_line */
|
/* Record our cycle_command_line */
|
||||||
cycle_command_line = data->command_line;
|
cycle_command_line = data->command_line;
|
||||||
cycle_cursor_pos = data->buff_pos;
|
cycle_cursor_pos = data->buff_pos;
|
||||||
|
|||||||
10
screen.cpp
10
screen.cpp
@@ -1234,7 +1234,8 @@ void s_write(screen_t *s,
|
|||||||
size_t explicit_len,
|
size_t explicit_len,
|
||||||
const int *colors,
|
const int *colors,
|
||||||
const int *indent,
|
const int *indent,
|
||||||
size_t cursor_pos)
|
size_t cursor_pos,
|
||||||
|
const screen_data_t *pager_data)
|
||||||
{
|
{
|
||||||
screen_data_t::cursor_t cursor_arr;
|
screen_data_t::cursor_t cursor_arr;
|
||||||
|
|
||||||
@@ -1321,6 +1322,13 @@ void s_write(screen_t *s,
|
|||||||
}
|
}
|
||||||
|
|
||||||
s->desired.cursor = cursor_arr;
|
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_update(s, layout.left_prompt.c_str(), layout.right_prompt.c_str());
|
||||||
s_save_status(s);
|
s_save_status(s);
|
||||||
}
|
}
|
||||||
|
|||||||
8
screen.h
8
screen.h
@@ -109,6 +109,11 @@ class screen_data_t
|
|||||||
{
|
{
|
||||||
return line_datas.size();
|
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,
|
size_t explicit_len,
|
||||||
const int *colors,
|
const int *colors,
|
||||||
const int *indent,
|
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
|
This function resets the screen buffers internal knowledge about
|
||||||
|
|||||||
Reference in New Issue
Block a user