Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the cursor to the beginning before printing right prompt #8011

Merged
merged 2 commits into from May 18, 2021

Conversation

faho
Copy link
Member

@faho faho commented May 17, 2021

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.

A screenshot:

Screenshot_20210517_173936

Here fish and gnome-terminal disagree on the width of (U+2606 WHITE STAR). The first shell has the staircase effect, the second has this patch applied.

The cursor is still wrong - the final line has echo ☆123, and the cursor is logically after the 3. However, that's much less annoying than the staircase.

The cost of this is one cursor move to the start (a \r, typically) and longer move to the right prompt per printing of the right prompt, which should be acceptable.

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

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.
@faho faho added this to the fish 3.3.0 milestone May 17, 2021
@faho
Copy link
Member Author

faho commented May 17, 2021

Weirdly enough this now means it works better with a right prompt.

I'm not completely sure why, it's possible we remove a dependency on "current_width" for something more. Just unconditionally doing the move back to 0 before the right prompt improves things also for situations without a right prompt. I imagine that's probably too chatty, so maybe once before the right prompt and once after the last line?

@ridiculousfish
Copy link
Member

LGTM!

This helps with width issues when no right prompt is used.
@faho faho merged commit 25595a9 into fish-shell:master May 18, 2021
@faho
Copy link
Member Author

faho commented May 18, 2021

Merged with an additional move after printing everything, which appears to make fish almost usable with broken width.

@faho faho deleted the move-cursor-back-first branch May 18, 2021 07:10
aborodin added a commit to MidnightCommander/mc that referenced this pull request Jul 3, 2021
Fish 3.3.0 sends \r while printing prompt and mc erases prompt buffer.
This change was introduced by
fish-shell/fish-shell#8011.

(parse_subshell_prompt_string): modify subshell promt parsing.
First, skip trailing EOL (\n and \r). Then find previous EOL (if it
exists).
Get a part of subshell prompt between those EOLs and use it as
MC prompt.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants