Merge PR #457: Use pywinpty for PTY support on Windows

Authored by shitcoinsherpa. Imports winpty.PtyProcess on Windows instead
of ptyprocess.PtyProcess, and adds platform markers to the [pty] extra
so the correct package is installed automatically.
This commit is contained in:
teknium1 2026-03-09 21:09:56 -07:00
commit 4de5e017f1
2 changed files with 9 additions and 3 deletions

View file

@ -46,7 +46,10 @@ cron = ["croniter"]
slack = ["slack-bolt>=1.18.0", "slack-sdk>=3.27.0"] slack = ["slack-bolt>=1.18.0", "slack-sdk>=3.27.0"]
cli = ["simple-term-menu"] cli = ["simple-term-menu"]
tts-premium = ["elevenlabs"] tts-premium = ["elevenlabs"]
pty = ["ptyprocess>=0.7.0"] pty = [
"ptyprocess>=0.7.0; sys_platform != 'win32'",
"pywinpty>=2.0.0; sys_platform == 'win32'",
]
honcho = ["honcho-ai>=2.0.1"] honcho = ["honcho-ai>=2.0.1"]
mcp = ["mcp>=1.2.0"] mcp = ["mcp>=1.2.0"]
homeassistant = ["aiohttp>=3.9.0"] homeassistant = ["aiohttp>=3.9.0"]

View file

@ -148,11 +148,14 @@ class ProcessRegistry:
if use_pty: if use_pty:
# Try PTY mode for interactive CLI tools # Try PTY mode for interactive CLI tools
try: try:
import ptyprocess if _IS_WINDOWS:
from winpty import PtyProcess as _PtyProcessCls
else:
from ptyprocess import PtyProcess as _PtyProcessCls
user_shell = _find_shell() user_shell = _find_shell()
pty_env = os.environ | (env_vars or {}) pty_env = os.environ | (env_vars or {})
pty_env["PYTHONUNBUFFERED"] = "1" pty_env["PYTHONUNBUFFERED"] = "1"
pty_proc = ptyprocess.PtyProcess.spawn( pty_proc = _PtyProcessCls.spawn(
[user_shell, "-lic", command], [user_shell, "-lic", command],
cwd=session.cwd, cwd=session.cwd,
env=pty_env, env=pty_env,