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

Discussion in 'Ruby' started by Andy, Feb 6, 2008.

  1. Andy

    Andy Guest

    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
     
    Andy, Feb 6, 2008
    #1
    1. Advertising

  2. Andy

    Reacher Guest

    On Feb 5, 7:13 pm, Andy <> wrote:
    > 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?
    >
    > --
    > -Andy
    > "I have a great faith in fools; self-confidence my friends call it." -
    > Edgar Allen Poe


    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.
     
    Reacher, Feb 6, 2008
    #2
    1. Advertising

  3. Andy

    ben baka Guest

    [Note: parts of this message were removed to make it a legal post.]

    See:

    http://benjaminbaka.wordpress.com/2008/02/06/console-output-with-color-using-ruby/


    On Feb 6, 2008 12:54 AM, Reacher <> wrote:

    > On Feb 5, 7:13 pm, Andy <> wrote:
    > > 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?
    > >
    > > --
    > > -Andy
    > > "I have a great faith in fools; self-confidence my friends call it." -
    > > Edgar Allen Poe

    >
    > 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.
    >
    >



    --
    --Ben Baka
    Blog : http://benjaminbaka.wordpress.com/
     
    ben baka, Feb 6, 2008
    #3
  4. On Wed, Feb 06, 2008 at 09:54:55AM +0900, Reacher wrote:
    > On Feb 5, 7:13 pm, Andy <> wrote:
    > > 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?
    > >
    > > --
    > > -Andy
    > > "I have a great faith in fools; self-confidence my friends call it." -
    > > Edgar Allen Poe

    >
    > 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.


    Also look at highline (http://highline.rubyforge.org/). It has
    themeable colorized output for command line interfaces.

    http://highline.rubyforge.org/doc/classes/HighLine/ColorScheme.html

    enjoy,

    -jeremy

    --
    ========================================================================
    Jeremy Hinegardner
     
    Jeremy Hinegardner, Feb 6, 2008
    #4
  5. Andy

    Trans Guest

    On Feb 5, 7:13 pm, Andy <> wrote:
    > 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.
     
    Trans, Feb 6, 2008
    #5
  6. Andy

    Phlip Guest

    Andy wrote:
    > 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?

    --
    Phlip
     
    Phlip, Feb 6, 2008
    #6
  7. Andy

    Andy Guest

    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

    On Feb 6, 2008 12:16 PM, Trans <> wrote:
    >
    >
    > On Feb 5, 7:13 pm, Andy <> wrote:
    > > 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.
    >
    >
     
    Andy, Feb 6, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mdx

    color console output

    mdx, Mar 13, 2006, in forum: Java
    Replies:
    5
    Views:
    1,155
    mcoolive
    May 12, 2012
  2. Eric Pinnell
    Replies:
    5
    Views:
    3,731
    Barefoot Kid
    Feb 28, 2004
  3. pratap
    Replies:
    3
    Views:
    476
    James Kanze
    Jul 19, 2007
  4. Replies:
    5
    Views:
    3,459
    James Kanze
    Mar 4, 2008
  5. Kamaljeet Saini
    Replies:
    0
    Views:
    466
    Kamaljeet Saini
    Feb 13, 2009
Loading...

Share This Page