Make PSReadline render correct portion of prompt on Unix when it's a multi-line string#3867
Merged
daxian-dbw merged 2 commits intoPowerShell:masterfrom May 26, 2017
Merged
Conversation
Collaborator
|
Yay! ref to the PSReadLine issue PowerShell/PSReadLine#470 |
lzybkr
approved these changes
May 26, 2017
This was referenced May 26, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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

promptfunction returns a multi-line string. On Linux, when typing any input,PSReadlinetries 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.