prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.37k stars 716 forks source link

messy code is displayed with prompt occasionally #496

Open nanaal opened 7 years ago

nanaal commented 7 years ago

jonathanslenders,

When I run prompt with below format, messy code will be displayed occasionally as below. I am not sure whether it is a bug of python-prompt-toolkit. Can you help to have a look? Thanks a lot in advance.

Nana

^[[35;1R file size limit(MB): 50 ^[[70;1R has release extension: N ^[[70;1R node name: CGF01

`class EmailValidator(Validator): self.func = None def validate(self, document): if len(document.text) > 0 and document.text[-1] == "!": return if self.func == None: return tmp_val = self.func(document.text) if len(tmp_val): raise ValidationError(message=tmp_val, cursor_position=len(document.text))

for key, val in self.setMap.items(): validator = EmailValidator(); validator.func = val text = prompt(' %s: ' %key, default='%s' %str(self.getMap[key]()), validator=validator) if len(text) > 0 and text[-1] == "!": return True `

jonathanslenders commented 7 years ago

Hi @nanaal,

This is a cursor-position-response that should have been processed, but was printed instead. Can you please tell me which operating system and terminal application you are using?

Thanks, Jonathan

nanaal commented 7 years ago

Hi @jonathanslenders ,

Below are the info of operating system and terminal application. Please help to have a check. Thanks a lot.

Nana

[root@yywcdr-1 ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.2 (Maipo) [root@yywcdr-1 ~]# echo $TERM xterm

atherra commented 7 years ago

I can also reproduce this fairly easily by triggering fast prompt redraws by mashing Enter on the prompt or when printing a large set of tabulated data.

root@fsrv02:/root>

root@fsrv02:/root>

root@fsrv02:/root>

^[[53;1R
root@fsrv02:/root>

Disabling cooked mode (https://github.com/jonathanslenders/python-prompt-toolkit/pull/487) doesn't seem to change anything for me.

Testing https://github.com/jonathanslenders/python-prompt-toolkit/pull/339/files, I no longer see CPRs. I do, however, see seemingly random newlines between prompts (stdout proxying is on):

root@fsrv02:/root>
root@fsrv02:/root>
root@fsrv02:/root>

root@fsrv02:/root>

root@fsrv02:/root>

root@fsrv02:/root>

root@fsrv02:/root>
asmeurer commented 7 years ago

Same issue as https://github.com/jonathanslenders/python-prompt-toolkit/issues/456. I'll need to check if that PR fixes it.

asmeurer commented 7 years ago

I tested the branch (it's old, so you probably have to merge with master) and it doesn't fix the problem for me. Also sometimes it prints the first prompt twice.

atherra commented 7 years ago

Re. https://github.com/jonathanslenders/python-prompt-toolkit/pull/339/files I tested it by cherry-picking to master.

jonathanslenders commented 7 years ago

Hi everyone, could you test whether this issue still happens on the 2.0 branch? (Possibly you'll have to make a few small changes for using 2.0.) If that's still the case, it would be much easier to fix it there. Thanks!

asmeurer commented 7 years ago

I modified my patch in https://github.com/jonathanslenders/python-prompt-toolkit/issues/456 to work in 2.0, and it reproduced there.