Attributes
Read
No documentation available
Class Methods
::
lib/reline/line_editor.rb
View on GitHub
# File tmp/rubies/ruby-master/lib/reline/line_editor.rb, line 53
def initialize(list)
@list = list
end
No documentation available
Instance Methods
lib/reline/line_editor.rb
View on GitHub
# File tmp/rubies/ruby-master/lib/reline/line_editor.rb, line 57
def lines(screen_width)
return [] if @list.empty?
list = @list.sort
sizes = list.map { |item| Reline::Unicode.calculate_width(item) }
item_width = sizes.max + 2
num_cols = [screen_width / item_width, 1].max
num_rows = list.size.fdiv(num_cols).ceil
list_with_padding = list.zip(sizes).map { |item, size| item + ' ' * (item_width - size) }
aligned = (list_with_padding + [nil] * (num_rows * num_cols - list_with_padding.size)).each_slice(num_rows).to_a.transpose
aligned.map do |row|
row.join.rstrip
end
end
No documentation available