-
-
Notifications
You must be signed in to change notification settings - Fork 809
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
Prompt only renders in ansi #771
Comments
I have a few questions. What is PS running in? PowerShell console, Windows Terminal, ConEmu, Cmder, etc? What do you get for |
Thanks for the extra information! That helps narrow things down. Can you check a couple of other things? Run |
Done.
|
I wonder if this is related to some console mode tweaks posh-git makes. Can you go to the directory where posh-git is installed and open if (($PSVersionTable.PSVersion.Major -ge 6) -and !$IsWindows) { to this: if ($PSVersionTable.PSVersion.Major -ge 6) { This will prevent the console mode tweaks. Try importing the modified module in a If the above doesn't fix it then there is only one other thing that I can think of. That is the # Open a fresh pwsh -noprofile session
# The following ANSI string should display correctly:
"D:\tvfischer\Devs\git\PoSHsnippets `e[93m[`e[39m`e[92mfvt-azshara`e[39m`e[92m ↑12`e[39m`e[31m +4`e[39m`e[31m ~1`e[39m`e[31m -0`e[39m`e[31m!`e[39m`e[93m]`e[39m>"
# This bit is essentially what the Invoke-Utf8ConsoleCommand does without the error checking
$currentEncoding = [Console]::OutputEncoding
$currentEncoding.IsSingleByte
if ($currentEncoding.IsSingleByte) { [Console]::OutputEncoding = [Text.Encoding]::UTF8 }
git -c core.quotepath=false -c color.status=false status -unormal --short --branch 2>$null
if ($currentEncoding.IsSingleByte) { [Console]::OutputEncoding = $currentEncoding }
# Now see if the ANSI string still displays correctly:
"D:\tvfischer\Devs\git\PoSHsnippets `e[93m[`e[39m`e[92mfvt-azshara`e[39m`e[92m ↑12`e[39m`e[31m +4`e[39m`e[31m ~1`e[39m`e[31m -0`e[39m`e[31m!`e[39m`e[93m]`e[39m>" Sorry for asking this of you. It would be easier if I could repro this but I haven't been able to. Anyway, I appreciate your willingness to help! |
I'm not sure if this would have any impact but I use cygwin and the default |
Good observation. Thanks because I was running out of things to try and possible failure mechanisms. BTW if you set |
yes it does. I ran
So i guess the question is how do we make this automatic or improve the module to handle this scenario |
Another fix would be to use Git for Windows but yeah, there's something going on with the |
it's funny though, cause I checked the git packages in
|
I believe console apps have to declare that they support ANSI console mode. Perhaps these mingw-based versions of Git haven't done that yet. See this comment: PowerShell/PowerShell#11449 (comment) and a follow tweak to someone's console app: dialex/JColor@baa3b95#diff-df3dc36270b358a02b972f5066b69a74R332 |
Just as an FYI, I get the same results in ConEmu (v 191012 [64]) with all the suggested ideas. When I switch off ANSI, I get the listing of PowerShell color settings in the middle of the prompt using just: $prompt += & $GitPromptScriptBlock
if ($prompt) { "$prompt" } else { "" } With my prompt (a little complex, but works well for me...) and ANSI on, I don't see the prompt at all. But turn it off, I get the PS settings mixed in. My prompt function: function global:prompt {
if (Test-Administrator) { # Use different username if elevated
$prompt = Write-Prompt "(Elevated) " -ForegroundColor DarkRed
}
else {
$prompt = ""
}
if ($versionIs51) {
$charge = Get-WmiObject Win32_Battery -Property EstimatedChargeRemaining
}
else {
$charge = Get-CimInstance Win32_Battery -Property EstimatedChargeRemaining
}
$chargeAlert = "Gray"
if ($charge.EstimatedChargeRemaining -lt 50)
{
$chargeAlert = "Yellow"
}
if ($charge.EstimatedChargeRemaining -lt 25)
{
$chargeAlert = "Red"
}
if ($charge.EstimatedChargeRemaining -lt 50) {
$prompt += Write-Prompt "Batt $($charge.EstimatedChargeRemaining)% : " -ForegroundColor $chargeAlert
}
$prompt += Write-Prompt "$Env:USERNAME@" -ForegroundColor DarkYellow
$prompt += Write-Prompt "$Env:COMPUTERNAME : " -ForegroundColor DarkGray
$GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true
$GitPromptSettings.DefaultPromptSuffix = '`n$(">" * ($nestedPromptLevel + 1)) '
#$GitPromptSettings.DefaultPromptDebugSuffix = '`n [DBG]$(">" * ($nestedPromptLevel + 1)) '
$prompt += Write-Prompt "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") : " -ForegroundColor DarkCyan
$prompt += & $GitPromptScriptBlock
if ($prompt) { "$prompt" } else { "" }
} What it should look like... Just thought I'd throw this in for added info about what is going on with what I see. Going back to PS 5 for a while... ;) (J/K, I'll live with the dead prompt until you get something worked out to try again.) |
So turning off ANSI seems to fix cygwin, but I'd generally expect cygwin to understand ANSI so we should be able to fix it somehow.
@tvfischer to clarify, by "this helped" do you mean the prompt works as expected with In #771 (comment) you tried a few ANSI tests in a clean shell. I'd be curious if ANSI continues to work after you've run cygwin
This seems like a bug/quirk we could fix. With |
Here ya go... From a git repository:
Outside of a git repo, the prompt works fine. Let me know if you need anything else! |
Someone reached out by email the other day with a similar issue. Switching from cygwin I just noticed the reported
I'm at a loss here. Is there some way you might be loading posh-git twice resulting in different types of the same name? |
@DHowett does anything here ring a bell to you? |
This one is pretty terrible and utterly unavoidable 😄 I did an investigation in microsoft/terminal#4921 (comment). In short, the Cygwin/MSYS2 runtime likes to fiddle with the console mode, even after a process has detached from the console. We've seen instances of git (though it's just a stand-in for any Cygwin application) turning off VT handling in the middle of powershell printing its colored prompt. Turning it back on would be an endless arms race... but there's hope that the Cygwin runtime >=3.1 helps? |
@tvfischer (or anyone with Git for Cygwin handy) when you have a moment, could you check if #807 shows you a warning and works (turns off |
Something to add with the issues I commented on, the prompt appears "correctly" with the extra config parameters when there are waiting commits to be pushed. Otherwise, it is the |
I load it once in my profile based on the version of PS I'm running. # Make things pretty...
Write-Host "Setting prompt..." -ForegroundColor DarkGreen
if ($null -ne (Get-InstalledModule -Name "posh-git")) {
if (($versionIs51)) {
Import-Module posh-git
}
else {
Import-Module 'C:\Program Files\PowerShell\7-preview\Modules\posh-git\src\posh-git.psd1'
}
} Since I need to debug in 5.1 for other dev purposes, it has to be this way until someone at work here decides to upgrade a couple thousand Win10 clients to 7.1... ;) |
Ok, I thought that upgrading to PS preview 7.2 had fixed my prompt. It had. Until I fixed the profile situation. It seems that any custom rendering fails. If I remove my custom prompt from the equation, posh-git prompt works flawlessly with the standard prompt configuration. At least there's that much more info to go on... |
@tvfischer have you found posh-git v1.x doesn't work in PS 5.1? It should, so you shouldn't need the conditional import. Can you try adding |
If the module only gets imported once, I am not sure what else to try. I assume you are still getting the same type assignment error? |
I ran into a similar problem, and can reproduce it with PowerShell echo (Write-Output alias) and Git for Windows cat.exe. I reported it to PowerShell/PowerShell#14360.
If this is indeed the same issue, then the problem will not occur under Windows Powershell (only PowerShell Core). If so, this looks like a PowerShell core problem, not a posh git specific issue. |
@drichardson RE the original problem in this issue - I saw this PR go by on PowerShell 7 - may be related. |
Yes, that fix is for the issue I reported (see PR context). |
The fix may possibly be in the new preview... Downloading now... https://aka.ms/PowerShell-Release?tag=v7.2.0-preview.2 Edit: No, it isn't yet. But getting the latest regardless. |
FYI, fix has finally made it into master. Now just need to wait for a preview to test (I couldn't find any downloadable daily builds to test). |
Fix is in. I verified it fixed my problem. I don't use posh, but perhaps someone here can see if it fixes this issue too. https://github.com/PowerShell/PowerShell/releases/tag/v7.2.0-preview.4 |
My initial tests show no errors, but also a Prompt code is still this:
|
And from
Edit: IT WORKS! I had to play with installing the release version of posh-git, the new PS release, and a minor tweak to my profile, but it works! |
Great! @tvfischer this issue has gone far afield, but it seems like things are working OK? Please reopen if you're still struggling with this. |
I know this is a really old issue, but I just had the problem where suddenly had my prompt for posh-git stop working and rendering things like this: "←[93m[←[39m←[96mmain←[39m←[93m]←[39m" where it should just have had [main]. The problem turned out to be that I had copied info from my .gitconfig at work to my .gitconfig on my home machine and it contained the line: fsmonitor = true This option was apparently not supported by the version of git on my home machine which resulted in posh-git displaying an incorrect prompt. Once I updated my version of git to the latest version, the problem went away. So in short, if your prompt for posh-git stops working correctly, make sure you have not introduced issues in your git configuration. |
System Details
Issue Description
I am experiencing a problem with with the rendering of the prompt. It is constantly displaying what looks like the ansi version of the prompt information. See picture below.
Terminal code page is utf8:
If i try version 0.7.3 it renders a bit better but doesn't quite work and fails with oh-my-posh.
The text was updated successfully, but these errors were encountered: