Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] color on linux terminal

1,683 views
Skip to first unread message

Markus Weihs

unread,
Jan 13, 2007, 3:39:07 PM1/13/07
to caml...@inria.fr
Hi,

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

Daniel de Rauglaudre

unread,
Jan 13, 2007, 3:56:13 PM1/13/07
to caml...@inria.fr
Hi,

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/

Goulagman

unread,
Jan 13, 2007, 4:00:24 PM1/13/07
to caml...@inria.fr
On 13/01/07, Markus Weihs <mwe...@gmx.at> wrote:
>
> Hi,
>
> 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"


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

Eric Cooper

unread,
Jan 13, 2007, 4:00:35 PM1/13/07
to caml...@yquem.inria.fr, caml...@inria.fr
On Sat, Jan 13, 2007 at 08:29:16PM +0000, Markus Weihs wrote:
> 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"

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

Markus Weihs

unread,
Jan 13, 2007, 4:09:01 PM1/13/07
to caml...@inria.fr
> print_string "\027[31m blabla"

Whoa, that was quick! Thanks for all your answers.

Philippe Wang

unread,
Jan 13, 2007, 4:42:14 PM1/13/07
to Goulagman

On 13 janv. 07, at 21:56, Goulagman wrote:

> 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"

;-)

Christophe TROESTLER

unread,
Jan 13, 2007, 5:49:36 PM1/13/07
to mwe...@gmx.at
On Sat, 13 Jan 2007, Markus Weihs <mwe...@gmx.at> wrote:
>
> to get coloured output on a linux terminal, you can do something like
>
> echo -e "\033[31m This is now red"

You can also use ANSITerminal
<http://math.umh.ac.be/an/software.php#x4-90008>.

ChriS

Florian Weimer

unread,
Jan 16, 2007, 1:30:15 PM1/16/07
to caml...@yquem.inria.fr
* Eric Cooper:

> 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.

Xavier Leroy

unread,
Jan 21, 2007, 12:14:00 PM1/21/07
to Eric Cooper
> This is my biggest "pet peeve" about OCaml. It uses *decimal* escapes
> for characters,

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

0 new messages