# How can i make the colorful font with black background for puts?

**URL:** <https://rubytalk.org/t/how-can-i-make-the-colorful-font-with-black-background-for-puts/65306>\
**Category:** ruby-talk\
**Created:** [19 April 2012 13:08 UTC](https://rubytalk.org/t/how-can-i-make-the-colorful-font-with-black-background-for-puts/65306 "2012-04-19T13:08:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [19 April 2012 13:08 UTC](https://rubytalk.org/t/how-can-i-make-the-colorful-font-with-black-background-for-puts/65306/1 "2012-04-19T13:08:39Z")

</div>

puts 'Hello World."

That prints 'Hello World' on white background with normal font size.  
How can i make the font size bigger with black background and with green  
font color like we can do in gnome-terminal from

> > Colors.

Is it possible to change color of font and background color of terminal  
with ruby?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)\
**Post date:** [19 April 2012 13:25 UTC](https://rubytalk.org/t/how-can-i-make-the-colorful-font-with-black-background-for-puts/65306/2 "2012-04-19T13:25:48Z")

</div>

[http://rubyworks.github.com/ansi](http://rubyworks.github.com/ansi)

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [19 April 2012 13:34 UTC](https://rubytalk.org/t/how-can-i-make-the-colorful-font-with-black-background-for-puts/65306/3 "2012-04-19T13:34:52Z")

</div>

Hi,

When working on Linux, ANSI escape codes are probably the most simple  
(but also most lowlevel) way to do this:

> **[ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code)**
>
> ANSI escape sequences are a standard for in-band signaling to control the cursor location, color, and other options on video text terminals. Certain sequences of bytes, most starting with Esc and '\[', are embedded into the text, which the terminal looks for and interprets as commands, not as character codes. ANSI sequences were introduced in the 1970s to replace vendor-specific sequences and became widespread in the computer equipment market by the early 1980s. They were used by the nascent bulle...

There are also a lot of libraries floating around. The most extensive is  
probably ncurses.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [19 April 2012 15:08 UTC](https://rubytalk.org/t/how-can-i-make-the-colorful-font-with-black-background-for-puts/65306/4 "2012-04-19T15:08:14Z")

</div>

I'm trying to do 'green font/texts on black background'.

printf "\033[40m\033[37mBlack Background\033[0m\n"

But that green is not brighter.  
I'm trying to do something like,  
[http://kpumuk.info/ruby-on-rails/colorizing-console-ruby-script-output/](http://kpumuk.info/ruby-on-rails/colorizing-console-ruby-script-output/)

ESC-1, 32;40

How can i rewrite this printf "\033[40m\033[37mBlack  
Background\033[0m\n" for escape one(1) ?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [19 April 2012 15:34 UTC](https://rubytalk.org/t/how-can-i-make-the-colorful-font-with-black-background-for-puts/65306/5 "2012-04-19T15:34:04Z")

</div>

How can i set the text color to light green? Not the 32 only.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Lars\_Haugseth1](https://avatars.discourse-cdn.com/v4/letter/l/839c29/32.png) [@Lars\_Haugseth1](https://rubytalk.org/u/Lars_Haugseth1)\
**Post date:** [20 April 2012 17:43 UTC](https://rubytalk.org/t/how-can-i-make-the-colorful-font-with-black-background-for-puts/65306/6 "2012-04-20T17:43:05Z")

</div>

$ gem install term-ansicolor

In your Ruby code:

&nbsp;&nbsp;&nbsp;require 'term/ansicolor'

&nbsp;&nbsp;&nbsp;class String  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include Term::ANSIColor  
&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;puts "Hello World".green.on\_black

More info: [GitHub - flori/term-ansicolor: Ruby library that colors strings using ANSI escape sequences](https://github.com/flori/term-ansicolor)

> **···**
>
> On 04/19/2012 03:08 PM, gmspro gmspro wrote:
> 
> > puts 'Hello World." That prints 'Hello World' on white background with normal font size. How can i make the font size bigger with black background and with green font color like we can do in gnome-terminal from Edit\>Preferences\>Colors. Is it possible to change color of font and background color of terminal with ruby?
> 
> --  
> Lars Haugseth

---

<div class="post-metadata">

**Author:** ![11142](https://avatars.discourse-cdn.com/v4/letter/1/e0b2c6/32.png) [@11142](https://rubytalk.org/u/11142)\
**Post date:** [19 April 2012 15:21 UTC](https://rubytalk.org/t/how-can-i-make-the-colorful-font-with-black-background-for-puts/65306/7 "2012-04-19T15:21:11Z")

</div>

W dniu 19 kwietnia 2012 17:08 użytkownik gmspro gmspro  
\<lists@ruby-forum.com\> napisał:

> I'm trying to do 'green font/texts on black background'.
> 
> printf "\033[40m\033[37mBlack Background\033[0m\n"
> 
> But that green is not brighter.  
> I'm trying to do something like,  
> [Colorizing console Ruby-script output | Dmytro Shteflyuk's Home](http://kpumuk.info/ruby-on-rails/colorizing-console-ruby-script-output/)
> 
> ESC-1, 32;40
> 
> How can i rewrite this printf "\033[40m\033[37mBlack  
> Background\033[0m\n" for escape one(1) ?

These technique (ANSI escape codes) only work on Linux flavors. To  
make it work on Windows, you need to run your Ruby script from inside  
some better console than default cmd - I suggest ansicon (google it).

-- Matma Rex

---

<div class="post-metadata">

**Author:** ![Zachary\_Scott2](https://avatars.discourse-cdn.com/v4/letter/z/ccd318/32.png) [@Zachary\_Scott2](https://rubytalk.org/u/Zachary_Scott2)\
**Post date:** [19 April 2012 16:23 UTC](https://rubytalk.org/t/how-can-i-make-the-colorful-font-with-black-background-for-puts/65306/8 "2012-04-19T16:23:03Z")

</div>

Has anyone got this to work for (all) ruby output? Like in a bashrc or  
something?  
It'd be nice to have rake output, and the like, be escaped automatically..

> **···**
>
> On Thu, Apr 19, 2012 at 11:34 AM, gmspro gmspro \<lists@ruby-forum.com\> wrote:
> 
> > How can i set the text color to light green? Not the 32 only.
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Eric\_Christopherson](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/eric_christopherson/32/1849_2.png) [@Eric\_Christopherson](https://rubytalk.org/u/Eric_Christopherson)\
**Post date:** [20 April 2012 17:26 UTC](https://rubytalk.org/t/how-can-i-make-the-colorful-font-with-black-background-for-puts/65306/9 "2012-04-20T17:26:04Z")

</div>

puts "\033[40;37;1mBlack Background\033[0m"

Notes:  
- puts appends "\n" automatically  
- escape sequence "\033[1m" is used for bright (high intensity)  
- separate escape sequences can be combined by changing the trailing  
'm' of all but the last one to ';'

> **···**
>
> On Thu, Apr 19, 2012 at 10:08 AM, gmspro gmspro \<lists@ruby-forum.com\> wrote:
> 
> > I'm trying to do 'green font/texts on black background'.
> > 
> > printf "\033[40m\033[37mBlack Background\033[0m\n"
> > 
> > But that green is not brighter.  
> > I'm trying to do something like,  
> > [Colorizing console Ruby-script output | Dmytro Shteflyuk's Home](http://kpumuk.info/ruby-on-rails/colorizing-console-ruby-script-output/)
> > 
> > ESC-1, 32;40
> > 
> > How can i rewrite this printf "\033[40m\033[37mBlack  
> > Background\033[0m\n" for escape one(1) ?

---

<div class="post-metadata">

**Author:** ![7rans](https://avatars.discourse-cdn.com/v4/letter/7/a8b319/32.png) [@7rans](https://rubytalk.org/u/7rans)\
**Post date:** [20 April 2012 03:54 UTC](https://rubytalk.org/t/how-can-i-make-the-colorful-font-with-black-background-for-puts/65306/10 "2012-04-20T03:54:55Z")

</div>

I just read about grc today. Might try that.

> **···**
>
> >
