8000 Make PSReadline render correct portion of prompt on Unix when it's a multi-line string by daxian-dbw · Pull Request #3867 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Make PSReadline render correct portion of prompt on Unix when it's a multi-line string #3867

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

Merged
merged 2 commits into from
May 26, 2017

Conversation

daxian-dbw
Copy link
Member

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:
image

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 of Console.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.

function Prompt
{
    $id = 1
    $historyItem = Get-History -Count 1
    if ($historyItem)
    {
        $id = $historyItem.Id + 1
    }

    if ($host.UI.SupportsVirtualTerminal)
    {
        $CSI = [char]0x1b + '['
        "${CSI}00m${CSI}01;30m[$($executionContext.SessionState.Path.CurrentLocation)]${CSI}00m`nPS:${id}$('>' * ($nestedPromptLevel + 1)) "
    }
    else
    {
        
        Write-Host -ForegroundColor DarkGray "[$($executionContext.SessionState.Path.CurrentLocation)]"
        "PS:$id$('>' * ($nestedPromptLevel + 1)) "
    }
}

@vors
Copy link
Collaborator
vors commented May 25, 2017

Yay! ref to the PSReadLine issue PowerShell/PSReadLine#470

@daxian-dbw daxian-dbw self-assigned this May 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0