Codes printed to terminal when using typeahead with FinalTerm sequences
See original GitHub issueConsider the finalterm-shell-integration.py example. Make the following change to it
--- a/examples/finalterm-shell-integration.py
+++ b/examples/finalterm-shell-integration.py
@@ -8,7 +8,7 @@ from __future__ import unicode_literals
from prompt_toolkit import prompt
from prompt_toolkit.token import Token
import sys
-
+import time
BEFORE_PROMPT = '\033]133;A\a'
AFTER_PROMPT = '\033]133;B\a'
@@ -29,8 +29,9 @@ def get_prompt_tokens(cli):
if __name__ == '__main__':
- answer = prompt(get_prompt_tokens=get_prompt_tokens)
-
- sys.stdout.write(BEFORE_OUTPUT)
- print('You said: %s' % answer)
- sys.stdout.write(AFTER_OUTPUT.format(command_status=0))
+ while True:
+ answer = prompt(get_prompt_tokens=get_prompt_tokens)
+ time.sleep(2)
+ sys.stdout.write(BEFORE_OUTPUT)
+ print('You said: %s' % answer)
+ sys.stdout.write(AFTER_OUTPUT.format(command_status=0))
Then run the script and type
hello
hello
hello
hello
several times without waiting for the prompt. Eventually, you’ll see something like this:
Say something: # hello
^[[45;1Rello
You said: hello
The ^[[45;1R
is printed before the output. I don’t understand what that escape code is exactly. It doesn’t look like one of the FinalTerm codes. I believe the final term codes themselves are being printed correctly, as the “select output” feature in iTerm2 works correctly (it selects everything, including the ^[[45;1R
).
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
cursor shape (e.g. for vim mode) · Issue #192 · prompt-toolkit ...
I know the character sequences that change cursor shape for my terminal, ... Codes printed to terminal when using typeahead with FinalTerm sequences...
Read more >The magical command line - Stubbornella
The command line makes poor use of a visual memory (though setting ... So, when I type git m , the magical command...
Read more >Documentation - iTerm2 - macOS Terminal Replacement
To use autocomplete, type the beginning of a word and then press cmd-;. ... If enabled, escape codes that initiate printing will be...
Read more >2_Linux Enviroment and command line
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component ......
Read more >Reference — prompt_toolkit 3.0.36 documentation
This is important on terminals that use vt100 input. We can't distinguish the ... This can be used for instance, for inserting Final...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As far as I can tell this is fixed in 2.0. I think somewhere between the new typeahead code and the better CPR handling it got fixed (I can bisect if you are interested).
I think I figured out the issue with PipeInput specifically (see https://github.com/jonathanslenders/python-prompt-toolkit/issues/610#issuecomment-385522974). Basically the stdout Output class assumes the input can respond to a CPR request, and has no way to know if it is PipeInput. Perhaps PipeInput should get a faked CPR request responder to deal with this? The real problem seems to be the disconnect between Input and Output classes in the code, even though CPR requests and responses inherently link the two (and require they both be a real TTY). At any rate, for now, I’ve come the conclusion that PipeInput should never be used for interactive purposes (only for things like unit tests). I’m still working on translating my code to 2.0 so I can’t say yet if my issues fully exist there.
One thing I couldn’t figure out though is what exactly the CPR responses even do. I commented out the CPR request code, and everything seemed to still act normal in my application. I also noticed that 2.0 has some code to automatically stop sending CPR codes if it notices they are not being responded to. So I’m curious exactly what I should expect to stop working if CPR codes are disabled. And if it’s nothing I care about if I could just disable them myself.
For more info, my
ipython_config.py
consists of:Partly from https://github.com/jonathanslenders/python-prompt-toolkit/issues/192#issuecomment-380654372