Move the cursor to the beginning before printing right prompt

This makes the right prompt position independent of the width of the
commandline, which prevents staircase effects. That means, with "X"
standing in as a character that the terminal and fish disagree on:

```
> echo X           rightprompt
```

will stay like that instead of creating a staircase like

```
> echo X            rightpromp
t> echo X             rightpromp
pt> echo X
```

and so on.

The cursor still won't be *correct*, but it will be wrong in a less
annoying way.
This commit is contained in:
Fabian Homborg 2021-05-17 17:34:41 +02:00
parent d3ceba107e
commit 0660ea5be7

View File

@ -877,6 +877,9 @@ static void s_update(screen_t *scr, const wcstring &left_prompt, const wcstring
// Output any rprompt if this is the first line.
if (i == 0 && right_prompt_width > 0) { //!OCLINT(Use early exit/continue)
// Move the cursor to the beginning of the line first to be independent of the width.
// This helps prevent staircase effects if fish and the terminal disagree.
s_move(scr, 0, 0);
s_move(scr, static_cast<int>(screen_width - right_prompt_width), static_cast<int>(i));
set_color(highlight_spec_t{});
s_write_str(scr, right_prompt.c_str());