Почему PowerShell уродует консоль FAR?

Столкнулись с проблемой в использовании Far? Здесь можно получить помощь.
Post Reply
nyq
Posts: 6
Joined: Tue 22 Oct, 2013 04:16
Has thanked: 1 time

Почему PowerShell уродует консоль FAR?

Post by nyq »

FAR 3.0.5800 x64, Win10. Запускаем из командной строки PowerShell в интерактивном режиме или же просто на выполнение отдельной команды.

Проблема: Если окно FAR-а было до запуска powerShell максимизировано, то весь вывод PowerShell осуществляется только в верхней половине консоли.
test1.png
Если же оно не было максимизировано, то размер окна меняется на некоторый другой, при этом в консоли остаётся мусор от панелей FAR-а.
test2.png
test2.png (11.02 KiB) Viewed 1593 times
После окончания работы PowerShell и возврате в консоль FAR-а сам FAR оказывается изуродованным, панели отображаются в совершенно нечитаемом виде.
test3.png
Ничем, кроме перезапуска FAR-а это исправить не получается. При этом если запускать PowerShell из стандартной консоли Windows, он работает нормально и консоль не портит. Что я делаю не так?
Yegor
Posts: 1328
Joined: Mon 04 Apr, 2005 13:41
Location: San Ramon, CA / Kharkov, UA
Has thanked: 32 times
Been thanked: 61 times

Почему PowerShell уродует консоль FAR?

Post by Yegor »

Far 3.0.5852.0 x86 / Windows 10.0.19043.1110 x64 - не могу повторить. У меня все ок.
Мы не можем ждать милостей от Фара, взять их у него — наша задача! (C) Мичурин
nyq
Posts: 6
Joined: Tue 22 Oct, 2013 04:16
Has thanked: 1 time

Почему PowerShell уродует консоль FAR?

Post by nyq »

Нашёл настройку, при включении которой появляется этот дефект. Control Panel->Region->Administrative->Change system locale->Use Unicode UTF-8 for worldwide language support. Если она включена, то начинается уродование консоли FAR-а при запуске PowerShell, если она отключена, то ничего не уродуется (но при этом пропадает полноценная поддержка Уникода, так что отключение этой опции для меня решением не является).
nyq
Posts: 6
Joined: Tue 22 Oct, 2013 04:16
Has thanked: 1 time

Почему PowerShell уродует консоль FAR?

Post by nyq »

Также эффект воспроизводится, если перед запуском PowerShell в консоли выполнить команду chcp 65001
Одним словом, как только мы тем или иным способом переводим консоль на уникодовую кодовую страницу, начинается уродование FAR-а при запуске PowerShell.
Интересно, кто-нибудь это победил?
Yegor
Posts: 1328
Joined: Mon 04 Apr, 2005 13:41
Location: San Ramon, CA / Kharkov, UA
Has thanked: 32 times
Been thanked: 61 times

Почему PowerShell уродует консоль FAR?

Post by Yegor »

Под UTF-8, у меня Windows PowerShell ломает и обычную консоль (cmd), даже шрифт на растровый меняет почему-то (по умолчанию у меня Consolas). А вот с PowerShell 7.1.3 все ок.
Last edited by Yegor on Sat 24 Jul, 2021 02:17, edited 1 time in total.
Мы не можем ждать милостей от Фара, взять их у него — наша задача! (C) Мичурин
User avatar
DrKnS
Posts: 6114
Joined: Thu 04 Aug, 2005 06:44
Location: Kyiv
Has thanked: 12 times
Been thanked: 426 times

Почему PowerShell уродует консоль FAR?

Post by DrKnS »

A long time ago in a galaxy far, far away, somewhere between the years 2006 and 2009, Microsoft decided to move the console subsystem from kernel space to user space.
In layman's terms, since Windows 7 the window that cmd.exe, far and other apps use belongs to conhost.exe instead of csrss.exe.

Obviously, because of this transition the console code started using slightly different APIs to talk to the outside world, e.g. to display the text.
And to display the text they chose a GDI function that for unidentified historical reasons doesn't use Uniscribe.
In layman's terms, it doesn't use the font fallback feature: when the chosen font doesn't have a certain glyph, it doesn't try to substitute one from a different font and just displays � instead.

Unfortunately, no one tested it properly with various national characters back then and the bug made it to Windows 7 and all the subsequent Windows versions.

Of course, this couldn't go unnoticed forever: one day some Asian user of powershell spotted that some character is not rendered properly with the Consolas font and filed a bug.

Unfortunately, back in the day Microsoft was focused on different ideas and the console subsystem was considered legacy.
Or maybe people who knew how GDI works already left and the "Console's current text rendering engine does not support font-fallback" urban legend was born.
Or something else, who knows.
Anyways, instead of finding the root cause and fixing it properly the powershell devs came up with a workaround, which is... I don't know how to stay technically correct and polite simultaneously. Oh, whatever, which is insane:
https://github.com/microsoft/terminal/issues/280#issuecomment-517870239 wrote:whenever Windows PowerShell identifies a code page that isn't supported by Consolas, it will change the font to Terminal
Why "insane"? Because Terminal, as a raster font, only supports one (!) codepage by definition and while that workaround maybe fixed a particular glyph for a particular Asian customer, it also killed the Unicode support for the rest of the world. Not to mention that console apps should respect user's preferences and not fiddle with the console host in the first place.

In other words, powershell tries to be smarter than it is and fails spectacularly.

File a bug report to them. That workaround breaks more than it fixes. It shouldn't have been there in the first place and it's no longer necessary even for that particular Asian customer, because now the font fallback works as intended in conhost (you're welcome).
Post Reply

Return to “Нужна помощь”