# Is there an easy way to color/control console output?

**URL:** <https://www.ruby-forum.com/t/is-there-an-easy-way-to-color-control-console-output/128227>\
**Category:** Ruby\
**Created:** [February 6, 2008, 1:13am UTC](https://www.ruby-forum.com/t/is-there-an-easy-way-to-color-control-console-output/128227 "2008-02-06T01:13:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://www.ruby-forum.com/u/andy)\
**Post date:** [February 6, 2008, 1:13am UTC](https://www.ruby-forum.com/t/is-there-an-easy-way-to-color-control-console-output/128227/1 "2008-02-06T01:13:54Z")

</div>

Hello everyone, is there an easy way for me to color my console  
output? What about updating just a particular x/y coordinate? I  
don’t have time to learn Tk right now for a graphical GUI but just  
being able to control the color and locations of what I print out  
would be so nice. I am on windows right now but I would like the code  
to be cross platform if it as all possible. Anyone here have any  
suggestions for something light weight?

---

<div class="post-metadata">

**Author:** ![andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://www.ruby-forum.com/u/andy)\
**Post date:** [February 6, 2008, 1:56am UTC](https://www.ruby-forum.com/t/is-there-an-easy-way-to-color-control-console-output/128227/2 "2008-02-06T01:56:09Z")

</div>

On Feb 5, 7:13 pm, Andy [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> “I have a great faith in fools; self-confidence my friends call it.” -  
> Edgar Allen Poe

Take a look at ncurses. I’ve never used the ruby extension for it,  
but it’s a fairly easy way to manipulate the console. There is color  
support. Also, Coderay ([http://coderay.rubychan.de/](http://coderay.rubychan.de/)) is a gem that  
colorizes text based on coding language.

---

<div class="post-metadata">

**Author:** ![andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://www.ruby-forum.com/u/andy)\
**Post date:** [February 6, 2008, 7:49pm UTC](https://www.ruby-forum.com/t/is-there-an-easy-way-to-color-control-console-output/128227/3 "2008-02-06T19:49:24Z")

</div>

On Wed, Feb 06, 2008 at 09:54:55AM +0900, Reacher wrote:

> > -Andy  
> > “I have a great faith in fools; self-confidence my friends call it.” -  
> > Edgar Allen Poe
> 
> Take a look at ncurses. I’ve never used the ruby extension for it,  
> but it’s a fairly easy way to manipulate the console. There is color  
> support. Also, Coderay ([http://coderay.rubychan.de/](http://coderay.rubychan.de/)) is a gem that  
> colorizes text based on coding language.

Also look at highline ([http://highline.rubyforge.org/](http://highline.rubyforge.org/)). It has  
themeable colorized output for command line interfaces.

```
http://highline.rubyforge.org/doc/classes/HighLine/ColorScheme.html

```

enjoy,

-jeremy

---

<div class="post-metadata">

**Author:** ![andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://www.ruby-forum.com/u/andy)\
**Post date:** [February 6, 2008, 11:16am UTC](https://www.ruby-forum.com/t/is-there-an-easy-way-to-color-control-console-output/128227/4 "2008-02-06T11:16:37Z")

</div>

See:

[http://benjaminbaka.wordpress.com/2008/02/06/console-output-with-color-using-ruby/](http://benjaminbaka.wordpress.com/2008/02/06/console-output-with-color-using-ruby/)

---

<div class="post-metadata">

**Author:** ![andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://www.ruby-forum.com/u/andy)\
**Post date:** [February 6, 2008, 10:53pm UTC](https://www.ruby-forum.com/t/is-there-an-easy-way-to-color-control-console-output/128227/5 "2008-02-06T22:53:12Z")

</div>

Thank you all very much for your info and links. It’s very much  
appreciated.

–  
-Andy  
“I have a great faith in fools; self-confidence my friends call it.” –  
Edgar Allen Poe

---

<div class="post-metadata">

**Author:** ![andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://www.ruby-forum.com/u/andy)\
**Post date:** [February 6, 2008, 8:17pm UTC](https://www.ruby-forum.com/t/is-there-an-easy-way-to-color-control-console-output/128227/6 "2008-02-06T20:17:16Z")

</div>

On Feb 5, 7:13 pm, Andy [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello everyone, is there an easy way for me to color my console  
> output? What about updating just a particular x/y coordinate? I  
> don’t have time to learn Tk right now for a graphical GUI but just  
> being able to control the color and locations of what I print out  
> would be so nice. I am on windows right now but I would like the code  
> to be cross platform if it as all possible. Anyone here have any  
> suggestions for something light weight?

If all you need is basic ANSI, ie. color:

$ gem install facets  
$ irb

> > require ‘facets/ansicode’  
> > include Console::ANSICode
> > 
> > p red, “Hello”, blue, “World”  
> > “\e[31mHello\e[34mWorld”
> > 
> > p red{ “Hello” } + blue{ “World” }  
> > “\e[31mHello\e[0m\e[34mWorld\e[0m”

We have Florian F. to thank for the original version of this lib.

T.
