Not getting expected colors with ansi_format/3 on Windows

With SWI-Prolog (threaded, 64 bits, version 8.2.3) in the terminal on Microsoft Windows [Version 10.0.17134.1902] this:

?-ansi_format([fg(1,249, 1)],'~w',['green text']), nl, ansi_format([fg(200,1, 1)],'~w',['red text']).

just results in green text and red text both printed in blue. Other examples also generate unexpected output. This works on MacOS though.

Any suggestions?

Kind regards, JCR

The swipl-win.exe console doesn’t support 24-bit direct color. Seems it neither supports the 8-bit color model, so you only have the classical 16 ANSI colors.

To get more, some hacking is required in src/win32/console/console.c :slight_smile:

1 Like

Thanks Jan!

This works as expected:
?- ansi_format([fg(yellow)], '~w', ['bananas']), nl, ansi_format([fg(blue)], '~w', ['blue berries']).

Looking at the code in i see that the color options in this case seem to be black, red, green, yellow, blue, magenta, cyan and white. Or are there additional colors?


Nope. These are the good old 16 color ansi palette (8 colors in normal and high intensity mode). Since then there is the 256 model and the direct color model, but neither is implemented in the swipl-win.exe console. It shouldn’t be rocket science to do so …

1 Like