mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
Prevent multi-line prompts from repeating during window resize
Fixes https://github.com/fish-shell/fish-shell/issues/321
This commit is contained in:
parent
211b9ea8b9
commit
618b42980d
1 changed files with 95 additions and 67 deletions
34
screen.cpp
34
screen.cpp
|
@ -162,10 +162,11 @@ static bool allow_soft_wrap(void)
|
||||||
to detect common escape sequences that may be embeded in a prompt,
|
to detect common escape sequences that may be embeded in a prompt,
|
||||||
such as color codes.
|
such as color codes.
|
||||||
*/
|
*/
|
||||||
static size_t calc_prompt_width( const wchar_t *prompt )
|
static size_t calc_prompt_width_and_lines( const wchar_t *prompt, size_t *out_prompt_lines )
|
||||||
{
|
{
|
||||||
size_t res = 0;
|
size_t res = 0;
|
||||||
size_t j, k;
|
size_t j, k;
|
||||||
|
*out_prompt_lines = 1;
|
||||||
|
|
||||||
for( j=0; prompt[j]; j++ )
|
for( j=0; prompt[j]; j++ )
|
||||||
{
|
{
|
||||||
|
@ -305,6 +306,7 @@ static size_t calc_prompt_width( const wchar_t *prompt )
|
||||||
else if( prompt[j] == L'\n' )
|
else if( prompt[j] == L'\n' )
|
||||||
{
|
{
|
||||||
res = 0;
|
res = 0;
|
||||||
|
*out_prompt_lines += 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -317,6 +319,25 @@ static size_t calc_prompt_width( const wchar_t *prompt )
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t calc_prompt_width(const wchar_t *prompt)
|
||||||
|
{
|
||||||
|
size_t ignored;
|
||||||
|
return calc_prompt_width_and_lines(prompt, &ignored);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t calc_prompt_lines(const wchar_t *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
|
||||||
|
size_t result = 1;
|
||||||
|
if (wcschr(prompt, L'\n') != NULL)
|
||||||
|
{
|
||||||
|
calc_prompt_width_and_lines(prompt, &result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Test if there is space between the time fields of struct stat to
|
Test if there is space between the time fields of struct stat to
|
||||||
use for sub second information. If so, we assume this space
|
use for sub second information. If so, we assume this space
|
||||||
|
@ -989,9 +1010,16 @@ void s_reset( screen_t *s, bool reset_cursor )
|
||||||
s->actual_lines_before_reset = s->actual.line_count();
|
s->actual_lines_before_reset = s->actual.line_count();
|
||||||
|
|
||||||
int prev_line = s->actual.cursor.y;
|
int prev_line = s->actual.cursor.y;
|
||||||
|
|
||||||
|
/* If the prompt is multi-line, we need to move up to the prompt's initial line. We do this by lying to ourselves and claiming that we're really below what we consider "line 0" (which is the last line of the prompt). This will cause is to move up to try to get back to line 0, but really we're getting back to the initial line of the prompt. */
|
||||||
|
const size_t prompt_line_count = calc_prompt_lines(s->actual_prompt.c_str());
|
||||||
|
assert(prompt_line_count >= 1);
|
||||||
|
prev_line += (prompt_line_count - 1);
|
||||||
|
|
||||||
s->actual.resize(0);
|
s->actual.resize(0);
|
||||||
s->actual.cursor.x = s->actual.cursor.y = 0;
|
s->actual.cursor.x = 0;
|
||||||
s->actual_prompt = L"";
|
s->actual.cursor.y = 0;
|
||||||
|
s->actual_prompt.clear();
|
||||||
s->need_clear=true;
|
s->need_clear=true;
|
||||||
|
|
||||||
if( !reset_cursor )
|
if( !reset_cursor )
|
||||||
|
|
Loading…
Reference in a new issue