Skip to content

Control buffer/writing output from a PSReadLine keyhandler function? #3509

Answered by Hrxn
Hrxn asked this question in Q&A
Discussion options

You must be logged in to vote

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 calling InvokePrompt() 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,…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Hrxn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant