77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/umu/core/selector.rb', line 77
def (options)
return [] if options.empty?
index = 0
ary = []
while (key = $stdin.getch) != "\C-c"
if key == "\e"
second_key = $stdin.getch
if second_key == '['
key = $stdin.getch
case key
when 'A', 'D'
index -= 1 if index != 0
when 'B', 'C'
index += 1 if index < (options.size - 1)
else
"esc: [#{key}"
end
puts "\e[#{options.size + 1}A"
options.each_with_index do |x, idx|
print pointer(idx == index)
puts checker(ary.include?(idx), x)
end
else
key = "esc: #{second_key}"
end
end
if key == ' '
ary.include?(index) ? ary.delete(index) : (ary << index)
puts "\e[#{options.size + 1}A"
options.each_with_index do |x, idx|
print pointer(idx == index)
puts checker(ary.include?(idx), x)
end
end
next unless key == "\r"
check_items = ary.sort.map { |x| options[x] }
cover(options.size)
return check_items
end
end
|