Formatting Ruby Text?

C

Carter Davis

Hello. I was wondering...Is it possible to format text in Ruby besides
using the string literals like \n or \t? For example, can you make text
bold?
 
S

Stefan Rusterholz

Carter said:
Hello. I was wondering...Is it possible to format text in Ruby besides
using the string literals like \n or \t? For example, can you make text
bold?

Not sure I understand your question correctly. If you mean the
source-code then you're looking for a syntax highlighting editor which
doesn't touch the text at all but just highlights it.
If you mean when outputting e.g. via puts then it entirely depends on
your output device. If it is a terminal that supports ANSII escape
sequences then you can use them. Look for the Term::ANSIColor gem on
rubyforge for a convenient way to do that. Plain it is like this:
puts "\e[1mBold\e[0m"
puts "\e[31mRed\e[0m"

With the gem you can do it like this:
puts "Bold".bold
puts "Red".red
(iirc)

Regards
Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,038
Members
47,633
Latest member
BriannaLyk

Latest Threads

Top