-
Notifications
You must be signed in to change notification settings - Fork 300
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
Fix dynamic changing of font in Windows console on CJK codepages #771
Fix dynamic changing of font in Windows console on CJK codepages #771
Conversation
If PowerShell is not running in a console, this code probably won't work as expected - for example if we are running under ConPTY, so we should avoid checking the font in that case. I think you can check this easily enough by calling GetFileType on the file handle from STD_INPUT_HANDLE. If the return value is not FILE_TYPE_CHAR, then we can skip calling checking the font. |
2f4e5fa
to
f6906f7
Compare
f6906f7
to
668b01d
Compare
private static bool IsHandleRedirected(bool stdin) | ||
{ | ||
var handle = GetStdHandle((uint)(stdin ? StandardHandleId.Input : StandardHandleId.Output)); | ||
|
||
// If handle is not to a character device, we must be redirected: | ||
int fileType = GetFileType(handle); | ||
if ((fileType & FILE_TYPE_CHAR) != FILE_TYPE_CHAR) |
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.
Per the documentation, GetFileType()
returns a single value and is not flags.
On Windows, the outputencoding is tied to a codepage which is tied to a font. When using a CJK locale, the default is using a raster font that can render the CJK glyphs. Previously, PSReadLine 2.0.0 was manipulating the OutputEncoding to utf8 which resulted in a visible font change in the console and the resulting rendering in the screen buffer was not correct.
The fix is to detect that a raster font is being used and not change the output encoding. Also in cases where the output encoding is already utf8, there's no need to change it.