From: Josh Cheek Date: 2011-08-05T04:12:49+09:00 Subject: Re: Colores en la terminal --bcaec5171eadf4056b04a9b2c12b Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Thu, Aug 4, 2011 at 7:20 AM, Y=E1bir G. wrote: > Hi everyone! > > I'm doing a terminal program and need to know if you can put text color. > > thanks > > -- > Posted via http://www.ruby-forum.com/. > > You can, but I haven't found any way to do it reliably across both Windows and Unix. If you are in Unix, go to the terminal and run: $ ruby -e 'puts "\e[01mBLACK \e[32mRED \e[33mYELLOW \e[34mBLUE \e[35mMAGENT= A \e[36mCYAN \e[37mWHITE \e[0mNONE"' The dollar sign indicates my promt. The \e is the escape key (top left on your keyboard, ansi character 27), then a left bracket. This \e[ is called an escape sequence, and you can put codes after it that have special meanings. 3#m means change the foreground, 4#m means change the background (ie run the same code above but change the 3s to 4s. For more about escape sequences, check out http://en.wikipedia.org/wiki/ANSI_escape_code There are also a ton of gems that do this (you might make one yourself, it'= s a fun short exercise, and will help you become familiar with how escape sequences work). --bcaec5171eadf4056b04a9b2c12b--