Add workaround for Midnight Commander's issue with prompt extraction #9540
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When we draw the prompt, we move the cursor to the actual position we think it is by issuing a carriage return (via
move(0,0)
), and then going forward until we hit the spot.This helps when the terminal and fish disagree on the width of the prompt, because we are now definitely in the correct place, so we can only overwrite a bit of the prompt (if it renders longer than we expected) or leave space after the prompt. Both of these are benign in comparison to staircase effects we would otherwise get.
Unfortunately, midnight commander ("mc") tries to extract the last line of the prompt, and does so in a way that is overly naive - it resets everything to 0 when it sees a
\r
, and doesn't account for cursor movement. In effect it's playing a terminal, but not committing to the bit.Since this has been an open request in mc for quite a while, we hack around it, by checking the $MC_SID environment variable.
If we see it, we skip the clearing. We end up most likely doing relative movement from where we think we are, and in most cases it should be fine.
TODOs: