to get coloured output on a linux terminal, you can do something like
echo -e "\033[31m This is now red"
How can I do this with OCaml? The following doesn't work
print_string "\033[31m blabla"
Thanks in advance,
Markus
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
On Sat, Jan 13, 2007 at 08:29:16PM +0000, Markus Weihs wrote:
> How can I do this with OCaml? The following doesn't work
> print_string "\033[31m blabla"
print_string "\027[31m blabla"
Character codes are in decimal in OCaml, not in octal.
--
Daniel de Rauglaudre
http://pauillac.inria.fr/~ddr/
It's because, for Ocaml, the escape sequence \0xx matches the ASCII
character xx in decimal, not in octal.
print_string "\027[31m blabla" works fine
Thanks in advance,
>
> Markus
>
>
This is my biggest "pet peeve" about OCaml. It uses *decimal* escapes
for characters, not octal like everywhere else in the UNIX and
C-influenced universe.
So you want
print_string "\027[31m blabla"
--
Eric Cooper e c c @ c m u . e d u
Whoa, that was quick! Thanks for all your answers.
> It's because, for Ocaml, the escape sequence \0xx matches the
> ASCII character xx in decimal, not in octal.
>
> print_string "\027[31m blabla" works fine
>
Well, what you said is true, still it's not meant to be explained
like this ! (well I guess and hope so)
The backslash in a character or string sequence introduces a decimal
number between 0 and 255 with *exactly* 3 digits.
You can also write special characters in hexadecimal :
"\xFF" = "\255"
;-)
You can also use ANSITerminal
<http://math.umh.ac.be/an/software.php#x4-90008>.
ChriS
> This is my biggest "pet peeve" about OCaml. It uses *decimal* escapes
> for characters, not octal like everywhere else in the UNIX and
> C-influenced universe.
DNS and BIND use decimal escape sequences, too.
Hexadecimal is also supported ("\x1b[31m blabla") and highly recommended.
> not octal like everywhere else in the UNIX and C-influenced universe.
Well, how many fingers do you have? :-) Octal is a left-over from the
PDP-11 days and should have been abandoned a long time ago.
- Xavier Leroy