# How to coloring Windows command prompt in irb?

**URL:** <https://www.ruby-forum.com/t/how-to-coloring-windows-command-prompt-in-irb/87736>\
**Category:** Ruby\
**Created:** [March 5, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/how-to-coloring-windows-command-prompt-in-irb/87736 "2007-03-05T17:44:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinwoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@shinwoo](https://www.ruby-forum.com/u/shinwoo)\
**Post date:** [March 5, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/how-to-coloring-windows-command-prompt-in-irb/87736/1 "2007-03-05T17:44:10Z")

</div>

Is there any gem or ruby script to make irb command prompt in windows  
color? I found a gem ‘wirble’ which is very nice but it only works in  
Linux or Mac. It can’t work in cygwin or windows command prompt. I  
searching for hours on any windows command prompt which can show color  
but couldn’t make it, I only found some interactive python script to do  
that…☹

Finally I had to search for any source code to show color in cmd prompt.  
In the end I found 2 win32api to do that and luckily I can quickly  
included in ruby using the ruby win32api call. Here are the 2 win32api  
to show color:

#----------------------------------------------------------------------  
require ‘Win32API’  
get\_std\_handle = Win32API.new(“kernel32”, “GetStdHandle”, [‘L’], ‘L’)  
set\_console\_txt\_attrb =  
Win32API.new(“kernel32”,“SetConsoleTextAttribute”,  
[‘L’,‘N’], ‘I’)  
hout = get\_std\_handle.call(-11)  
set\_console\_txt\_attrb.call(hout,7)  
puts ‘default command prompt color’  
set\_console\_txt\_attrb.call(hout,12)  
puts ‘command prompt red color text’

# the color range from 1 - 15 for black background color

# we also can change the input text color, I never try that, but I think

# it should be get\_std\_handle.call(-10) or -12…forgot already

#-----------------------------------------------------------------------  
This script is working fine for me to print color text. Can anyone  
integrate this windows coloring script into ‘wirble’ ? It is hard for me  
to change the ‘wirble’ ruby script. It would be thankfully if anyone can  
do that.

Regards,  
Shin Guey

---

<div class="post-metadata">

**Author:** ![shinwoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@shinwoo](https://www.ruby-forum.com/u/shinwoo)\
**Post date:** [March 5, 2007, 5:53pm UTC](https://www.ruby-forum.com/t/how-to-coloring-windows-command-prompt-in-irb/87736/2 "2007-03-05T17:53:14Z")

</div>

On 3/5/07, Shin guey Wong [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> to show color:  
> set\_console\_txt\_attrb.call(hout,12)
> 
> Regards,  
> Shin Guey

maybe this would help: [http://rubyforge.org/projects/winconsole](http://rubyforge.org/projects/winconsole) (ansi  
coloring for console)
