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

A

Andy

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?

--=20
-Andy
"I have a great faith in fools; self-confidence my friends call it." =96
Edgar Allen Poe
 
R

Reacher

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?

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/) is a gem that
colorizes text based on coding language.
 
J

Jeremy Hinegardner

T

Trans

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 Frank to thank for the original version of this lib.

T.
 
P

Phlip

Andy said:
Hello everyone, is there an easy way for me to color my console
output?

New question: what's a good escape code to query the current background color?

I dislike colored output that fails to contrast with my console...
What about updating just a particular x/y coordinate?

Either curses or ncurses, right?
 
A

Andy

Thank you all very much for your info and links. It's very much appreciate=
d.

--=20
-Andy
"I have a great faith in fools; self-confidence my friends call it." =96
Edgar Allen Poe

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 Frank to thank for the original version of this lib.

T.
 

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
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top