0

There is one thing I can no longer do on my Mac: Type a bunch of Python in my text editor, launch the Python environment from the command line, and paste a few quick commands into the interpreter. Bracketed paste mode pastes the multi-line block as some kind of highlighted single line:

enter image description here

It doesn't just run, I have to hit enter to send the highlighted text to the interpreter. When I do that, Python doesn't like it:

enter image description here

The weird thing is that this doesn't happen on the command line itself, only in the Python environment. It happens whether I start Python in the Mac Terminal, or XQuartz xterm.

I think the issue is bracketed-paste-mode. I found some tips on disabling it in bash or zsh, but have not found anything for csh/tcsh. printf '\e\[?2004l' or the more standard printf '\033\[?2004l' do not work for me.

The terminal command line itself is not in bracketed-paste-mode. When I launch Python, the Python environment is in bracketed-paste-mode. When I leave the environment, the shell again is not in bracketed-paste-mode. So somehow this mode is triggered only in the Python environment... and I cannot do printf escape codes in this environment.

giardia
  • 141

1 Answers1

1

\e is nonstandard; \033 is standard.

The place to look is not in csh/tcsh, but Python, e.g., Pasting into Python REPL broken in recent brew Python builds (HomeBrew #68193).

According to a comment by Carlo Cabrera, the issue arose from readline 8.1 (e.g., the library developed with bash), who in turn referred to rlwrap prompt disappears w/ readline 8.1 message by Felix C. Stegerman. The suggested workaround is to configure the behavior in .inputrc, e.g.,

echo "set enable-bracketed-paste off" >> ~/.inputrc

Carlo Cabrera mentioned a blog which discusses the topic. There is a more comprehensive viewpoint in the xterm FAQ: Can bracketed-paste solve my problems?, expanded in XTerm – bracketed-paste