How do I format outputted text?

D

Dan Mariani

How can I control the format (font size, color and location) for text
that I am out-putting to the screen. For example:

puts ("Ruby is great!")

How can I make this appear in larger font on my screen when I run my
program?

Any help would be GREATLY appreciated!!

dm
 
D

Dan Zwell

Dan said:
How can I control the format (font size, color and location) for text
that I am out-putting to the screen. For example:

puts ("Ruby is great!")

How can I make this appear in larger font on my screen when I run my
program?

Any help would be GREATLY appreciated!!

dm

What environment are you running the program in? Are you using a GUI
toolkit? Are you just printing to the console? Are you (trying) to get
this functionality in TextMate? What operating system are you using? Do
you need a portable program?

See http://catb.org/~esr/faqs/smart-questions.html

Dan
 
D

Dan Mariani

Dan said:
What environment are you running the program in?
A: I am running the program from the DOS Command Prompt.

Are you using a GUI toolkit?
A: No, I don't even know what one is. I am new to both programming and
Ruby.

Are you just printing to the console?
A: Yes, I am just printing to the console.

Are you (trying) to get this functionality in TextMate?
A: I am not familiar with TextMate.

What operating system are you using?
A: Windows XP

Do you need a portable program?
A: Yes, I would prefer that it be portable.

Thanks for the help!
 
D

Dan Zwell

Dan said:
A: I am running the program from the DOS Command Prompt.

Are you using a GUI toolkit?
A: No, I don't even know what one is. I am new to both programming and
Ruby.

Are you just printing to the console?
A: Yes, I am just printing to the console.

When printing to the console, the simplest case is that you add spaces
or newlines.

10.times { puts }
puts (" " * 20) + "This is in the middle of the screen"
10.times { puts }

Being that most text mode programs print one line at a time, there isn't
an easier way. Perhaps you could write a method that printed 30 lines at
a time, if you wanted the illusion of being able to print to various
parts of the screen. A lot of people use simple ideas like printing
blank lines or loud characters to get the eye's attention. You can't
change the font, but there's a lot you can do to effectively
communicate. Some examples:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

!!!!!! Are you sure? !!!!!!!!!

==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffh264] vfm: ffmpeg (FFmpeg H.264)
==========================================================================

Started.........

To do more with screen positioning, there is a library called ncurses
that gives you complete flexibility to place anything anywhere on the
screen. This is really the standard for complex console output. The
homepage for ncurses-ruby is here: http://ncurses-ruby.berlios.de/ , and
I saw what looked like a Windows package, but I don't know whether that
means you can install it without cygwin (Linux emulation, basically).
Learning to use this library might be too much to learn at once for a
beginner to programming, but know that this is the most powerful tool
(that can be used with Ruby) for doing layout stuff on the console.

If you will be content with being able to change colors, I would go for
a library called HighLine (http://highline.rubyforge.org/). See the
examples here
http://viewvc.rubyforge.mmmultiworks.com/cgi/viewvc.cgi/trunk/highline/examples/?root=highline
for descriptions of how it can be used. You can find documentation from
the first link.

Good luck,
Dan
 
J

Jeremy Woertink

Dan said:
How can I control the format (font size, color and location) for text
that I am out-putting to the screen. For example:

puts ("Ruby is great!")

How can I make this appear in larger font on my screen when I run my
program?

Any help would be GREATLY appreciated!!

dm

Doing it in console, you can't format it. There are GUI toolkits like
FXRuby you can checkout or just do a google search for GUI toolkits for
Ruby. If you do Rails development on MacOSX there is a gem that allows
you to have your text in different colors for your log file. Being new
to all this stuff, that may be a bit too much, but just keep it in mind
if you ever get into Rails development, then hop back on here and ask
the question again :)


~Jeremy
 
M

Mohit Sindhwani

Jeremy said:
Doing it in console, you can't format it. There are GUI toolkits like
FXRuby you can checkout or just do a google search for GUI toolkits for
Ruby. If you do Rails development on MacOSX there is a gem that allows
you to have your text in different colors for your log file. Being new
to all this stuff, that may be a bit too much, but just keep it in mind
if you ever get into Rails development, then hop back on here and ask
the question again :)


~Jeremy

Or you could use WideStudio [1] to make Ruby based executable programs
in a GUI style!

[1] www.widestudio.org

Cheers,
Mohit.
9/3/2007 | 11:33 PM.
 

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

Forum statistics

Threads
474,264
Messages
2,571,322
Members
48,005
Latest member
ChasityFan

Latest Threads

Top