#PowerShell 5 - PSReadLine? behaviour when pasting multi-line code `missing closing '}'`

22 messages · Page 1 of 1 (latest)

remote walrus
#

Hello,

I have a weird issue I do not know how to phrase to get google to answer me how (if at all) to resolve, or why this might even be the case.
I suspect it is probably a PSReadLine behaviour that has been fixed in PS7 as it does not occur there.

Trying to paste multi-line code for a class (or a function), powershell is trying to execute this line-by-line instead of as a full block.
Copying and pasting, starting a PS5 session (no profile, to exclude influence of oh-my-posh prompt)

in PS7 I get:

PS C:\Users\David> class ClassName
>> {
>> [string] $ParameterName
>>
>> [string] $Parameter2
>>
>> }
PS C:\Users\David>

in PS5 I get:

PS C:\WINDOWS\System32> class ClassName
>> {
>> [string] $ParameterName
>>
At line:3 char:1
+ [string] $ParameterName
+ ~~~~~~~~~~~~~~~~~~~~~~~
Missing closing '}' in statement block or type definition.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingEndCurlyBrace

PS C:\WINDOWS\System32> [string] $Parameter2

PS C:\WINDOWS\System32>
PS C:\WINDOWS\System32> }
At line:1 char:1
+ }
+ ~
Unexpected token '}' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

PS C:\WINDOWS\System32>

Can anyone tell me what this behaviour is called, and whether I can configure PS5 to behave the same as PS7?

Cheers,
David

Edit: PsReadline v2.3.5 (just found 2.3.6 is out)

woven frigate
#

doesnt really answer your question entirely, but I can tell you that it happens because of blank lines

remote walrus
#

it does indeed. 🙂

#

it interprets fine without blank lines, so how would I get the readline key handler to use AddLine instead of AcceptLine for blank lines on input? I found a PasteAsHereString item, but that does not seem to do anything for me...

woven frigate
#

sorry if that was a bit "duh", just didn't see it mentioned specifically and wanted to let you know it wasn't just a you thing 🙂

remote walrus
#

no worries, should have specified. I am trying to run code from a module or just test a class I have just written and I can't reformat this every time I run it, so trying to find a way to get there while still dependent on PS5

woven frigate
#

using windows terminal?

remote walrus
#

VsCode, but testing in Windows Terminal as well

woven frigate
#

i got it to work in win terminal by removing the keybinding for paste in win terminal settings

remote walrus
#

uh-oh, is windows terminal overwriting key handers...?

#

indeed, this works. how peculiar. can I get to these settings in vscode too?

#

hm. so ctrl+v now works in vscode too, but F8 does not...

woven frigate
#

i can't imagine living in a world without F8 in vscode 🙃

remote walrus
#

Run Selection is my main use case here...

woven frigate
#

but yeah i dunno, i just mucked around a bit and figured that out, i dont really know anything about the terminal workings

remote walrus
#

you brought me one step closer, thank you 🙂

#

at least I can copy/paste safely now

#

Further difference in Windows Termainal is CTRL+v (now works) VS right click for paste.. (which does not...)

#

odd

woven frigate
#

yeah presumably because rclick still being handled by WT and not psreadline

random cloud
#

right. sometimes the problem is the terminal or editor has a ctrl+v keybinding ( which is taking priority over psreadline )
If you remove it, then PSReadLine should correctly read it