You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Windows PSReadline stores and restores multiple bits of console state before/after commands #964
This applies to all extant versions of Powershell.
Steps to reproduce or exception report
There are a number of user preferences that are PSReadline stores and restores across command executions; it is arguable as to whether it is PSReadline's job to do so.
the codepage
this is the cause of font flickering across commands in the windows console (still!)
mitigation: none; i'm curious as to why it changes the codepage to begin with?
the index of the currently-set foreground and background colors
when using a modern terminal (or the terminal options in Windows 19H1), this causes colored lines to streak across the window because the "default colors" are not representable through color indices.
mitigation: CSI 0 m will reset the color to whatever the user requested as defaults
For Chinese-simplified OS, the code page is 936 (Chinese Simplified (GB2312)). The corresponding default font is 新宋体 (Font Family: 54)
For Chinese-traditional OS, the code page is 950 (Chinese Traditional (Big5)). The corresponding default font is 細明體 (Font Family: 54)
For Japanese OS, the code page is 932 (Japanese (Shift-JIS)). The corresponding default font is MS ゴシック (Font Family: 54)
NoteFont Family: 54 is not that special. Consolas and Lucida Sans Typewriter also have Font Family 54, and it could be the same for many other fonts too.
The font flickers because: when setting OutputEncoding to utf8, several more fonts will become available in the console host (Properties -> Font) comparing to when using the default OutputEncoding. For example, on the Chinese-simplified OS, Consolas, Courier New and Lucida Console become available after setting Console.OutputEncoding = Encoding.UTF8.
when the user chooses one of the newly available font, the font will be restored back to the default font when Console.OutputEncoding is restored to the initial default encoding, because the chosen font is unavailable when using the default encoding (default code page).
when the user chooses a font that's available for both the default and utf8 code pages, the font flickering won't happen because the font won't be restored.
I'm not sure how this should be fixed. For a workaround, we can check whether the initial encoding is one of the default CJK encoding's, and if so not change the output encoding.
However, it seems setting code page to utf8 was to fix rendering issues with CJK characters, and not changing the output encoding sounds contradict to that. Jason Shirk (@lzybkr) Could you please explain more about why PSReadLine changes the codepage to begin with?
Dongbo Wang (@daxian-dbw) - I'm not sure there's much more to say about why. I didn't do a lot of investigation - I was just guessing at a possible fix - but the change seemed to help according to some users.
Jason Shirk (@lzybkr) Can you please point me to some of the issues that got fixed or mitigated by changing/restoring the code page? That would be helpful.
I want to update that microsoft/terminal#1145 is not a PSReadLine issue, but a Windows Terminal or .NET Core issue. The cursor shape is reverted when hiding the cursor and then showing it by setting Console.CursorVisible. microsoft/terminal#4124 is logged for that. Related issue in PSReadLine repo is #903
Hi, Mates, I have to say this issue has existed for too looooong time since powershell-7 release, even the latest stable release V-7.1.3, I have to fix it by workaround, really a big surprise!
For anyone still hitting this in 2026 on conhost with PowerShell 5.1 or 7.x,
I patched the PSReadLine 2.4.5 DLL directly to fix this by re-emitting
the ANSI cursor sequence in ReallyRender() after CursorVisible is restored.
Activity
lzybkr commentedon Jul 16, 2019
Setting the codepage was the easy way to fix rendering issues with CJK characters. It seemed to work well.
If there is a more appropriate fix, details would be appreciated.
Try beta4, I think this was fixed.
Should be an easy fix here.
You'll need to provide a repro.
daxian-dbw commentedon Jan 4, 2020
I investigated the
font flickeringissue on CJK locale machines. Here is what I found:CJK locale machines doesn't use the Raster font by default. So the fix in Fix dynamic changing of font in Windows console on CJK codepages #771 doesn't help.
936(Chinese Simplified (GB2312)). The corresponding default font is新宋体(Font Family: 54)950(Chinese Traditional (Big5)). The corresponding default font is細明體(Font Family: 54)932(Japanese (Shift-JIS)). The corresponding default font isMS ゴシック(Font Family: 54)Font Family: 54is not that special.ConsolasandLucida Sans Typewriteralso haveFont Family54, and it could be the same for many other fonts too.The font flickers because: when setting
OutputEncodingtoutf8, several more fonts will become available in the console host (Properties -> Font) comparing to when using the defaultOutputEncoding. For example, on theChinese-simplifiedOS,Consolas,Courier NewandLucida Consolebecome available after settingConsole.OutputEncoding = Encoding.UTF8.Console.OutputEncodingis restored to the initial default encoding, because the chosen font is unavailable when using the default encoding (default code page).utf8code pages, the font flickering won't happen because the font won't be restored.I'm not sure how this should be fixed. For a workaround, we can check whether the initial encoding is one of the default CJK encoding's, and if so not change the output encoding.
However, it seems setting code page to
utf8was to fix rendering issues with CJK characters, and not changing the output encoding sounds contradict to that.Jason Shirk (@lzybkr) Could you please explain more about why PSReadLine changes the codepage to begin with?
lzybkr commentedon Jan 4, 2020
Dongbo Wang (@daxian-dbw) - I'm not sure there's much more to say about why. I didn't do a lot of investigation - I was just guessing at a possible fix - but the change seemed to help according to some users.
daxian-dbw commentedon Jan 5, 2020
Jason Shirk (@lzybkr) Can you please point me to some of the issues that got fixed or mitigated by changing/restoring the code page? That would be helpful.
lzybkr commentedon Jan 6, 2020
There may be other issues, but #289 is one I think.
daxian-dbw commentedon Jan 6, 2020
I want to update that microsoft/terminal#1145 is not a PSReadLine issue, but a Windows Terminal or .NET Core issue. The cursor shape is reverted when hiding the cursor and then showing it by setting
Console.CursorVisible.microsoft/terminal#4124 is logged for that. Related issue in PSReadLine repo is #903
daxian-dbw commentedon Mar 20, 2020
For Windows users with CJK as default display language, there may be a workaround to the font flickering issue: unchecking the
Unicode UTF-8option in the language settings.ToMakeSense commentedon Mar 29, 2021
Hi, Mates, I have to say this issue has existed for too looooong time since powershell-7 release, even the latest stable release
V-7.1.3, I have to fix it by workaround, really a big surprise!mammadkoma commentedon Jan 21, 2022
What should we do for use vertical line always?
daxian-dbw commentedon May 31, 2024
Storing and restoring
OutputEncodingalso causes thechcpcommand to seemingly not work as expected. See the video record in #4027.8192bits commentedon Mar 19, 2026
For anyone still hitting this in 2026 on conhost with PowerShell 5.1 or 7.x,
I patched the PSReadLine 2.4.5 DLL directly to fix this by re-emitting
the ANSI cursor sequence in ReallyRender() after CursorVisible is restored.
PSReadLineOverride
No recompilation needed. Add the registry keys, drop the DLL, set up $PROFILE, done.
Providing persistent cursor shape.
Feedback welcome.