Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Allow Pasting Multi-Line Scripts/Functions into the Terminal Window #92021

Closed
gw-bcharboneau opened this issue Mar 4, 2020 · 2 comments · Fixed by #94559
Closed
Assignees
Labels
feature-request Request for new features or functionality terminal Integrated terminal issues verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@gw-bcharboneau
Copy link

OS: Windows 10 build 18362
VSCode: 1.42.1
Powershell: 5.1 and core 7.0.r3

When Pasting a multiline function or script into the terminal window within VSCode it appears to have hard line breaks even though powershell supports code block pasting natively.
for example, if you paste the following function into the terminal within vscode, it will complain that it is missing a closing } since it is not on the end of line 1. however if you paste it into the native powershell console (regardless of version) it handles the line continuation properly.

example function provided will not run in PSCore as it is unable to import the System.Web Assembly. but you can test with any function, the result is the same.

function New-Password {
    Add-Type -AssemblyName 'System.Web'
    $length = 16 ## characters
    $nonAlphaChars = 5
    $pass = [System.Web.Security.Membership]::GeneratePassword($length, $nonAlphaChars)
    return $pass
}
@Tyriar Tyriar added feature-request Request for new features or functionality terminal Integrated terminal issues terminal-conpty Integrated terminal issues related to the ConPTY backend labels Apr 6, 2020
@Tyriar Tyriar added this to the Backlog milestone Apr 6, 2020
@Tyriar Tyriar changed the title Windows: Allow Pasting MultiLine Scripts/Functions into the Terminal Window Windows: Allow Pasting Multi-Line Scripts/Functions into the Terminal Window Apr 6, 2020
@Tyriar
Copy link
Member

Tyriar commented Apr 6, 2020

With help understanding this from @TylerLeonhardt, I got this:

if($true)
{
# asdf
}
else
{
}

From this:

image

To this:

image

Workaround: By unbinding this keybinding (paste into keybindings.json):

{
	"key": "ctrl+v",
	"command": "-workbench.action.terminal.paste",
	"when": "terminalFocus"
}

This happens because PowerShell's PSReadLine handles ctrl+v. Thinking about a way to solve this generically now.

@Tyriar
Copy link
Member

Tyriar commented Apr 6, 2020

Proposal to fix: New built-in keybinding rule like this:

{
	"key": "ctrl+v",
	"command": "-workbench.action.terminal.paste",
	"when": "terminalFocus && !terminalShellType == 'pwsh'"
}

terminalShellType would be of the shape: 'cmd' | 'pwsh' | 'wsl' | 'gitbash' | undefined currently Windows only using the shell detection logic we already have:

public getShellType(executable: string): TerminalShellType {
switch (executable.toLowerCase()) {
case 'cmd.exe':
return WindowsShellType.CommandPrompt;
case 'powershell.exe':
case 'pwsh.exe':
return WindowsShellType.PowerShell;
case 'bash.exe':
return WindowsShellType.GitBash;
case 'wsl.exe':
case 'ubuntu.exe':
case 'ubuntu1804.exe':
case 'kali.exe':
case 'debian.exe':
case 'opensuse-42.exe':
case 'sles-12.exe':
return WindowsShellType.Wsl;
default:
return undefined;
}
}

Tyriar added a commit that referenced this issue Apr 6, 2020
@Tyriar Tyriar removed the terminal-conpty Integrated terminal issues related to the ConPTY backend label Apr 6, 2020
@Tyriar Tyriar modified the milestones: Backlog, April 2020 Apr 14, 2020
@Tyriar Tyriar added the verification-needed Verification of issue is requested label Apr 27, 2020
@roblourens roblourens added the verified Verification succeeded label Apr 29, 2020
@github-actions github-actions bot locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality terminal Integrated terminal issues verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
3 participants