ferium icon indicating copy to clipboard operation
ferium copied to clipboard

Support colouring on Windows conhost

Open supsm opened this issue 3 years ago • 6 comments

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): image

list command (incorrectly displayed): image

list command (correctly displayed, in Windows Terminal): image

supsm avatar Jun 22 '22 00:06 supsm

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?)

theRookieCoder avatar Jun 22 '22 13:06 theRookieCoder

Just more used to it, really No matter what I do, I don't think I can replicate cmd in windows terminal exactly

supsm avatar Jul 11 '22 04:07 supsm

I don't think I can replicate cmd in windows terminal exactly

Why is that so? Something to do with the shortcuts?

theRookieCoder avatar Jul 11 '22 13:07 theRookieCoder

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

supsm avatar Jul 11 '22 19:07 supsm

One reason for using Windows Terminal is that it's completely unavailable pre-Win10.

I'm currently getting the same formatting codes in cmd: image image

Nekkowe avatar Jul 18 '22 10:07 Nekkowe

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:

JustSimplyKyle avatar Jul 23 '22 03:07 JustSimplyKyle

It seems I need to use this winapi function to enable ansi escape codes for conhost.

theRookieCoder avatar Nov 12 '22 12:11 theRookieCoder

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?

CatGamer23 avatar Dec 03 '22 15:12 CatGamer23

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.

theRookieCoder avatar Dec 03 '22 15:12 theRookieCoder

Hmm that was stupid of me, turns out there is a function in coloured itself that enables support for conhost.

theRookieCoder avatar Feb 06 '24 14:02 theRookieCoder