2

Is it possible to colour the console output with OCaml on Windows ?

It seems to be possible on a linux terminal : print_string "\027[31m blabla" but I cannot find any information regarding the Windows console.

RUser4512
  • 1,050
  • 9
  • 23

3 Answers3

2

Using ther Vanilla windows tooling..

Color management is not possible by default using the command ( ms dos ) console emulation.

Out of the box, the best you can get is by using the PowerShell command line interface instead and to configure the colors like explained in this page.

In an opened terminal:

write-host -foregroundcolor Red "Hello"

will result in Hello printed in Red ...

But this is not convenient at all..

A better solution provided by an external tool

The easiest way is to uses an external tool to do the job, but you'll need to install a kind of windows command line extension. A nice project can be found HERE it's called ANSICON and will directly interpret the ANSI codes the same way the Linux modern terminal emulators does.

Ludovic Frérot
  • 605
  • 4
  • 9
  • Great, thank you! however, I could change the colors from a C# application with the default command so it seems able to support different colors... Or am I missing something ? – RUser4512 Mar 18 '16 at 10:11
1

You may be interested in ANSITerminal . I do not remember how good the Windows version is — I personally do not use that platform — but do not hesitate to fill issues or submit pull requests.

ChriS
  • 606
  • 3
  • 6
0

If you are looking for ANSI color support (and more) in cmd.exe you can use clink.

Daniel Bünzli
  • 5,119
  • 20
  • 21