-
-
Notifications
You must be signed in to change notification settings - Fork 511
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
cmd/age: fix terminal escape sequences on Windows #475
base: main
Are you sure you want to change the base?
Conversation
If possible, we enable virtual terminal processing, which is necessary for using terminal escape sequences on instances of the Windows Console. When enabling virtual terminal processing fails, we completely avoid using escape sequences to prevent weird characters to be printed to the console. Fixes FiloSottile#474
|
||
mode |= ENABLE_PROCESSED_OUTPUT | ||
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | ||
ret, _, _ := setConsoleMode.Call(uintptr(syscall.Stdout), uintptr(mode)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this and sorry about the review lag!
I made a couple small style changes, but then realized this shouldn't be unconditionally be stdout, as we might have opened CONOUT$
as a terminal instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time to review!
Shouldn't this work anyway by using syscall.Stdout
? Go initializes syscall.Stdout
with GetStdHandle(STD_OUTPUT_HANDLE)
(see here), and STD_OUTPUT_HANDLE
defaults to CONOUT$
, as described in the Windows Console docs.
Maybe I'm confusing or missing something. If so, could you please elaborate on the situation?
With this PR, if possible, we enable virtual terminal processing, which is necessary for using terminal escape sequences on instances of the Windows Console. When enabling virtual terminal processing fails, we completely avoid using escape sequences to prevent weird characters to be printed to the console.
Please see comments on code for more info.
Fixes #474
P.S.: I'm happy to explain eventually obscure choices I made.