102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/git_ui.rb', line 102
def decide prompt, acts, color = :default
keys = acts.map { |act| act.key } << '?'
prompt = "#{prompt} [#{keys.join('')}]: ".colorize(color)
act = nil
loop {
uncook_stty!
print prompt
$stdout.flush
inp = $stdin.read(1)
print "\n"
if inp == '?'
puts acts.map { |a|
" #{a.key}: #{a.desc}"
}
elsif a = acts.find { |a| inp == a.key }
cook_stty!
return a.block.call
else
puts "No such action: #{inp}"
end
}
end
|