Skip to content

Commit

Permalink
Merge pull request #28 from slowbro/master
Browse files Browse the repository at this point in the history
Fix Issue #20
  • Loading branch information
piotrmurach committed Oct 7, 2019
2 parents 83ef4cd + 3106b83 commit dbd1b8c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 5 additions & 1 deletion lib/tty/table/column_constraint.rb
Expand Up @@ -141,7 +141,11 @@ def shrink
ratio = ((natural_width - renderer.width) / column_size.to_f).ceil

widths = (0...column_size).reduce([]) do |lengths, col|
lengths + [renderer.column_widths[col] - ratio]
width = (renderer.column_widths[col] - ratio)
# basically ruby 2.4 Numeric#clamp
width = width < minimum_width ? minimum_width : width
width = width > renderer.width ? renderer.width : width
lengths << width
end
distribute_extra_width(widths)
end
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/renderer/ascii/resizing_spec.rb
Expand Up @@ -99,12 +99,12 @@

it 'resizes each column' do
expect(renderer.render).to eql unindent(<<-EOS)
+---+---+-----+
|h… |h… |head3|
+---+---+-----+
|a… |aa2|aaa… |
|b1 |b2 |b3 |
+---+---+-----+
+----+----+---+
|he… |he… |h… |
+----+----+---+
|aaa1|aa2 |a… |
|b1 |b2 |b3 |
+----+----+---+
EOS
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/renderer/basic/resizing_spec.rb
Expand Up @@ -84,9 +84,9 @@

it 'resizes each column' do
expect(renderer.render).to eql unindent(<<-EOS)
he… he… head3
aaa1 aa2 aaaa
b1 b2 b3
head1 he… head3
aaa1 aa2 aaa
b1 b2 b3
EOS
end
end
Expand Down

0 comments on commit dbd1b8c

Please sign in to comment.