prompt-toolkit / prompt-toolkit/python-prompt-toolkit

Codes printed to terminal when using typeahead with FinalTerm sequences

Open
#456 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.6k
Forks
815
PR merge metrics
No merged PRs in 30d

Description

Consider 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).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with examples/finalterm-shell-integration.py and reproduce the issue by adding the shown delay, then entering repeated lines without waiting for the prompt. Trace how prompt_toolkit handles terminal responses during typeahead and compare the leaked escape sequence with the FinalTerm output. Done means repeated input no longer prints the response code while the iTerm2 output-selection behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.