-
Notifications
You must be signed in to change notification settings - Fork 5
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
use ANSI escape codes to control colours of parameters we print #466
Conversation
6d5b9a5
to
2f7848c
Compare
if( ( mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING ) == ENABLE_VIRTUAL_TERMINAL_PROCESSING ) { | ||
_enabled = true; | ||
return true; | ||
} |
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.
This seems to be for "its already enabled"?
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.
yes
[LibraryImport( Kernel32 )] | ||
private static partial IntPtr GetStdHandle( int nStdHandle ); |
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.
You sure we don't need to do SetLastError = true
here?
If we are calling into un-managed code & checking if that was a success (I might be mis-understanding the purpose of that flag).
On .NET, the error information is cleared (set to 0) before invoking the callee when this field is set to true
So maybe that only applies for repeated calls with subsequent successes?
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.
That's only needed if you want detailed error info.
See https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.marshal.getlastpinvokeerror?view=net-8.0.
It doesn't affect a function's return value.
It's sorta like $LASTEXITCODE
vs stdout in PowerShell, where even if it's not set, it doesn't affect stdout of a process.
The base branch was changed.
Why
.NET's
Console.ForegroundColor
only targets stdout.If we rely on
Console.ForegroundColor
and stdout is redirected (e.g.bmx print | iex
), we won't get any colour on stderr either.Related .NET issue: dotnet/runtime#83146
Changing to use ANSI escape codes to control text colours to work around this issue.
Ticket
https://desire2learn.atlassian.net/browse/VUL-423
depends on #464