terminal color output

Discussion of Common Lisp

terminal color output

Postby Jose Brava » Mon Jul 13, 2009 2:49 pm

Hi,

is there a simple way of getting a colored output with sbcl? I need the same output as from the
Code: Select all
echo -e "\033[34mBlah"
bash command. Any ideas ;)?

Thanks
--
JB
--
JB
Jose Brava
 
Posts: 2
Joined: Mon Jul 13, 2009 2:39 pm

Re: terminal color output

Postby nuntius » Tue Jul 14, 2009 6:34 pm

I'm not sure why #\Esc or the like don't work, but the following does.
(format t "~C[34mBlah" (code-char 27))
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: terminal color output

Postby gugamilare » Tue Jul 14, 2009 8:15 pm

nuntius wrote:I'm not sure why #\Esc or the like don't work, but the following does.
(format t "~C[34mBlah" (code-char 27))


You mean like this:

Code: Select all
(format t "~C[34mBlah" #\Esc)


? This works fine here.
gugamilare
 
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil

Re: terminal color output

Postby nuntius » Tue Jul 14, 2009 8:57 pm

What I couldn't get was something like "#\Esc[34mBlah". The code-char was simply cruft from experimentation.
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: terminal color output

Postby Ramarren » Tue Jul 14, 2009 11:35 pm

nuntius wrote:What I couldn't get was something like "#\Esc[34mBlah". The code-char was simply cruft from experimentation.


You want cl-interpol for that sort of thing.
Ramarren
 
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland

Re: terminal color output

Postby Jose Brava » Wed Jul 15, 2009 1:37 am

Thank you all for your answers, it works!
--
JB
Jose Brava
 
Posts: 2
Joined: Mon Jul 13, 2009 2:39 pm

Re: terminal color output

Postby gugamilare » Wed Jul 15, 2009 4:18 am

nuntius wrote:What I couldn't get was something like "#\Esc[34mBlah". The code-char was simply cruft from experimentation.


Well, that wouldn't work. the '#\' is a reader macro as much as, for instance, '#()', and you can't place a vector inside a string as well.

Just note that (code-char 27) will not necessarily return #\Esc according to the ANSI spec. All implementation that I know of use either ASCII or Unicode, which means that it will work in all of them, but this is not required - as much as the ANSI spec concerns, you can create an implementation which uses characters with your own encoding.
gugamilare
 
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil

Re: terminal color output

Postby nuntius » Wed Jul 15, 2009 6:54 pm

gugamilare wrote:Just note that (code-char 27) will not necessarily return #\Esc according to the ANSI spec. All implementation that I know of use either ASCII or Unicode, which means that it will work in all of them, but this is not required - as much as the ANSI spec concerns, you can create an implementation which uses characters with your own encoding.


Please... If (char-code #\Esc) is not 27, there's little chance of the terminal understanding either... A real programmer would write a raw byte array anyway. ;)
User avatar
nuntius
 
Posts: 498
Joined: Sat Aug 09, 2008 10:44 am
Location: Burlington, MA

Re: terminal color output

Postby gugamilare » Wed Jul 15, 2009 9:34 pm

nuntius wrote:Please... If (char-code #\Esc) is not 27, there's little chance of the terminal understanding either... A real programmer would write a raw byte array anyway. ;)

Theoretically, an implementation can create some kind of internal codification and use ASCII or Unicode to communicate with the terminal (the same way that an implementation uses Unicode internally and is able to write ISO-8859-1 files). But, you are right, it would be a waste of time to create such an implementation :)
gugamilare
 
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil

Re: terminal color output

Postby Paul » Wed Jul 15, 2009 9:57 pm

Jose Brava wrote:Hi,

is there a simple way of getting a colored output with sbcl? I need the same output as from the
Code: Select all
echo -e "\033[34mBlah"
bash command. Any ideas ;)?

Thanks
--
JB


http://users.actrix.co.nz/mycroft/terminfo.lisp

(ti:set-terminal)
(ti:tputs ti:set-a-foreground 4)
Paul
 
Posts: 106
Joined: Tue Jun 02, 2009 6:00 am

Next

Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 1 guest

cron