Forum: Ruby using ansicolor

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sy Ali (Guest)
on 2006-04-12 09:20
(Received via mailing list)
http://term-ansicolor.rubyforge.org/

I did a successful gem install of term-ansicolor and am trying to use
it:

  include Term::ANSIColor
  print red, bold, "red bold", reset, "\n"

gives me:

  uninitialized constant Term


I tried all kinds of variations, found some code where other people
used this and tried all that out.  No luck.

Is this a problem with my Ruby or gems installation?
Cameron McBride (Guest)
on 2006-04-12 10:27
(Received via mailing list)
Sy,

On 4/12/06, Sy Ali <removed_email_address@domain.invalid> wrote:
>
>
> I tried all kinds of variations, found some code where other people
> used this and tried all that out.  No luck.
>
> Is this a problem with my Ruby or gems installation?


make sure you require the correct library (you might need to require
'rubygems' first)

require "lib/term/ansicolor"

(why the maintainer chose to put the lib/ prefix, I don't really know)

Cameron
Florian F. (Guest)
on 2006-04-12 13:51
(Received via mailing list)
Hi,

Sy Ali wrote:

>
>
>I tried all kinds of variations, found some code where other people
>used this and tried all that out.  No luck.
>
>Is this a problem with my Ruby or gems installation?
>
>
It seems to work fine here:

closure:~ flori$ ruby
require 'term/ansicolor'
include Term::ANSIColor
print red, bold, "red bold", reset, "\n"
*red bold*

Have you required the library before trying to use it?

Florian
James G. (Guest)
on 2006-04-12 16:50
(Received via mailing list)
On Apr 12, 2006, at 12:18 AM, Sy Ali wrote:

> http://term-ansicolor.rubyforge.org/

Just FYI, HighLine can also do ANSI color, and much, much more...  :)

James Edward G. II
unknown (Guest)
on 2006-04-12 18:59
(Received via mailing list)
On Wed, 12 Apr 2006, Florian F. wrote:

> Florian
that's good stuff florian!  any idea how to make this work? (it's a
snippet out
of something i'm working on attm):


     harp:~ > cat a.rb
     require 'readline'
     require 'rubygems'
     require_gem 'term-ansicolor'
     class ::String; include Term::ANSIColor; end


     complete = lambda do |words|
       words = words.strip.split(%r/\s+/) unless Array === words
       Readline::completion_proc = lambda do |s|
         list = words.select{|c| c.index s}
         list = list.empty? ? words : list
         list.map{|word| word.blue}
       end
     end

     sif_in = []

     readline =
       if STDIN.tty?
         lambda{|prompt| line =
Readline::readline(prompt.strip.red.dark.bold.underline << "
").to_s.strip; sif_in << line; line.empty? ? nil : line}
       else
         lambda{|prompt| line = STDIN.gets.to_s.strip; sif_in << line;
line.empty? ? nil : line}
       end


     complete['one two three']
     line = readline['number >']
     puts line


the interaction between the completion_proc and term-ansicolor results
in the
the escape codes being shown literally?  thoughts?

thanks.

-a
Sy Ali (Guest)
on 2006-04-12 20:07
(Received via mailing list)
On 4/12/06, Cameron McBride <removed_email_address@domain.invalid> wrote:
> make sure you require the correct library (you might need to require
> 'rubygems' first)

That was the solution.  I needed to require rubygems.  Apparently, I
thought everything was more magical.  ;)

require 'rubygems'
require 'term/ansicolor'
include Term::ANSIColor
print red, bold, "red bold", reset, "\n"


On 4/12/06, James Edward G. II <removed_email_address@domain.invalid> wrote:
> Just FYI, HighLine can also do ANSI color, and much, much more...  :)

Thanks.  I went poking around for a solution and a quick search came
up with ansicolor.  I'll investigate this one when I have a bit of
time.

http://highline.rubyforge.org/
http://www.rubyquiz.com/quiz29.html
Sy Ali (Guest)
on 2006-04-12 20:16
(Received via mailing list)
On 4/12/06, Sy Ali <removed_email_address@domain.invalid> wrote:
> On 4/12/06, James Edward G. II <removed_email_address@domain.invalid> wrote:
> > Just FYI, HighLine can also do ANSI color, and much, much more...  :)
>
> Thanks.  I went poking around for a solution and a quick search came
> up with ansicolor.  I'll investigate this one when I have a bit of
> time.
>
> http://highline.rubyforge.org/
> http://www.rubyquiz.com/quiz29.html

Silly me, this is Ruby.  Although nothing is straightforward, google
gave me the answers I needed:

require 'rubygems'
require 'highline/import'
say("This is <%= color('red bold', red, bold) %>!")
Sy Ali (Guest)
on 2006-04-12 20:22
(Received via mailing list)
On 4/12/06, Sy Ali <removed_email_address@domain.invalid> wrote:
> Silly me, this is Ruby.  Although nothing is straightforward, google
> gave me the answers I needed:

I'm not sure that made english sense.  Let's try that again.

Silly me, "a bit of time" for Ruby really is only a small bit of time.
 I have some time right now so I'll play with it.

I played with it, and like everything else I've seen I'll need to
learn a bit more to get it to work.  However, I quickly googled for
someone else's code and easily adapted it to my needs:

require 'rubygems'
require 'highline/import'
say("This is <%= color('red bold', red, bold) %>!")
Florian F. (Guest)
on 2006-04-12 22:47
(Received via mailing list)
Sy Ali wrote:

>That was the solution.  I needed to require rubygems.  Apparently, I
>thought everything was more magical.  ;)
>
>require 'rubygems'
>require 'term/ansicolor'
>include Term::ANSIColor
>print red, bold, "red bold", reset, "\n"
>
>
You can set RUBYOPT=-rubygems in your environment, if you don't want to
require 'rubygems'. So users can transparently either use gems or
install from source or use their package managers.
Sy Ali (Guest)
on 2006-04-13 00:25
(Received via mailing list)
On 4/12/06, Florian F. <removed_email_address@domain.invalid> wrote:
> You can set RUBYOPT=-rubygems in your environment
<snip>

Aah, good point.  Maybe I should also recommend this for the guys who
handle the packages for my Linux distro.
unknown (Guest)
on 2006-04-13 00:31
(Received via mailing list)
On Thu, 13 Apr 2006, Sy Ali wrote:

> On 4/12/06, Florian F. <removed_email_address@domain.invalid> wrote:
>> You can set RUBYOPT=-rubygems in your environment
> <snip>
>
> Aah, good point.  Maybe I should also recommend this for the guys who
> handle the packages for my Linux distro.

be careful.  it's breaks some packages, like the gsl.

-a
Sy Ali (Guest)
on 2006-04-13 00:53
(Received via mailing list)
On 4/12/06, removed_email_address@domain.invalid 
<removed_email_address@domain.invalid> wrote:
> On Thu, 13 Apr 2006, Sy Ali wrote:
>
> > On 4/12/06, Florian F. <removed_email_address@domain.invalid> wrote:
> >> You can set RUBYOPT=-rubygems in your environment
> > <snip>
> >
> > Aah, good point.  Maybe I should also recommend this for the guys who
> > handle the packages for my Linux distro.
>
> be careful.  it's breaks some packages, like the gsl.

Always a catch.  Ok, I'd rather insert it into my code manually every
time.. at this point I"m just goofing around anyways.
Jim W. (Guest)
on 2006-04-13 02:08
unknown wrote:
> On Thu, 13 Apr 2006, Sy Ali wrote:
>
>> On 4/12/06, Florian F. <removed_email_address@domain.invalid> wrote:
>>> You can set RUBYOPT=-rubygems in your environment
>> <snip>
>>
>> Aah, good point.  Maybe I should also recommend this for the guys who
>> handle the packages for my Linux distro.
>
> be careful.  it's breaks some packages, like the gsl.

Does gsl just not work with gems at all?  Or is it that setting RUBYOPT
breaks it?

Thanks?

--
-- Jim W.
unknown (Guest)
on 2006-04-13 03:20
(Received via mailing list)
On Thu, 13 Apr 2006, Jim W. wrote:

>> be careful.  it's breaks some packages, like the gsl.
>
> Does gsl just not work with gems at all?  Or is it that setting RUBYOPT
> breaks it?

there is a superclass conflict with with the Rational class.  afaik this
is
the fault of the gsl...

i can send the error message later - it's on a box at home.

cheers.

-a
This topic is locked and can not be replied to.