Skip to content

Instantly share code, notes, and snippets.

@Larusso
Created February 4, 2015 11:31
Show Gist options
  • Save Larusso/ce7df9a788e945e83cae to your computer and use it in GitHub Desktop.
Save Larusso/ce7df9a788e945e83cae to your computer and use it in GitHub Desktop.
Monkeypatch for text-table to support ANSI colors
require 'colorize'
module Text
class Table
class Cell
def initialize(options = {}) #:nodoc:
@value = options[:value].to_s
@row = options[:row]
@align = options[:align ] || :left
@colspan = options[:colspan] || 1
@color = options[:color] || :default
@background = options[:background] || :default
@effect = options[:effect] || :default
end
def set_color(string)
string.colorize color: @color, background: @background, mode: @effect
end
def to_s #:nodoc:
([' ' * table.horizontal_padding]*2).join case align
when :left
set_color(value.ljust cell_width)
when :right
set_color(value.rjust cell_width)
when :center
set_color(value.center cell_width)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment