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.
316017672dfe1c4e8e22843348ee32d4?d=identicon&s=25 Sy Ali (Guest)
on 2006-04-12 07: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?
A4a4095ff08bd0fced3c3fddbeac743a?d=identicon&s=25 Cameron McBride (Guest)
on 2006-04-12 08:27
(Received via mailing list)
Sy,

On 4/12/06, Sy Ali <sy1234@gmail.com> 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
D84df7c68f790e492c4ad4ec5fe65547?d=identicon&s=25 Florian Frank (Guest)
on 2006-04-12 11: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
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-04-12 14: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 Gray II
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-04-12 16:59
(Received via mailing list)
On Wed, 12 Apr 2006, Florian Frank 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
316017672dfe1c4e8e22843348ee32d4?d=identicon&s=25 Sy Ali (Guest)
on 2006-04-12 18:07
(Received via mailing list)
On 4/12/06, Cameron McBride <cameron.mcbride@gmail.com> 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 Gray II <james@grayproductions.net> 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
316017672dfe1c4e8e22843348ee32d4?d=identicon&s=25 Sy Ali (Guest)
on 2006-04-12 18:16
(Received via mailing list)
On 4/12/06, Sy Ali <sy1234@gmail.com> wrote:
> On 4/12/06, James Edward Gray II <james@grayproductions.net> 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) %>!")
316017672dfe1c4e8e22843348ee32d4?d=identicon&s=25 Sy Ali (Guest)
on 2006-04-12 18:22
(Received via mailing list)
On 4/12/06, Sy Ali <sy1234@gmail.com> 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) %>!")
D84df7c68f790e492c4ad4ec5fe65547?d=identicon&s=25 Florian Frank (Guest)
on 2006-04-12 20: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.
316017672dfe1c4e8e22843348ee32d4?d=identicon&s=25 Sy Ali (Guest)
on 2006-04-12 22:25
(Received via mailing list)
On 4/12/06, Florian Frank <flori@nixe.ping.de> 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.
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-04-12 22:31
(Received via mailing list)
On Thu, 13 Apr 2006, Sy Ali wrote:

> On 4/12/06, Florian Frank <flori@nixe.ping.de> 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
316017672dfe1c4e8e22843348ee32d4?d=identicon&s=25 Sy Ali (Guest)
on 2006-04-12 22:53
(Received via mailing list)
On 4/12/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> On Thu, 13 Apr 2006, Sy Ali wrote:
>
> > On 4/12/06, Florian Frank <flori@nixe.ping.de> 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.
10d4acbfdaccb4eee687a428ca00a5d8?d=identicon&s=25 Jim Weirich (weirich)
on 2006-04-13 00:08
unknown wrote:
> On Thu, 13 Apr 2006, Sy Ali wrote:
>
>> On 4/12/06, Florian Frank <flori@nixe.ping.de> 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 Weirich
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 unknown (Guest)
on 2006-04-13 01:20
(Received via mailing list)
On Thu, 13 Apr 2006, Jim Weirich 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.