Permalink
Browse files

Fixed exception when a menu list contains items wider that the terminal

  • Loading branch information...
Mon-Ouie committed Mar 22, 2013
1 parent 6627ce7 commit 5b89492a9a95a096cdf1af5468f84674466e6d52
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/coolline/menu.rb
View
@@ -20,13 +20,18 @@ def initialize(input, output)
# Sets the menu's string to a list of items, formatted in columns.
#
# If some items are to wide to be showed, they will be excluded from the
# list.
#
# @param [Array<String>] items
def list=(items)
height, width = @input.winsize
items = items.reject { |s| ansi_length(s) > width }
if items.empty?
self.string = ""
else
height, width = @input.winsize
col_width = items.map { |s| ansi_length(s) }.max
col_count = width / col_width
item_count = col_count * (height - 1)

0 comments on commit 5b89492

Please sign in to comment.