Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix dynamic changing of font in Windows console on CJK codepages #771
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.
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.