Fix choose method

This commit is contained in:
Faik Uygur
2008-11-06 11:25:18 +00:00
parent f436bea87e
commit 8c364e206a
+7 -10
View File
@@ -94,17 +94,14 @@ class CLI(pisi.ui.UI):
self.output(pisi.util.colorize(msg + '\n', 'green')) self.output(pisi.util.colorize(msg + '\n', 'green'))
def choose(self, msg, opts): def choose(self, msg, opts):
print msg msg = unicode(msg)
for i in range(0,len(opts)): import re
print i + 1, opts(i) prompt = msg + pisi.util.colorize(_(' (%s)' % "/".join(opts)), 'red')
while True: while True:
s = raw_input(msg + pisi.util.colorize('1-%d' % len(opts), 'red')) s = raw_input(prompt.encode('utf-8'))
try: for opt in opts:
opt = int(s) if opt.startswith(s):
if 1 <= opt and opt <= len(opts): return opt
return opts(opt-1)
except Exception:
pass
def confirm(self, msg): def confirm(self, msg):
msg = unicode(msg) msg = unicode(msg)