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

Tab char `' '`(`\t`) displays as `^I` when pasting into input

Open
#1,868 0 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

In some downstream applications, we want to paste code directly into the input. If a tab character is included in the code, the prompt displays it as ^I.

For a specific instance, when coding in an R script in VSCode, the "vscode-R" extension could send a block of code into the REPL of the Python package radian, which utilizes prompt-toolkit as the IO in the REPL. If the block of code contains tabs, the REPL will display abnormally. https://github.com/randy3k/radian/issues/313

Screenshot

Thankfully, reproducing this behavior is not a hard task.

  1. Make a simple prompt:
>>> from prompt_toolkit import prompt
>>> prompt("Input: ")
Input: 
  1. Paste tab char > <, resulting in:
Input: tab char >^I<

I have tried a solution mentioned in https://github.com/tmbo/questionary/issues/154#issuecomment-905592622, which patches prompt_toolkit.layout.screen .Char.display_mappings['\t'] = '\t', and a solution in Issue #1452, which listens for the tab key to insert spaces. However, it still does not work properly. I also found a workaround mentioned in Issue #556, but it is not suitable in our situation.

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 the documented prompt_toolkit.prompt entry point and reproduce the issue by pasting tab char >\t< into the prompt. Trace the input and display handling that turns the tab into ^I; done means pasted tabs no longer display abnormally in the prompt.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.