lib/highline/menu.rb in highline-2.0.1 vs lib/highline/menu.rb in highline-2.0.2
- old
+ new
@@ -372,13 +372,14 @@
map_items_by_index + map_items_by_name
end
end
def map_items_by_index
- if @index == :letter
- l_index = "`"
- all_items.map { l_index.succ!.dup }
+ if [:letter, :capital_letter].include?(@index)
+ # @ and ` are the previous ASCII characters to A and a respectively
+ prev_char = (@index == :capital_letter ? '@' : '`')
+ all_items.map { prev_char.succ!.dup }
else
(1..all_items.size).map(&:to_s)
end
end
@@ -434,11 +435,11 @@
item = items.find { |i| i.name == selection }
return item if item
# 97 is the "a" letter at ascii table
# Ex: For "a" it will return 0, and for "c" it will return 2
- index = selection.ord - 97
+ index = selection.downcase.ord - 97
items[index]
end
def value_for_selected_item(item, details)
if item.action
@@ -515,11 +516,12 @@
def mark_for_decoration(text, ix)
case @index
when :number
["#{ix + 1}#{@index_suffix}", text]
- when :letter
- ["#{('a'.ord + ix).chr}#{@index_suffix}", text]
+ when :letter, :capital_letter
+ first_letter = (@index == :capital_letter ? 'A' : 'a')
+ ["#{(first_letter.ord + ix).chr}#{@index_suffix}", text]
when :none
[text, ""]
else
["#{index}#{@index_suffix}", text]
end