Getting powershell current line before ENTER is pressed

12

I had an idea to write a visualizer that displays an AST of your PowerShell line as you type it. But to do this, the first step would be to get the text of the current line, before it is submitted (before ENTER is pressed), but I can't find an API function or hook to do this. Does one exist?

I am using PowerShell Core 7.1.0 on the new Windows Terminal.

PredictiveSource

It seems like PSReadLine's PredictiveSource option might be able to be used for this, provided that it can be invoked on every letter entry and not just on TAB, but I can't find any info on the type contract for 3rd-party plugins after digging through both the docs and the the C# code...

Set-PSReadLineKeyHandler

As the legendary @mklement0 has suggested, perhaps Set-PSReadLineKeyHandler could be used. It appears to be intended for keybindings, but I'm still wrapping my head around how it could be used to this purpose.

Share
Improve this question
6
  • 13
    Before voting to close, read meta question: meta.stackoverflow.com/q/407114/14768 – Joshua Apr 26 at 16:43
  • 1
    "Brilliant idea" is six syllables. – khelwood yesterday
  • @khelwood you pronounce "idea" with 3 syllables? – xdhmoore yesterday
  • @xdhmoore I think everyone does. – khelwood yesterday
  • @mklement0 That certainly makes more sense than "idea" being 2 syllables. – khelwood 13 hours ago

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue