Psreadline: Blank lines not permitted after operator in specific terminals

Created on 6 Oct 2019  路  6Comments  路  Source: PowerShell/PSReadLine

Enter the following directly into terminal with Enter or Shift+Enter between lines:

5 +

5 -

10

In PowerShell's _default_ terminal, this works perfectly and lines are allowed to be continued.

However, in a VS Code pwsh terminal (not the vscode-powershell Integrated Terminal, just a regular one) _and_ in the new Windows Terminal, a parsing error is reported as soon as the blank line is entered, not allowing any time to add additional input.

This works as expected when executing a stored script file. I suspect this is a bug in PSReadLine, but I suppose it's possible that the bug comes from Windows Terminal _and_ VS Code's terminal, this just seems like the most logical place to start. 馃檪

Environment data

Windows Terminal

PS version: 7.0.0-preview.3
PSReadline version: 2.0.0-beta5
os: 10.0.18362.1 (WinBuild.160101.0800)
PS file version: 7.0.0.0
HostName: ConsoleHost (Windows Terminal)
BufferWidth: 120
BufferHeight: 27

VS Code Terminal

PS version: 7.0.0-preview.4
PSReadline version: 2.0.0-beta5
os: 10.0.18362.1 (WinBuild.160101.0800)
PS file version: 7.0.0.0
HostName: ConsoleHost
BufferWidth: 221
BufferHeight: 16

Steps to reproduce or exception report

  1. Open terminal
  2. Enter aforementioned simple expression with empty lines in between
  3. See error.
Resolution-External

Most helpful comment

This is more or less because the SHIFT + ENTER key binding doesn't play well with winpty/conpty. When you press SHIFT + ENTER, only the ENTER comes across, no SHIFT.

In VSCode you can get around it by adding this to your keybindings.json

{
    "key": "shift+enter",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "\u2665" },
    "when": "terminalFocus",
},

and this to your PowerShell profile:

# Treat the heart emoji like shift+enter when in VSCode.
if ($env:TERM_PROGRAM -eq 'vscode') {
        Set-PSReadLineKeyHandler -Chord "$([char]0x2665)" -Function AddLine
}

Afaik there's nothing PSRL can do about this because all it's getting is ENTER.

All 6 comments

Yeah, this has been very annoying. It also hoses the ability to do multiline pastes. A fix would be very welcome.

Ctrl+Enter does succeed at generating new lines past the cursor in Windows Terminal.

There is a thread on this regarding VS Code, @TylerLeonhardt, I think, was looking in to this.

This is more or less because the SHIFT + ENTER key binding doesn't play well with winpty/conpty. When you press SHIFT + ENTER, only the ENTER comes across, no SHIFT.

In VSCode you can get around it by adding this to your keybindings.json

{
    "key": "shift+enter",
    "command": "workbench.action.terminal.sendSequence",
    "args": { "text": "\u2665" },
    "when": "terminalFocus",
},

and this to your PowerShell profile:

# Treat the heart emoji like shift+enter when in VSCode.
if ($env:TERM_PROGRAM -eq 'vscode') {
        Set-PSReadLineKeyHandler -Chord "$([char]0x2665)" -Function AddLine
}

Afaik there's nothing PSRL can do about this because all it's getting is ENTER.

Interesting... is there anything we can do on Windows Terminal to get something similar?

Not that I can see. It doesn't look like they have a command for that, and looking at the schema for their settings file it seems to only accept a simple command name, no args (so probably a bit of work until they have something like sendSequence).

Thanks @SeeminglyScience for the insights!
@vexx32 I found https://github.com/microsoft/terminal/issues/530 in the Terminal repo.

Was this page helpful?
0 / 5 - 0 ratings