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
Thankfully, reproducing this behavior is not a hard task.
Make a simple prompt:
>>> from prompt_toolkit import prompt
>>> prompt("Input: ")
Input:
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.
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 utilizesprompt-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/313Thankfully, reproducing this behavior is not a hard task.
tab char > <
, resulting in: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.