Skip to content

Allow accepting the current input automatically from within 'OnIdle' event handler #4830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented Jul 10, 2025

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 another console.Readkey() call -- the first key pressing will be swallowed by the 'readkey thread' in this case.

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure you've added one or more new tests
  • Make sure you've tested these changes in terminals that PowerShell is commonly used in (i.e. conhost.exe, Windows Terminal, Visual Studio Code Integrated Terminal, etc.)
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed at PowerShell-Docs
      • Doc Issue filed:
Microsoft Reviewers: Open in CodeFlow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant