Allow accepting the current input automatically from within 'OnIdle' event handler #4830
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
This PR contains changes to allow accepting the current input automatically from within 'OnIdle' event handler. It is used in
AIShell
project to allow an AI agent to run command in the connected PowerShell session with user's permission.It's only supported on Windows, because accepting input without a keystroke would leave the 'readkey thread' blocked on the
_console.ReadKey()
call. On Linux and macOS, that will cause all subsequent writes to console to be blocked on Linux and macOS until a key is pressed.With iTerm2 on macOS, a key can be sent to its tab/pane via its Python API server, so
AIShell
can potentially leverage its Python API to make PowerShell accept a command line input. But on Windows, we have to rely on PSReadLine to support this functionality.Caveat
On Windows, having the 'readkey thread' blocked on the
_console.ReadKey()
call doesn't affect subsequent writes to console. However, it will cause problem if the accept command involves anotherconsole.Readkey()
call -- the first key pressing will be swallowed by the 'readkey thread' in this case.PR Checklist
Microsoft Reviewers: Open in CodeFlow