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

posh-git prompt makes PowerShell transcripts less readable #282

Closed
aaronmcdavid opened this issue May 11, 2016 · 14 comments
Closed

posh-git prompt makes PowerShell transcripts less readable #282

aaronmcdavid opened this issue May 11, 2016 · 14 comments

Comments

@aaronmcdavid
Copy link

With posh-git:

>

C:\devcd log-ssh
 [
master
 ≡
]
>

C:\dev\log-sshls


    Directory: C:\dev\log-ssh


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        4/28/2016   6:21 PM          35815 LICENSE
-a----        4/28/2016   6:25 PM           4477 Log-SSH.pl
-a----        4/28/2016   6:21 PM             74 README.md

Without posh-git:

PS C:\dev> cd log-ssh
PS C:\dev\log-ssh> ls


    Directory: C:\dev\log-ssh


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a----       2016-04-28     18:21      35815 LICENSE
-a----       2016-04-28     18:25       4477 Log-SSH.pl
-a----       2016-04-28     18:21         74 README.md

@dahlbyk
Copy link
Owner

dahlbyk commented May 11, 2016

What version of Windows/PowerShell? My transcripts on PS 4.0 seem to always show PS> as the prompt?

@aaronmcdavid
Copy link
Author

Windows:

Caption        : Microsoft Windows 7 Enterprise 
OSArchitecture : 64-bit

Powershell:

Name             : Windows PowerShell ISE Host
Version          : 5.0.10586.117

I'm using the following prompt replacement function, which I got from elsewhere in this repository. I'm thinking it's the standard thing to do, but maybe not:

    function global:prompt {
        $realLASTEXITCODE = $LASTEXITCODE
        $Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
        Write-Host($pwd.ProviderPath) -nonewline
        Write-VcsStatus
        $global:LASTEXITCODE = $realLASTEXITCODE
        return "> "
        }

@dahlbyk
Copy link
Owner

dahlbyk commented May 11, 2016

Ooh, it might have something to do with ISE? Do you see the same behavior in a normal host?

@aaronmcdavid
Copy link
Author

I do see similar behaviour:

PS>. 'C:\Users\«REDACTED»\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'

C:\dev
>
PS>cd Log-SSH
C:\dev\Log-SSH
 [
master
 ≡
]
>
PS>ls


    Directory: C:\dev\Log-SSH


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        4/28/2016   6:21 PM          35815 LICENSE
-a----        4/28/2016   6:25 PM           4477 Log-SSH.pl
-a----        4/28/2016   6:21 PM             74 README.md


C:\dev\Log-SSH
 [
master
 ≡
]
>
PS>exit
**********************
Windows PowerShell transcript end
End time: 20160511114455
**********************

@theaquamarine
Copy link
Collaborator

theaquamarine commented May 11, 2016

The same thing happens for me, it looks like the transcript doesn't obey Write-Host's -NoNewLine setting.

C:\Users\bluewrite-host "test"; write-host "test"; write-host "tested"
test
test
tested
>
C:\Users\blueecho "now with nonewline"
now with nonewline
>
C:\Users\bluewrite-host -NoNewline "test"; write-host -NoNewline "test"; write-host -NoNewline "tested"
test
test
tested
>
>
>

Edit: It looks like each command's output is logged separately (which makes sense), so unless the number of Write-Hosts involved in the prompt can be reduced, I'm not sure what can be done about this.

@aaronmcdavid
Copy link
Author

I had noticed that. I guess it's really PowerShell's transcription logic that's broken, not posh-git. I'm intrigued that the > appears before the rest of the Write-Hosts. Somehow the return value of the prompt function is getting to the transcript before the strings that are being Write-Host-ed.

@dahlbyk
Copy link
Owner

dahlbyk commented May 12, 2016

Very curious. Unless we were to replace the multi-Write-Host formatting with some sort of single ANSI color-ized string, I'm not sure there's anything we can do about this. Of course, now I am very curious if a multi-colored output is even possible with a single Write-Host.

@aaronmcdavid
Copy link
Author

I agree. I poked at the [Host.UI] object a little and got nowhere. Someone wrote a wrapper for Write-Host that processes ANSI color, but I think that, even should you be able to return the entire prompt, with colours, as a single string with ANSI codes, even then one would have to change the function that prints the return value of the global prompt function to something that understands ANSI codes. I don't know enough about PowerShell / .NET to dig that deep.

@lzybkr
Copy link
Collaborator

lzybkr commented May 12, 2016

ANSI escape sequences are supported in the very latest Windows 10 insider builds (basically anything later than the November update).

PowerShell 5.1 (not yet available outside of the latest Windows Insider builds) adds a new property you can test to see if ANSI escape sequences are supported: $host.UI.SupportsVirtualTerminal

So you could write something like:

if ($PSVersionTable['PSVersion'] -ge "5.1" -and $host.UI.SupportsVirtualTerminal)
{
    $CSI = [char]0x1b + '['
    "${CSI}31mHello${CSI}32m World${CSI}0m"
}
else
{
    Write-Host -ForegroundColor DarkRed -NoNewline Hello; Write-Host -ForegroundColor DarkGreen ' World'
}

You can read more about which sequences are supported here: https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032%28v=vs.85%29.aspx

@dahlbyk
Copy link
Owner

dahlbyk commented Sep 16, 2016

Completely forgot about this. ANSI support is in progress: #304

@dahlbyk
Copy link
Owner

dahlbyk commented Mar 3, 2017

develop now has basic ANSI support, and transcripts are indeed fixed:
image

Though something funky is going on with the prompt on lines with commands:
image

@Jaykul
Copy link

Jaykul commented Mar 27, 2017

Not sure what to say about that one, @dahlbyk -- I mean, the escape sequences are in the log...

  1. PowerShell could strip them so they're not logged
  2. Or, you could remove them if you don't want them
  3. Or, you could read them somewhere that renders them (i.e. if you run that to the console, it'll render in color)

@dahlbyk
Copy link
Owner

dahlbyk commented Mar 27, 2017

To clarify, by "something funky" I mean that the first and last lines with AnsiConsole have a truncated prompt string than doesn't include the escape sequences, while the middle two lines show the full prompt (with escape sequences, as expected).

@dahlbyk
Copy link
Owner

dahlbyk commented Jan 10, 2018

I'm going to go ahead and close this. ANSI support in 1.0 seems to improve the situation enough.

@dahlbyk dahlbyk closed this as completed Jan 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants