Check for bad values of console_width

Fixes Homebrew/homebrew#453.
This commit is contained in:
Max Howell 2010-01-16 13:12:38 +00:00
parent 056851463e
commit d1355af66e

View File

@ -123,7 +123,8 @@ def puts_columns items, cols = 4
items.concat("\n") unless items.empty?
# determine the best width to display for different console sizes
console_width = `/bin/stty size`.chomp.split(" ").last
console_width = `/bin/stty size`.chomp.split(" ").last.to_i
console_width = 80 if console_width <= 0
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