--- bin/apport-cli 2016-03-31 08:13:38.000000000 -0600
+++ bin/apport-cli.new 2017-10-10 12:54:03.561619739 -0600
@@ -34,7 +34,7 @@
self.buttons = []
self.visible = False
- def raw_input_char(self, prompt):
+ def raw_input_char(self, prompt, char_count=1):
'''raw_input, but read only one character'''
sys.stdout.write(prompt)
@@ -50,7 +50,7 @@
termios.tcsetattr(file, termios.TCSANOW, attributes)
try:
- ch = str(sys.stdin.read(1))
+ ch = str(sys.stdin.read(char_count))
finally:
termios.tcsetattr(file, termios.TCSANOW, saved_attributes)
@@ -82,9 +82,19 @@
for index, button in enumerate(self.buttons):
print(' %s: %s' % (self.keys[index], button))
- response = self.raw_input_char(_('Please choose (%s):') % ('/'.join(self.keys)))
+ char_count = 1
+ if len(self.keys) > 10: # we need two characters
+ char_count = 2
+ if len(self.keys) > 50: # Usability concerns
+ raise RuntimeError(
+ "Too many choices provided to the user (%s)"
+ % '/'.join(self.keys))
+ response = self.raw_input_char(
+ _('Please choose (%s):') % ('/'.join(self.keys)),
+ char_count=char_count).strip()
+ import pdb; pdb.set_trace()
try:
- return self.keys.index(response[0].upper()) + 1
+ return self.keys.index(response.upper()) + 1
except ValueError:
pass
except KeyboardInterrupt:
@@ -143,15 +153,15 @@
hasattr(self.report[key], 'isspace') and \
not self.report._is_binary(self.report[key]) and \
keylen < max_show:
- l = self.report[key]
+ s = self.report[key]
elif keylen >= max_show:
- l = _('(%i bytes)') % keylen
+ s = _('(%i bytes)') % keylen
else:
- l = _('(binary data)')
+ s = _('(binary data)')
- if isinstance(l, bytes):
- l = l.decode('UTF-8', errors='ignore')
- details += l
+ if isinstance(s, bytes):
+ s = s.decode('UTF-8', errors='ignore')
+ details += s
details += '\n\n'
return details
@@ -365,6 +375,7 @@
subprocess.call(command, shell=True)
+
if __name__ == '__main__':
app = CLIUserInterface()
if not app.run_argv():