[ANN] col 1.0.1

col: high-level console color formatting for Ruby

If you want a dash of color in your Ruby console program, use
Term::ANSIColor.
If your color formatting requirements are more complicated, use Col.
Col provides as much convenience as possible without modifying builtin
classes.

=== SYNOPSIS

    require 'col'

    puts Col("Hello world!").red.bold
    puts Col("Hello world!").rb
    puts Col("Hello world!").fmt [:red, :bold]
    puts Col("Hello world!").fmt :rb

    puts Col("Hello ", "world!").fmt :red, :green
    puts Col("Hello ", "world!").fmt "r,g"

    puts Col("Hello ", "world!").fmt [:red, :bold], [:green, :bold]
    puts Col("Hello ", "world!").fmt "rb,gb"

    puts Col("Hello ", "world!").fmt [:bold], [:cyan, :italic, :on_white]
    puts Col("Hello ", "world!").fmt "_b,ciow"

    puts Col("Hello ", "world!").fmt [:blue, :on_yellow], [:on_green]
    puts Col("Hello ", "world!").fmt "b_oy,__og"

    puts Col.inline( "Hello ", :red, "world!", :blue )

    puts Col.inline(
      "Hello ", [:red, :bold, :on_white],
      "world!", :b_oy
    )

See http://gsinclair.github.com/col.html for full details.

=== 1.0.1 / 2012-01-01

* 1 minor enhancement:

  * Col#to_str implemented to play nicely with puts
    (problem became apparent with Ruby 1.9.3?)

=== 1.0.0 / 2010-07-25

* First release

=== LICENCE

MIT

Love the idea. Where do I find "tap"

C:/Ruby/lib/ruby/gems/1.8/gems/col-1.0.1/lib/col.rb:101:in `result': undefined method `tap' for "":String (NoMethodError)
     from C:/Ruby/lib/ruby/gems/1.8/gems/col-1.0.1/lib/col.rb:54:in `fmt'
     from C:/Ruby/lib/ruby/gems/1.8/gems/col-1.0.1/lib/col.rb:71:in `method_missing'

101 String.new.tap { |str|
102 @strings.zip(@format_spec).each do |string, spec|
103 d = decorated_string(string, spec)
104 str << d
105 end
106 }

Ah... Object#tap is a Ruby 1.9 feature that doesn't exist in 1.8.
(Actually, it probably exists in 1.8.7, but not 1.8.6 or earlier.) So
I guess Col doesn't work in 1.8 :frowning:

It's easily defined:
  class Object
    def tap
      yield self
      self
    end
  end

Thanks for the report. I'll do some proper 1.8 testing and try to
make it work, removing any 1.9-specific code. Look for a 1.0.2
release sometime soon.

Gavin

···

On Mon, Jan 2, 2012 at 11:12 AM, Tom Reilly <w3gat@nwlagardener.org> wrote:

Love the idea. Where do I find "tap"
[...]
101 String.new.tap { |str|
[...]

Col v1.0.2 has been released. It is compatible with Ruby 1.8.6+. I
haven't tested any earlier versions.

Gavin

···

On Mon, Jan 2, 2012 at 11:58 AM, Gavin Sinclair <gsinclair@gmail.com> wrote:

Thanks for the report. I'll do some proper 1.8 testing and try to
make it work, removing any 1.9-specific code. Look for a 1.0.2
release sometime soon.