From a59d00e4b77ae61763280708c9263a1955031cf0 Mon Sep 17 00:00:00 2001 From: Michael Johnston Date: Tue, 21 Oct 2014 16:38:19 -0700 Subject: [PATCH] allow setting color of table borders swap byebug for debugger in gemspec, see https://github.com/cldwalker/debugger/issues/125 --- Gemfile | 2 +- Gemfile.lock | 12 +++++------- lib/command_line_reporter/row.rb | 4 +++- lib/command_line_reporter/table.rb | 7 +++++-- spec/table_spec.rb | 9 +++++++++ 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 38b9f90..3dd82d5 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ end group :development do gem 'kramdown' - gem "debugger" + gem "byebug" gem "pry" gem "rake" gem "flog" diff --git a/Gemfile.lock b/Gemfile.lock index 4c3503e..6f72ee9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -158,8 +156,8 @@ DEPENDENCIES RedCloth autotest-growl autotest-standalone + byebug colored - debugger faraday flay flog diff --git a/lib/command_line_reporter/row.rb b/lib/command_line_reporter/row.rb index 7467de8..cfe4888 100644 --- a/lib/command_line_reporter/row.rb +++ b/lib/command_line_reporter/row.rb @@ -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 = {}) @@ -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 @@ -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} " : '' diff --git a/lib/command_line_reporter/table.rb b/lib/command_line_reporter/table.rb index 9a90339..144a758 100644 --- a/lib/command_line_reporter/table.rb +++ b/lib/command_line_reporter/table.rb @@ -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] @@ -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] @@ -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? diff --git a/spec/table_spec.rb b/spec/table_spec.rb index df9b565..7eeed8c 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -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 @@ -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|