1

Clink's default text output is in white. E.g. after injecting Clink, typing clinkTabTab shows:

enter image description here

If I set the cmd window to black text on white background ("Properties" → "Colors"), this is the output:

enter image description here

The second row cannot be seen, because it is white text on white background. Clink's text output remains white, ignoring the color settings for the cmd window.

How can we set Clink's output color?

Is there something alike set clink.prompt_colour=12 for output color?

Pacerier
  • 26,733
  • 82
  • 197
  • 273

1 Answers1

3

It's not possible without 3rd-party apps.

clink doesn't insert colors into the output, it only allows the command shell to interpret them. You need to use a program which displays color output. These are mostly Linux applications because cmd.exe doesn't usually show them anyway. For example, if you install the GnuWin32 version of ls you can see color in a console which has already been injected.

First inject clink. There are several ways to do this. The other methods are listed on the clink information page:

clink.exe inject

Then you can use the command:

ls --color

To view directory listings in color.

If you also install the printf command then you can color the output of your own scripts. For example:

printf "\033[0;31mhello\33[0m, \33[0;32mworld\33[0m"

Will print 'hello' in red and 'world' in green. You could also use the GNU echo command, with the -e option, but because that is already a Windows command you'll need to use the full path to the exe every time you use it.

There are surely other programs which can do this but this is how I use it. I've written a full guide to setting this up the way I use it that you may be interested in.

Pacerier
  • 26,733
  • 82
  • 197
  • 273
krowe
  • 5,493
  • 1
  • 24
  • 31
  • 1
    However Clink is able to set the prompt color fine: `set clink.prompt_colour=12`. Is there no equivalent option to set the text color? – Pacerier Aug 23 '15 at 23:10
  • 1
    Programs need to output special character sequences in order to tell the console which colors to output. Because Windows console applications do not output these characters, very few apps for Windows will be colored (unless it was specifically made to work with clink). clink can modify the command prompt because it is adding those characters to the prompt. Some Windows programs will show color though. For example, TYPE will output color too if the file it is showing has the required characters in it. – krowe Aug 23 '15 at 23:21
  • Clink states that it hooks into `ReadConsole()` so wouldn't it be able to assign colors to the output too? Another oddity is, if it doesn't, why is the color white color instead of the color cmd uses (which is set to black using "properties >> colors" on the cmd window). – Pacerier Aug 23 '15 at 23:57
  • I've already explained that it DOES do that. The problem is that 99% of Windows apps don't output the color escape codes. Try this, create a new text file in Notepad++ and select `Edit -> Character Panel`. Then take the string I've given above `/033[0;31m....` and paste it into the file. Then replace each `/033` with the `ESC` character (27 Decimal). Then save it. Now you can type `TYPE myfile.txt` and you'll see that it too is colored. Unfortunately, TYPE is one of the few Windows apps that you'll be able to get to output these characters though. – krowe Aug 24 '15 at 01:15
  • It just occurred to me that you also need a console capable of interpreting these color codes. There are several ways to do this. I use ConEmu but if you want the default console to do this you'll want a ANSI.SYS replacement like ANSICON: http://adoxa.altervista.org/ansicon . The downside of this is that it'll permanantly (AFAIK) add color support to your console (because it replaces your current DLL). If you want to use this then just download it and run `ansicon.exe -i`. From then on your console will have color support. – krowe Aug 24 '15 at 01:57
  • This is what I see with `type myfile.txt`: http://i.stack.imgur.com/7yC7M.png . To recap, are you saying that default cmd doesn't have color support so Clink wouldn't be able to do colors too? But why does it seem like Clink is setting text to white color, even after I've changed cmd settings for text color to black? – Pacerier Aug 24 '15 at 05:46
  • The color support offered by the default cmd.exe console is very bad. clink supports both but if you use the default then clink is very limited on what it can do about this situation. If you use anything with standard ANSI support then it is fine (once setup). You can either use ANSICON or something like ConEmu to get that support. – krowe Aug 24 '15 at 06:22
  • Btw I see that you are calling `Clink` as `CLink`. Why do you call it as `CLink`? Back to topic: Why is Clink able to set the prompt color for default cmd but not the output color? Is it due to a bug or is it due to an inherent Windows limitation? – Pacerier Aug 24 '15 at 09:43
  • I'm just calling it that way so that you can see exactly what I'm doing. Normally, I use ConEmu to inject it but I will sometimes just run the `*.bat` file. It is neither a bug or a limitation of clink. Clink doesn't app output as part of it's job and there are already other tools that do it. I 'believe' that in the past it did include part of the modified ANSI sys but they have removed that because it was already handled by apps like ansicon.exe. – krowe Aug 24 '15 at 22:25
  • 1
    Am I right to say that you're saying that "it's not possible without 3rd party apps"? – Pacerier Aug 25 '15 at 08:08