trouble with cmd.Cmd and prompting
Cameron Simpson
cs at zip.com.au
Wed Jan 18 05:49:31 EST 2017
On 04Jan2017 12:20, Cameron Simpson <cs at zip.com.au> wrote:
>I will try to get a minimal example others can run.
Well I've made some time for this, and it seems to be an interaction with my
python3, the "input" builtin, and readline. Cmd.cmdloop behaves fine if I turn
off the .raw_input attribute, and I can reproduce the issue without the cmd
module.
Test code:
import readline
line = input("F> ")
print("gap")
line = input("G> ")
Results on a terminal:
[~]fleet*2> python3 foo.py
F> a
F> gap
n
G> %
[~]fleet*>
That "%" is an artifact of no final newline after the "G> ".
If I comment out the import of readline it looks like this:
G> %
[~]fleet*> python3 foo.py
F> a
gap
G> b
[~]fleet*>
as one would expect. Ignoring my shell prompts, the contents of a typescript
show:
python3 foo.py^M
F> a^M
F> gap^M
b^M
G>
Those "^M"s are carriage returns. I kind of suspect the second "F> " is
readline doing some kind of redraw. I am baffled by the lack of initial "G> "
prompt; that "G> " above appears to be the secondary issue, after I've pressed
return for the "b" line.
This is on a Mac, so I've no strace command to hand. I've also got all manner
of potential special stuff (readline library from MacPorts, etc). I'll keep
stripping stuff back...
Cheers,
Cameron Simpson <cs at zip.com.au>
More information about the Python-list
mailing list