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 21, 2014
1 parent bd9dde4 commit 446ff3b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end

group :development do
gem 'kramdown'
gem "debugger"
gem "byebug"
gem "pry"
gem "rake"
gem "flog"
Expand Down
12 changes: 5 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ GEM
ast (1.1.0)
autotest-growl (0.2.16)
autotest-standalone (4.5.11)
byebug (3.2.0)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
celluloid (0.15.2)
timers (~> 1.1.0)
celluloid-io (0.15.0)
Expand All @@ -19,13 +22,8 @@ GEM
charlock_holmes (0.6.9.4)
coderay (1.1.0)
colored (1.2)
columnize (0.3.6)
debugger (1.6.5)
columnize (>= 0.3.1)
debugger-linecache (~> 1.2.0)
debugger-ruby_core_source (~> 1.3.1)
columnize (0.8.9)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.3.1)
diff-lcs (1.2.5)
docile (1.1.3)
faraday (0.9.0)
Expand Down Expand Up @@ -158,8 +156,8 @@ DEPENDENCIES
RedCloth
autotest-growl
autotest-standalone
byebug
colored
debugger
faraday
flay
flog
Expand Down
2 changes: 1 addition & 1 deletion lib/command_line_reporter/column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def to_cell(str)
# then colorize the cell text
cell = str.empty? ? blank_cell : aligned_cell(str)
padding_str = ' ' * self.padding
padding_str + colorize(cell) + padding_str
colorize(padding_str + cell + padding_str)
end

def blank_cell
Expand Down
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 446ff3b

Please sign in to comment.