Skip to content
Browse files

Merge pull request #25 from TvL2386/master

Fixed ability to use '|' characters in a Cell and have it included in the cell width count
  • Loading branch information...
2 parents 8f67731 + e98391b commit a8f9179b4a21268ef49c858651bd0ee9fbab2eca @scottjg scottjg committed
Showing with 10 additions and 1 deletion.
  1. +3 −0 examples/examples.rb
  2. +1 −1 lib/terminal-table/cell.rb
  3. +6 −0 spec/cell_spec.rb
View
3 examples/examples.rb
@@ -5,6 +5,9 @@
puts table(['a', 'b'], [1, 2], [3, 4])
puts
+puts table(['name', 'content'], ['ftp.example.com', '1.1.1.1'], ['www.example.com', '|lalalala|lalala|'])
+
+puts
t = table ['a', 'b']
t.style = {:padding_left => 2, :width => 80}
t << [1, 2]
View
2 lib/terminal-table/cell.rb
@@ -87,7 +87,7 @@ def width
def escape(line)
line.to_s.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '').
gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '').
- gsub(/[\x03|\x1a]/, '')
+ gsub(/(\x03|\x1a)/, '')
end
end
end
View
6 spec/cell_spec.rb
@@ -51,4 +51,10 @@ class String; include Term::ANSIColor; end
cell.render.should == " foo "
end
+ it "should not ignore pipe characters" do
+ cell = Cell.new :value => "f|o|o", :table => Terminal::Table.new, :index => 0
+ cell.value.should == "f|o|o"
+ cell.value_for_column_width_recalc.should == 'f|o|o'
+ cell.render.should == " f|o|o "
+ end
end

0 comments on commit a8f9179

Please sign in to comment.
Something went wrong with that request. Please try again.