mirror of
https://github.com/openSUSE/osc.git
synced 2025-08-22 14:38:53 +02:00
Added readline support to cmdln-module.
This was already fixed in the original module: https://github.com/trentm/cmdln/issues/1 Signed-off-by: Florian Bergmann <fbergmann@suse.de>
This commit is contained in:
96
osc/cmdln.py
96
osc/cmdln.py
@@ -393,47 +393,63 @@ class RawCmdln(cmd.Cmd):
|
|||||||
"""
|
"""
|
||||||
self.cmdlooping = True
|
self.cmdlooping = True
|
||||||
self.preloop()
|
self.preloop()
|
||||||
if intro is None:
|
if self.use_rawinput and self.completekey:
|
||||||
intro = self.intro
|
|
||||||
if intro:
|
|
||||||
intro_str = self._str(intro)
|
|
||||||
self.stdout.write(intro_str+'\n')
|
|
||||||
self.stop = False
|
|
||||||
retval = None
|
|
||||||
while not self.stop:
|
|
||||||
if self.cmdqueue:
|
|
||||||
argv = self.cmdqueue.pop(0)
|
|
||||||
assert isinstance(argv, (list, tuple)), \
|
|
||||||
"item on 'cmdqueue' is not a sequence: %r" % argv
|
|
||||||
else:
|
|
||||||
if self.use_rawinput:
|
|
||||||
try:
|
|
||||||
try:
|
|
||||||
#python 2.x
|
|
||||||
line = raw_input(self._prompt_str)
|
|
||||||
except NameError:
|
|
||||||
line = input(self._prompt_str)
|
|
||||||
except EOFError:
|
|
||||||
line = 'EOF'
|
|
||||||
else:
|
|
||||||
self.stdout.write(self._prompt_str)
|
|
||||||
self.stdout.flush()
|
|
||||||
line = self.stdin.readline()
|
|
||||||
if not len(line):
|
|
||||||
line = 'EOF'
|
|
||||||
else:
|
|
||||||
line = line[:-1] # chop '\n'
|
|
||||||
argv = line2argv(line)
|
|
||||||
try:
|
try:
|
||||||
argv = self.precmd(argv)
|
import readline
|
||||||
retval = self.onecmd(argv)
|
self.old_completer = readline.get_completer()
|
||||||
self.postcmd(argv)
|
readline.set_completer(self.complete)
|
||||||
except:
|
readline.parse_and_bind(self.completekey+": complete")
|
||||||
if not self.cmdexc(argv):
|
except ImportError:
|
||||||
raise
|
pass
|
||||||
retval = 1
|
try:
|
||||||
self.lastretval = retval
|
if intro is None:
|
||||||
self.postloop()
|
intro = self.intro
|
||||||
|
if intro:
|
||||||
|
intro_str = self._str(intro)
|
||||||
|
self.stdout.write(intro_str+'\n')
|
||||||
|
self.stop = False
|
||||||
|
retval = None
|
||||||
|
while not self.stop:
|
||||||
|
if self.cmdqueue:
|
||||||
|
argv = self.cmdqueue.pop(0)
|
||||||
|
assert isinstance(argv, (list, tuple)), \
|
||||||
|
"item on 'cmdqueue' is not a sequence: %r" % argv
|
||||||
|
else:
|
||||||
|
if self.use_rawinput:
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
#python 2.x
|
||||||
|
line = raw_input(self._prompt_str)
|
||||||
|
except NameError:
|
||||||
|
line = input(self._prompt_str)
|
||||||
|
except EOFError:
|
||||||
|
line = 'EOF'
|
||||||
|
else:
|
||||||
|
self.stdout.write(self._prompt_str)
|
||||||
|
self.stdout.flush()
|
||||||
|
line = self.stdin.readline()
|
||||||
|
if not len(line):
|
||||||
|
line = 'EOF'
|
||||||
|
else:
|
||||||
|
line = line[:-1] # chop '\n'
|
||||||
|
argv = line2argv(line)
|
||||||
|
try:
|
||||||
|
argv = self.precmd(argv)
|
||||||
|
retval = self.onecmd(argv)
|
||||||
|
self.postcmd(argv)
|
||||||
|
except:
|
||||||
|
if not self.cmdexc(argv):
|
||||||
|
raise
|
||||||
|
retval = 1
|
||||||
|
self.lastretval = retval
|
||||||
|
self.postloop()
|
||||||
|
finally:
|
||||||
|
if self.use_rawinput and self.completekey:
|
||||||
|
try:
|
||||||
|
import readline
|
||||||
|
readline.set_completer(self.old_completer)
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
self.cmdlooping = False
|
self.cmdlooping = False
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user