@MasterCopipaster

Можно ли заставить терминал Windows понимать спец символы терминала?

Здравствуйте, написал небольшое приложение которое в консоли подсвечивает разными цветами текст.
В терминалах Linux/Unix системах все работает хорошо.
Однако при запуске в Windows символы которые отвечают за текст просто выводятся в терминал.
Можно ли как то это исправить? установить дополнительный пакет, или настройки в ярлыке какие подкрутить?

648fa01fae5b7093140166.png

648fa0a4dbe70914205298.png
  • Вопрос задан
  • 72 просмотра
Решения вопроса 1
saboteur_kiev
@saboteur_kiev Куратор тега Windows
software engineer
Терминалы винды и линукса изначально поддерживают разный набор контрольных символов.
https://en.wikipedia.org/wiki/Escape_sequence

Стандартный виндовый терминал так научить нельзя, надо использовать нестандартный
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
firedragon
@firedragon
Не джун-мидл-сеньор, а трус-балбес-бывалый.
Перепишите программу добавив windows спецефичный код
https://www.dotnetperls.com/console-color

или если подходящая версия то так


In Windows 10 build 16257 (released last year) and later, ANSI color and escape sequences for the built-in cmd.exe console (“conhost”) are subject to the following registry key:

[HKEY_CURRENT_USER\Console]
"VirtualTerminalLevel"=dword:00000001
See MSDN blogs for more information. There’s also some official MSDN docs and a bunch of articles on StackOverflow, such as here and here. There’s also some critical information on this subject in this github comment.

This new capability means that the following lines of code in youtube-dl are overly-restrictive:

https://github.com/rg3/youtube-dl/blob/f9f10268c18...

https://github.com/rg3/youtube-dl/blob/f9f10268c18...

https://github.com/rg3/youtube-dl/blob/f9f10268c18...

On Windows 10, the value of compat_os_name is “nt”. Because the lines listed above subsume all three cases where youtube-dl references the --no-color command-line option, the end result is that the --no-color option always asserted on Windows (that is, regardless of not specifying --no-color).

ytdl-no-color

Relaxing the three conjunctions shown above, by removing the and compat_os_name != 'nt' term from each, allows for ANSI color on Windows 10 (assuming the system-wide default is ‘enabled’ as specified by the registry key mentioned above).
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы