3 class CompletionMode < ScrollMode
6 def initialize list, opts={}
8 @header = opts[:header]
9 @prefix_len = opts[:prefix_len]
11 super :slip_rows => 1, :twiddles => false
15 update_lines unless @lines
20 update_lines unless @lines
24 def roll; if at_bottom? then jump_to_start else page_down end end
29 width = buffer.content_width
30 max_length = @list.max_of { |s| s.length }
31 num_per = [1, buffer.content_width / (max_length + INTERSTITIAL.length)].max
32 @lines = [@header].compact
33 @list.each_with_index do |s, i|
35 @lines << [] if i % num_per == 0
36 if @prefix_len < s.length
37 prefix = s[0 ... @prefix_len]
38 suffix = s[(@prefix_len + 1) .. -1]
39 char = s[@prefix_len].chr
41 @lines.last += [[:none, sprintf("%#{max_length - suffix.length - 1}s", prefix)],
42 [:completion_character_color, char],
43 [:none, suffix + INTERSTITIAL]]
45 @lines.last += [[:none, sprintf("%#{max_length}s#{INTERSTITIAL}", s)]]
48 @lines << "" if i % num_per == 0
49 @lines.last += sprintf "%#{max_length}s#{INTERSTITIAL}", s