Skip to content

Commit

Permalink
allow setting color of table borders
Browse files Browse the repository at this point in the history
swap byebug for debugger in gemspec, see cldwalker/debugger#125
  • Loading branch information
lastobelus committed Oct 29, 2015
1 parent 8952877 commit 34af674
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/command_line_reporter/row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module CommandLineReporter
class Row
include OptionsValidator

VALID_OPTIONS = [:header, :color, :bold, :encoding]
VALID_OPTIONS = [:header, :color, :border_color, :bold, :encoding]
attr_accessor :columns, :border, *VALID_OPTIONS

def initialize(options = {})
Expand All @@ -12,6 +12,7 @@ def initialize(options = {})
self.border = false
self.header = options[:header] || false
self.color = options[:color]
self.border_color = options[:border_color]
self.bold = options[:bold] || false
self.encoding = options[:encoding] || :unicode
end
Expand All @@ -31,6 +32,7 @@ def add(column)
def output
screen_count.times do |sr|
border_char = use_utf8? ? "\u2503" : '|'
border_char = border_char.send(self.border_color) if self.border_color

line = (self.border) ? "#{border_char} " : ''

Expand Down
7 changes: 5 additions & 2 deletions lib/command_line_reporter/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ module CommandLineReporter
class Table
include OptionsValidator

VALID_OPTIONS = [:border, :width, :encoding]
VALID_OPTIONS = [:border, :border_color, :width, :encoding]
attr_accessor :rows, *VALID_OPTIONS

def initialize(options = {})
self.validate_options(options, *VALID_OPTIONS)

self.border = options[:border] || false
self.border_color = options[:border_color] || false
self.width = options[:width] || false
self.encoding = options[:encoding] || CommandLineReporter::DEFAULTS[:encoding]

Expand All @@ -20,6 +21,7 @@ def initialize(options = {})
def add(row)
# Inheritance from the table
row.border = self.border
row.border_color = self.border_color

# Inherit properties from the appropriate row
inherit_column_attrs(row) if self.rows[0]
Expand Down Expand Up @@ -60,7 +62,8 @@ def auto_adjust_widths
def separator(type = 'middle')
left, center, right, bar = use_utf8? ? utf8_separator(type) : ascii_separator

left + self.rows[0].columns.map {|c| bar * (c.width + 2)}.join(center) + right
separator_str = left + self.rows[0].columns.map {|c| bar * (c.width + 2)}.join(center) + right
separator_str.send(self.border_color) if self.border_color
end

def use_utf8?
Expand Down
9 changes: 9 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
expect(CommandLineReporter::Table.new(:border => true).border).to eq(true)
end

it 'defaults the border_color' do
expect(CommandLineReporter::Table.new.border_color).to be_false
end

it 'accepts the border_color' do
expect(CommandLineReporter::Table.new(:border_color => true).border_color).to eq(true)
end

it 'output encoding should be ascii' do
expect(CommandLineReporter::Table.new(:encoding => :ascii).encoding).to eq(:ascii)
end
Expand Down Expand Up @@ -112,6 +120,7 @@
end
end


describe '#auto_adjust_widths' do
it 'sets the widths of each column in each row to the maximum required width for that column' do
table = CommandLineReporter::Table.new.tap do |t|
Expand Down

0 comments on commit 34af674

Please sign in to comment.