diff options
| author | Kieran Pilkington | 2009-11-14 13:43:07 +1300 |
|---|---|---|
| committer | Max Howell | 2009-12-17 19:19:33 +0000 |
| commit | 85ffad811756779c6edf1a0d020f2c1039559b92 (patch) | |
| tree | 10aa6141b5ac9cba17e3d5e8b5c727c80858bd95 /Library | |
| parent | 1a52c7f8644f0d6871c3c5fabd4bd7c124b3c9d3 (diff) | |
| download | brew-85ffad811756779c6edf1a0d020f2c1039559b92.tar.bz2 | |
Making column amount and width dynamic, adjusting to console size.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/utils.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 404873e60..e2c43c65a 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -104,8 +104,14 @@ def puts_columns items, cols = 4 if $stdout.tty? items = items.join("\n") if items.is_a?(Array) items.concat("\n") unless items.empty? - width=`/bin/stty size`.chomp.split(" ").last - IO.popen("/usr/bin/pr -#{cols} -t", "w"){|io| io.write(items) } + + # determine the best width to display for different console sizes + console_width = `/bin/stty size`.chomp.split(" ").last + longest = items.sort_by { |item| item.length }.last + optimal_col_width = (console_width.to_f / (longest.length + 2).to_f).floor + cols = optimal_col_width > 1 ? optimal_col_width : 1 + + IO.popen("/usr/bin/pr -#{cols} -t -w#{console_width}", "w"){|io| io.write(items) } else puts *items end |
