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

Plain text ANSI - SetConsoleMode fails on older versions of Windows 10 #55

Closed
kwmlodozeniec opened this issue Oct 12, 2020 · 43 comments
Closed
Assignees
Labels
🐛 bug Something isn't working 😵‍💫 help wanted Extra attention is needed windows

Comments

@kwmlodozeniec
Copy link

Prerequisites

  • [*] I have read and understand the CONTRIBUTING guide

  • [*] I looked for duplicate issues before submitting this one

Description

I followed the docs and upgraded oh my posh 2 to V3 on my Win10 machine using Powershell in admin mode. When I run the terminal I get the following exception:

PC=0x50c79a0000

syscall.loadsystemlibrary(0xc000010e00, 0xc000012800, 0xc000012800, 0x20)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/runtime/syscall_windows.go:136 +0xe7
syscall.LoadDLL(0xfe1e92, 0xb, 0xc000024000, 0xc00001a000, 0xc0000758d8)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/dll_windows.go:81 +0x16a
syscall.(*LazyDLL).Load(0xc0000041e0, 0x0, 0x0)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/dll_windows.go:245 +0xc8
syscall.(*LazyProc).Find(0xc000043bf0, 0x0, 0x0)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/dll_windows.go:300 +0xbf
syscall.(*LazyProc).mustFind(...)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/dll_windows.go:318
syscall.(*LazyProc).Addr(...)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/dll_windows.go:327
syscall.GetUserProfileDirectory(0x1f4, 0xc0001241a0, 0xc0000759b8, 0xc0001241a0, 0x509fe3f4a0
)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/zsyscall_windows.go:1910 +0x3e
syscall.Token.GetUserProfileDirectory(0x1f4, 0xc00000ef90, 0x2c, 0x0, 0x0)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/security_windows.go:368 +0x8f
os/user.current(0x0, 0x0, 0x0)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/os/user/lookup_windows.go:217 +0x1c7
os/user.Current.func1()
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/os/user/lookup.go:15 +0x29
sync.(*Once).doSlow(0x10f7de0, 0xfef020)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/sync/once.go:66 +0xf7
sync.(*Once).Do(...)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/sync/once.go:57
os/user.Current(0xc0001029c0, 0xc000102990, 0xc000005a60)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/os/user/lookup.go:15 +0x105
main.(*environment).getCurrentUser(0xc000006050, 0xc000005a00, 0xc0000059e0, 0xc0000059c0)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/environment.go
:99 +0x29
main.(*session).getUserName(0xc0000059a0, 0x0, 0x0)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/segment_sessio
n.go:64 +0x68
main.(*session).getFormattedText(0xc0000059a0, 0x0, 0x0)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/segment_sessio
n.go:40 +0x47
main.(*session).string(0xc0000059a0, 0x1017801, 0xc000006050)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/segment_sessio
n.go:31 +0x32
main.(*Segment).string(...)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/segment.go:72
main.(*engine).renderBlockSegments(0xc000075f40, 0xc0000401e0, 0x0, 0x0)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/engine.go:97 +
0x1c3
main.(*engine).render(0xc000075f40)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/engine.go:126
+0xe5
main.main()
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/main.go:64 +0x
3f5
rax     0x7ffe253672d4
rbx     0xffffffffffbadd11
rcx     0x41
rdi     0x509fd91700
rsi     0x7ffe253672d4
rbp     0x0
rsp     0x509fcbef00
r8      0x0
r9      0x8ac
r10     0x0
r11     0x509fe3f430
r12     0x7ffe29330000
r13     0x7ffe253610e8
r14     0xc000007a
r15     0x7ffe25365c70
rip     0x50c79a0000
rflags  0x10206
cs      0x33
fs      0x53
gs      0x2b```

My PS profile:

$PSDefaultParameterValues["Out-File:Encoding"] = "utf8"
$MaximumHistoryCount = 1000;

Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt -Theme agnoster
Set-Location C:\repos

Environment

  • Oh my Posh version: v3.13.0
  • Theme: agnoster
  • Operating System: Windows 10 build 10240
  • Shell: Powershell
  • Terminal: Allacritty (the same thing happens in standard PS 7 terminal)
  • Go version: go version go1.15.2 windows/amd64 (not sure if this matters)

Steps to Reproduce

  1. Install posh git and oh my posh.
  2. Update config file.
  3. Start terminal.

Expected behavior: [What you expected to happen]
Terminal starts without issues

Actual behavior: [What actually happened]
Oh my pish throws an exception

@JanDeDobbeleer
Copy link
Owner

Ooh. Interesting. Admin is a really challenging part on Windows. It works on my Windows machine, but apparently that's not true for everyone. I'll make a quick fix that ensures this no longer fails, but I'll have to spend some more time on why this fails exactly. Syscalls aren't my forte ^^

@kwmlodozeniec
Copy link
Author

Is this due to me installing it as admin?

@JanDeDobbeleer
Copy link
Owner

It seems that user.Current() fails in that case which is a standard golang call to retrieve the current user information. It also doesn't have an error option so I'll catch it and return an empty string in that case. I'm writing a solution as I type this. Stay tuned.

@kwmlodozeniec
Copy link
Author

Awesome, thank you!
What's interesting though is that in this case I am not running PS as admin explicitly, I only run as admin for installation.

JanDeDobbeleer added a commit that referenced this issue Oct 12, 2020
JanDeDobbeleer added a commit that referenced this issue Oct 12, 2020
JanDeDobbeleer added a commit that referenced this issue Oct 12, 2020
@JanDeDobbeleer
Copy link
Owner

@kwmlodozeniec once 3.14.0 is available, can you validate that fixes the issue?

@kwmlodozeniec
Copy link
Author

kwmlodozeniec commented Oct 12, 2020

C:\repos> Get-InstalledModule -Name oh-my-posh

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
3.14.0-beta          oh-my-posh                          PSGallery            A prompt theme engine for any shell

I still get an exception

Exception 0xc0000005 0x0 0x7ffe29500fff 0x46af8e0000
PC=0x46af8e0000

syscall.loadsystemlibrary(0xc00000d100, 0xc00000e8c0, 0xc00000e8c0, 0x20)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/runtime/syscall_windows.go:136 +0xe7
syscall.LoadDLL(0x13c1ee5, 0xb, 0xc000024000, 0xc00001a000, 0xc0000756a0)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/dll_windows.go:81 +0x16a
syscall.(*LazyDLL).Load(0xc0000041e0, 0x0, 0x0)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/dll_windows.go:245 +0xc8
syscall.(*LazyProc).Find(0xc000043bf0, 0x0, 0x0)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/dll_windows.go:300 +0xbf
syscall.(*LazyProc).mustFind(...)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/dll_windows.go:318
syscall.(*LazyProc).Addr(...)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/dll_windows.go:327
syscall.GetUserProfileDirectory(0x1ec, 0xc0000a4680, 0xc000075780, 0xc0000a4680, 0x46af7b9460)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/zsyscall_windows.go:1910 +0x3e
syscall.Token.GetUserProfileDirectory(0x1ec, 0xc00000b290, 0x2c, 0x0, 0x0)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/syscall/security_windows.go:368 +0x8f
os/user.current(0x0, 0x0, 0x0)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/os/user/lookup_windows.go:217 +0x1c7
os/user.Current.func1()
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/os/user/lookup.go:15 +0x29
sync.(*Once).doSlow(0x14d7de0, 0x13cf080)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/sync/once.go:66 +0xf7
sync.(*Once).Do(...)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/sync/once.go:57
os/user.Current(0xc000075a08, 0x1307e52, 0x30000)
        C:/hostedtoolcache/windows/go/1.15.2/x64/src/os/user/lookup.go:15 +0x105
main.(*environment).homeDir(0xc000004760, 0x0, 0xc000075b80)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/environment.go:68 +0x2d
main.(*path).inHomeDir(...)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/segment_path.go:89
main.(*path).rootLocation(0xc000005d80, 0xc00000ccc0, 0x10, 0xc000005d80, 0xc000005d60)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/segment_path.go:97 +0x85
main.(*path).getAgnosterPath(0xc000005d80, 0x0, 0x0)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/segment_path.go:77 +0xac
main.(*path).string(0xc000005d80, 0x13f7901, 0xc000004760)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/segment_path.go:41 +0x212
main.(*Segment).string(...)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/segment.go:72
main.(*engine).renderBlockSegments(0xc000075f40, 0xc0000401e0, 0x0, 0x0)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/engine.go:97 +0x1c3
main.(*engine).render(0xc000075f40)
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/engine.go:126 +0xf6
main.main()
        D:/a/oh-my-posh3/oh-my-posh3/src/github.com/JanDeDobbeleer/oh-my-posh3/main.go:64 +0x3f5
rax     0x7ffe253672d4
rbx     0xffffffffffbadd11
rcx     0x41
rdi     0x46af712d00
rsi     0x7ffe253672d4
rbp     0x0
rsp     0x46af53f4d0
r8      0x0
r9      0x8ac
r10     0x0
r11     0x46af7b93f0
r12     0x7ffe29330000
r13     0x7ffe253610e8
r14     0xc000007a
r15     0x7ffe25365c70
rip     0x46af8e0000
rflags  0x10206
cs      0x33
fs      0x53
gs      0x2b

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Oct 12, 2020

Well now. This is going the wrong way all over the place. It's actually a bug in go, as this implies it crashes underneath. We're one step further but not yet where we need to be. It seems usr, err := user.Current() is also used for the home directory. Given that go crashes rather than return a value in the err variable, I'll need to replace that as well.

JanDeDobbeleer added a commit that referenced this issue Oct 12, 2020
JanDeDobbeleer added a commit that referenced this issue Oct 12, 2020
@JanDeDobbeleer
Copy link
Owner

@kwmlodozeniec stay tuned for 3.14.1

@kwmlodozeniec
Copy link
Author

BTW, I wasn't sure if you are still in WIP but I tried latest and I get this:

 Set-PoshPrompt -Theme agnoster
The parameter is incorrect.

@JanDeDobbeleer
Copy link
Owner

That's all due to being installed as admin probably causing the paths and other items to act weird. We're almost there I guess, this is related to the PowerShell module rather than the go binary so I can troubleshoot this on a Windows machine.

@JanDeDobbeleer
Copy link
Owner

I'm going to try to fix this this evening (or at least reproduce).

@JanDeDobbeleer
Copy link
Owner

@kwmlodozeniec I can't reproduce this. Can you give me the exact installation procedure you followed?
image

@kwmlodozeniec
Copy link
Author

I'm wondering if it might be connected to my fairly old build of Windows 10. It's a work machine and the IT department is very conservative about updates, hence me trying to use alacritty instead on the new windows terminal. I will try the same process on my up to date machine and see if that works fine, if that's the case I am not sure if you want to bother fixing this? It might be worth setting a minimum supported / tested version of Windows 10 in the docs.

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Oct 13, 2020

The error we now see if related to the Module code (PowerShell) so I'm still curious what's triggering this. Pretty sure I'm using something that's not available somewhere.

Which version of PowerShell are you on?

@kwmlodozeniec
Copy link
Author

I've installed the latest version 7 about a week go.

@JanDeDobbeleer
Copy link
Owner

I'm going about this the wrong way. Can you open the module code and comment this line?

@kwmlodozeniec
Copy link
Author

Will do first thing tomorrow.

@kwmlodozeniec
Copy link
Author

kwmlodozeniec commented Oct 14, 2020

image

Get-
InstalledModule -Name oh-my-posh

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
3.14.3-beta          oh-my-posh                          PSGallery            A prompt them…

Same thing seems to be happening with 3.14.4 (I know it has got the fix for this issue but I tried for the sake of completeness).

Also, my version output:

C:\repos> $PSVersionTable

Name                           Value                        PSGallery            A prompt the
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.10240
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

@JanDeDobbeleer
Copy link
Owner

I know what's happening. On Windows we need to set the output mode to interpret ANSI. That's what's failing here. I have one thing I can try, but no guarantee.

@JanDeDobbeleer
Copy link
Owner

Ok, I made a fix in the dependency which hopefully provides more result. Can you try the attached binary?

posh.zip

@kwmlodozeniec
Copy link
Author

kwmlodozeniec commented Oct 14, 2020

image
Looks like the same result. I have tried it with and without the line you have asked me to comment out earlier.

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Oct 14, 2020

Ok. So. What happens is this. To render ANSI on Windows the executing binary needs to tell the handler it wants to enable this. But, somehow, that functionality isn't available on your machine or the wrong handler is being used (my initial bet). Given that this is a really low level API my knowledge of the domain is limited. I'll do some more research 👍🏻

To be clear, calling the binary directly results in the same output, right?

@kwmlodozeniec
Copy link
Author

When calling it from PS7 standard terminal I get this:

.\posh-windows-amd64.exe
64 The parameter is incorrect.
�[38;2;255;255;255;49m�[7m�[m�[0m�[48;2;255;255;255m�[38;2;16;14;35m �[0m�[48;2;255;255;255m�[38;2;16;14;35mmlodozk�[0m�[48;2;255;255;255m�[38;2;16;14;35m@�[0m�[48;2;255;255;255m�[38;2;16;14;35mPORTISHEAD�[0m�[48;2;255;255;255m�[38;2;16;14;35m �[0m�[48;2;145;221;255m�[38;2;255;255;255m�[0m�[48;2;145;221;255m�[38;2;16;14;35m ~\..\..\..\..\..\bin �[0m�[38;2;145;221;255m�[0m

When using alacritty

.\posh-windows-amd64.exe

?[38;2;255;255;255;49m?[7m?[m?[0m?[48;2;255;255;255m?[38;2;16;14;35m ?[0m?[48;2;255;255;255m
?[38;2;16;14;35mmlodozk?[0m?[48;2;255;255;255m?[38;2;16;14;35m@?[0m?[48;2;255;255;255m?[38;2;
16;14;35mPORTISHEAD?[0m?[48;2;255;255;255m?[38;2;16;14;35m ?[0m?[48;2;145;221;255m?[38;2;255;
255;255m?[0m?[48;2;145;221;255m?[38;2;16;14;35m ~\..\..\..\..\..\bin ?[0m?[38;2;145;221;255m
?[0m

The PS7 standard terminal output is most likely due to the fact I cannot set a proper PL font on that terminal exe.

@JanDeDobbeleer
Copy link
Owner

It could be related to this alacritty/alacritty#3063

I'm going to to try alacritty myself later today.

@JanDeDobbeleer
Copy link
Owner

@kwmlodozeniec the error you see in the standard terminal is coming from here. It can't set the mode which is most likely due to your specific version of Windows. Alacritty doesn't seem to show that error, implying it can set the mode, but then doesn't interpret the ANSI characters. That's most likely an Alacritty issue.

@kwmlodozeniec
Copy link
Author

That's a shame. I use powerline on my home machine, where I am on the latest Win10. I guess I will have to badger IT to update my work machine to something more recent. Thanks for investigating, let me know if you find some workaround.

@JanDeDobbeleer
Copy link
Owner

TL;DR: I use a package to facilitate ANSI coloring. A while back I noticed it wouldn't render in the current consoles on Windows as it set virtual terminal processing wrong for those. HOWEVER, it might just as well be that fix breaks on other places and would also explain as to why some of the other calls were failing earlier.

@JanDeDobbeleer
Copy link
Owner

@kwmlodozeniec did you try the proposed fix in the issue above? I can't seem to run alacritty (oh noes). Unless I really need that c++ distributable.
afbeelding

@kwmlodozeniec
Copy link
Author

kwmlodozeniec commented Oct 14, 2020

Yes, I already had that setting enabled, it made no difference to me.

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Oct 14, 2020

I might have a final thing I can try. Been reading too many docs about how to get the handle for the currently active console so stay tuned for a new version tomorrow 😉

@JanDeDobbeleer JanDeDobbeleer added windows 🐛 bug Something isn't working labels Oct 14, 2020
@JanDeDobbeleer JanDeDobbeleer self-assigned this Oct 14, 2020
@JanDeDobbeleer
Copy link
Owner

@kwmlodozeniec I made a minor change locally to see if that could fix the issue. If this doesn't work I'm out of options for now.
posh2.zip

@JanDeDobbeleer JanDeDobbeleer changed the title Exception when running on Win10 Plain text ANSI - SetConsoleMode fails on older versions of Windows 10 Oct 15, 2020
@kwmlodozeniec
Copy link
Author

So, updated the executable, turned on posh in my profile.
On PS7 terminal I get this when starting:

92 The handle is invalid.

If I then navigate to the module dir and run the exe directly I get this:

64 The parameter is incorrect.
�[38;2;255;255;255;49m�[7m�[m�[0m�[48;2;255;255;255m�[38;2;16;14;35m �[0m�[48;2;255;255;255m�[38;2;16;14;35mmlodozk�[0m�[48;2;255;255;255m�[38;2;16;14;35m@�[0m�[48;2;255;255;255m�[38;2;16;14;35mPORTISHEAD�[0m�[48;2;255;255;255m�[38;2;16;14;35m �[0m�[48;2;145;221;255m�[38;2;255;255;255m�[0m�[48;2;145;221;255m�[38;2;16;14;35m ~\..\..\..\..\..\bin �[0m�[38;2;145;221;255m�[0m�[0m

On alacritty is get the same garbage I did before.

@JanDeDobbeleer
Copy link
Owner

it just can't find the right stdout. I have no idea how to proceed with this one now.

@JanDeDobbeleer JanDeDobbeleer added the 😵‍💫 help wanted Extra attention is needed label Oct 15, 2020
@kwmlodozeniec
Copy link
Author

To be fair this is a very specific setup with out of date windows etc. Maybe you should not waste your time on this. This works fine on my home machine with up to date windows without issues.

@JanDeDobbeleer
Copy link
Owner

Let's just say I'm intrigued as to why this doesn't work.

@JanDeDobbeleer
Copy link
Owner

@kwmlodozeniec I changed the way to executable is invoked in the prompt function. I'm curious if that would have a positive impact here as well. Can you try 3.23.0?

@kwmlodozeniec
Copy link
Author

Without enabled a theme, just import the module I get this
image

If I enable a theme, for example Set-PoshPrompt -Theme paradox I get this:
image

So no error but it also stop posh-git from loading and prompt is just PS>

@JanDeDobbeleer
Copy link
Owner

What does the $error variable hold?

@kwmlodozeniec
Copy link
Author

PS>Get-Variable error

Name                           Value
----                           -----
Error                          {}

@JanDeDobbeleer
Copy link
Owner

Super useful. Thanks Powershell 🤦🏻‍♂️

@levirs565
Copy link

This may be issue from ConHost. Alacritty use ConPty from Conhost. WezTerm and Windows Terminal is using ConPty from OpenConsol. I guess this issue is not happenned in WezTerm and Windows Terminal. You can see this issue on Alacritty alacritty/alacritty#4794 .

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Nov 28, 2021

Alacritty issue, closing this due to ago. See alacritty/alacritty#4794 for context.

Copy link

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues.
If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐛 bug Something isn't working 😵‍💫 help wanted Extra attention is needed windows
Projects
None yet
Development

No branches or pull requests

3 participants