-
Hey, I've used some custom function shortcuts with PSReadLine for quite a while now and so far they have all work as expected, [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
[Microsoft.PowerShell.PSConsoleReadLine]::Insert('<some command here>')
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() and so on, you basically get the gist. But I noticed that when I do something like this: $Example = @{
Chord = 'F8'
BriefDescription = '....'
LongDescription = '....'
ScriptBlock = {
# Same happening for using [Console]::Write() etc.
Write-Host 'This is not yet implemented !'
}
}
Set-PSReadLineKeyHandler @Example the scriptblock is run as expected, but not entirely because (I assume) of how the buffer is handled by PSReadLine? Better to show than to describe, I think: pwsh_JqJ7QTEN8G.mp4As you can see, the output appears as expected, but the cursor position is still on the initial line... (I also tried including I'm aware of Do I have to keep track of cursor positioning manually somehow, or is there are more straightforward way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Okay, so I decided to try to experiment with this a bit again, and I think I understand now what I was missing before... While running my test function, trying to always follow along the output of
🙄 I simply had to put |
Beta Was this translation helpful? Give feedback.
Okay, so I decided to try to experiment with this a bit again, and I think I understand now what I was missing before...
While running my test function, trying to always follow along the output of
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState()
, I had a test loop and ended up callingInvokePrompt()
again, it suddenly hit me.InvokePrompt()
was working as intended the entire time. It was simply "replacing" the already existing prompt continuously, due to how the scriptblock works for Set-PSReadLineKeyHandler, I mean, it's actually obvious..🙄
I simply had to put
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
at the end of my scriptblock for my little demo function above,…