Skip to content

Commit

Permalink
Merge pull request #119 from nanobowers/issue118
Browse files Browse the repository at this point in the history
fixing issue #118
  • Loading branch information
nateberkopec committed Feb 3, 2021
2 parents 50f2dfc + ecbd0b9 commit f06ffb4
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 20 deletions.
36 changes: 36 additions & 0 deletions examples/issue118.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env ruby

require_relative '../lib/terminal-table'

puts Terminal::Table.new(headings: ['a', 'b', 'c', 'd'], style: { border: :unicode })

puts

tbl = Terminal::Table.new do |t|
t.style = { border: :unicode }
t.add_separator
t.add_separator
t.add_row ['x','y','z']
t.add_separator
t.add_separator
end
puts tbl

puts

puts Terminal::Table.new(headings: [['a', 'b', 'c', 'd'], ['cat','dog','frog','mouse']], style: { border: :unicode })

puts

puts Terminal::Table.new(headings: ['a', 'b', 'c', 'd'])

puts

tbl = Terminal::Table.new do |t|
t.add_separator
t.add_separator
t.add_row ['x','y','z']
t.add_separator
t.add_separator
end
puts tbl
8 changes: 8 additions & 0 deletions lib/terminal-table/cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ def width
end
inner_width + padding
end

def inspect
fields = %i[alignment colspan index value width].map do |name|
val = self.instance_variable_get('@'+name.to_s)
"@#{name}=#{val.inspect}"
end.join(', ')
return "#<#{self.class} #{fields}>"
end
end
end
end
2 changes: 1 addition & 1 deletion lib/terminal-table/row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Row
##
# Initialize with _width_ and _options_.

def initialize table, array = []
def initialize table, array = [], **_kwargs
@cell_index = 0
@table = table
@cells = []
Expand Down
78 changes: 59 additions & 19 deletions spec/unicode_table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,8 @@ module Terminal
╰──────┴───────╯
EOF
end

it "should test many separator borders" do
it "should test many separator borders" do
@table.style = { border: :unicode_thick_edge }
@table.title = 'Borders'
@table.headings = ['name', 'value']
Expand Down Expand Up @@ -786,26 +786,66 @@ module Terminal
┃ name │ value ┃
┣══════╪═══════┫
┃ 1st │ 1 ┃
┣━━━━━━━━━━━━━┫
┣╍╍╍╍╍╍╍╍╍╍╍╍╍┫
┣┅┅┅┅┅┅┅┅┅┅┅┅┅┫
┣┉┉┉┉┉┉┉┉┉┉┉┉┉┫
┣━━━━━━━━━━━━━┫
┣╍╍╍╍╍╍╍╍╍╍╍╍╍┫
┣┅┅┅┅┅┅┅┅┅┅┅┅┅┫
┣┉┉┉┉┉┉┉┉┉┉┉┉┉┫
┣━━━━━━━━━━━━━┫
┣╍╍╍╍╍╍╍╍╍╍╍╍╍┫
┣┅┅┅┅┅┅┅┅┅┅┅┅┅┫
┣┉┉┉┉┉┉┉┉┉┉┉┉┉┫
┠╌╌╌╌╌╌╌╌╌╌╌╌╌┨
┠┄┄┄┄┄┄┄┄┄┄┄┄┄┨
┠┈┈┈┈┈┈┈┈┈┈┈┈┈┨
┣═════════════┫
┣━━━━━━━━━━━━━┫
┣╍╍╍╍╍╍╍╍╍╍╍╍╍┫
┣┅┅┅┅┅┅┅┅┅┅┅┅┅┫
┣┉┉┉┉┉┉┉┉┉┉┉┉┉┫
┣━━━━━━━━━━━━━┫
┣╍╍╍╍╍╍╍╍╍╍╍╍╍┫
┣┅┅┅┅┅┅┅┅┅┅┅┅┅┫
┣┉┉┉┉┉┉┉┉┉┉┉┉┉┫
┣━━━━━━━━━━━━━┫
┣╍╍╍╍╍╍╍╍╍╍╍╍╍┫
┣┅┅┅┅┅┅┅┅┅┅┅┅┅┫
┣┉┉┉┉┉┉┉┉┉┉┉┉┉┫
┠╌╌╌╌╌╌╌╌╌╌╌╌╌┨
┠┄┄┄┄┄┄┄┄┄┄┄┄┄┨
┠┈┈┈┈┈┈┈┈┈┈┈┈┈┨
┣═════════════┫
┃ last │ N ┃
┗━━━━━━┷━━━━━━━┛
EOF
end
end

it "should allow headings with no rows (issue #118.a)" do
@table.headings = ['a', 'b', 'c', 'd']
@table.render.should eq <<-EOF.deindent
┌───┬───┬───┬───┐
│ a │ b │ c │ d │
╞═══╧═══╧═══╧═══╡
└───────────────┘
EOF
end

it "should allow multiple headings with no rows (issue #118.b)" do
@table.headings = [['a', 'b', 'c', 'd'], ['cat','dog','frog','mouse']]
@table.render.should eq <<-EOF.deindent
┌─────┬─────┬──────┬───────┐
│ a │ b │ c │ d │
╞═════╪═════╪══════╪═══════╡
│ cat │ dog │ frog │ mouse │
╞═════╧═════╧══════╧═══════╡
└──────────────────────────┘
EOF
end

it "should not create spurrious vertical intersections for adjacent separators (issue #118.c)" do
@table.add_separator
@table.add_separator
@table.add_row ['x','y','z']
@table.add_separator
@table.add_separator
@table.render.should eq <<-EOF.deindent
┌───────────┐
├───────────┤
├───┬───┬───┤
│ x │ y │ z │
├───┴───┴───┤
├───────────┤
└───────────┘
EOF
end


end
end

0 comments on commit f06ffb4

Please sign in to comment.