ferium
ferium copied to clipboard
Support colouring on Windows conhost
Description
What is the bug? Certain (most) commands cause formatting codes to be printed, instead of interpreted properly, on windows
To Reproduce
What did you do to encounter this bug?
Run ferium list in windows cmd.exe. Note that ferium help works properly, and appears to be the only one to do so.
Software version
- OS: Windows 11
- Ferium Version: 4.1.5
Additional information
Add any other context about the problem here.
SetConsoleMode with ENABLE_VIRTUAL_TERMINAL_PROCESSING in C/C++ WinAPI is usually used to deal with issues like these. I'm not sure what the rust equivalent of this is, but the help command does work properly (I don't really understand rust, so cannot locate the issue and open a pr).
Windows Terminal (rather than cmd.exe) does work properly, likely because the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag is set by default.
help command (correctly displayed):

list command (incorrectly displayed):

list command (correctly displayed, in Windows Terminal):

OK firstly, the help command works because that is auto-generated by the clap argparser. The reason I'm not using the colour library they use is because it's much more complicated than what I'm currently using. I'll have to experiment with more rust terminal colour providers to see what works. In the meantime, you can use Windows Terminal. (which is much better anyways. I'm curious, why would you still want to use conhost apps like cmd and powershell?)
Just more used to it, really No matter what I do, I don't think I can replicate cmd in windows terminal exactly
I don't think I can replicate cmd in windows terminal exactly
Why is that so? Something to do with the shortcuts?
I believe it's something to do with font spacing and stuff It just looks a little off to me, no matter what I try lmao
One reason for using Windows Terminal is that it's completely unavailable pre-Win10.
I'm currently getting the same formatting codes in cmd:

There are alternatives to windows terminal(wezterm alacritty to name a few)! I believe they will all work. Because their linux counterpart all do :tater:
It seems I need to use this winapi function to enable ansi escape codes for conhost.
In python, in order to enable ANSI codes, we call os.system('') because of a bug in cmd.exe (cmd.exe enables VT mode, but doesn't disable it on exit)
Maybe something similar would work in this case?
I read a bit about this workaround and don't really get why it works, but I think it makes use of something in the python interpreter itself, so I cannot take advantage of this in Rust.
Hmm that was stupid of me, turns out there is a function in coloured itself that enables support for conhost.