Make PSReadline render correct portion of prompt on Unix when it's a multi-line string #3867
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.
Issue Summary
My

prompt
function returns a multi-line string. On Linux, when typing any input,PSReadline
tries to render the whole prompt string again, instead of just the portion that is shown on the current line, which results in a bad prompt:Fix
Check whether the prompt is multi-line or not. If it is, then only use the part that is shown in the input line.
Additional Info
I am using VT100 escape sequences to colorize my prompt string, and I found that PSReadline doesn't work with VT100 on Unix, because it's calling
Console.Write(Char)
instead ofConsole.Write(String)
(see code here). I tried to fix that along with this PR, but it turns out to be not trivial, so I will postpone that fix to another PR.Since PSReadline doesn't work with VT100 on Unix yet, you need to make sure that the part of the prompt string shown on the input line does not contain any escape sequences. Otherwise, you will see random characters like in the above screenshot.
Prompt function I use on Unix
I think it would be useful to share the prompt function I'm using on Unix. It works fine with this fix.