A Windows software package providing an interface similar to a Unix pty-master for communicating with Windows console programs.
Go to file
Ryan Prichard 40d5b72c43 Pass certain keys to the console using windows messages.
If the terminal is placed in an alternate mode using DECCKM, then we
need to generate different input escape sequences for WSL (and other
programs using ENABLE_VIRTUAL_TERMINAL_INPUT).  AFAIK, there is no way
for winpty to detect whether an alternate mode is enabled, but it only
seems to affect a small number of keys, so send those keys as window
messages.

We don't send *all* keys as window messages, because the console may try
to interpret some of them.  It doesn't interpret the arrow keys and
Home/End, AFAICT, and those seem to be the only keys affected by DECCKM.
(The console's line-input mode *does* care about these navigation keys,
but in that case, WriteConsoleInput and window messages work equally well.)

DECCKM only seems to affect the keys when there is no modifier key.

I believe that by using SendMessage, winpty-agent will block until the
keys are appended to the console input buffer.  I'm not sure how to verify
it.  If this *weren't* the case, there could be a danger of key input
being transposed.  It seems unlikely to be an issue.

Fixes https://github.com/rprichard/winpty/issues/90
2017-01-15 04:20:05 -06:00
misc Add new test programs: ConinMode, ConoutMode, WriteConsole 2016-08-13 22:12:18 -05:00
ship Minor tweaks in ship/make_msvc_package.py 2016-06-14 05:38:09 -05:00
src Pass certain keys to the console using windows messages. 2017-01-15 04:20:05 -06:00
.drone.yml Continuous Integration: Add build configure for Tea CI. 2016-06-14 11:50:59 +08:00
.gitattributes Factor some code out of make_msvc_package.py into a simpler vcbuild.bat 2016-06-01 23:09:36 -05:00
.gitignore Add a script specifically for building pty4j's libpty hierarchy. 2016-06-01 23:31:48 -05:00
configure Makefile: stop reading environ variables and avoid spawning processes 2016-02-26 04:21:22 -06:00
LICENSE Update the LICENSE copyright year 2016-02-25 21:27:47 -06:00
Makefile Build/package winpty for embedding using gyp and MSVC 2016-06-01 20:01:37 -05:00
README.md Add a tea-ci badge to the README 2016-06-14 00:03:47 -05:00
RELEASES.md Pass certain keys to the console using windows messages. 2017-01-15 04:20:05 -06:00
vcbuild.bat Factor some code out of make_msvc_package.py into a simpler vcbuild.bat 2016-06-01 23:09:36 -05:00
VERSION.txt Bump version to 0.4.2 2017-01-03 23:08:15 -06:00

winpty

Build Status

winpty is a Windows software package providing an interface similar to a Unix pty-master for communicating with Windows console programs. The package consists of a library (libwinpty) and a tool for Cygwin and MSYS for running Windows console programs in a Cygwin/MSYS pty.

The software works by starting the winpty-agent.exe process with a new, hidden console window, which bridges between the console API and terminal input/output escape codes. It polls the hidden console's screen buffer for changes and generates a corresponding stream of output.

The Unix adapter allows running Windows console programs (e.g. CMD, PowerShell, IronPython, etc.) under mintty or Cygwin's sshd with properly-functioning input (e.g. arrow and function keys) and output (e.g. line buffering). The library could be also useful for writing a non-Cygwin SSH server.

Supported Windows versions

winpty runs on Windows XP through Windows 10, including server versions. It can be compiled into either 32-bit or 64-bit binaries.

Cygwin/MSYS adapter (winpty.exe)

Prerequisites

You need the following to build winpty:

  • A Cygwin or MSYS installation
  • GNU make
  • A MinGW g++ toolchain capable of compiling C++11 code to build winpty.dll and winpty-agent.exe
  • A g++ toolchain targeting Cygwin or MSYS to build winpty.exe

Winpty requires two g++ toolchains as it is split into two parts. The winpty.dll and winpty-agent.exe binaries interface with the native Windows command prompt window so they are compiled with the native MinGW toolchain. The winpty.exe binary interfaces with the MSYS/Cygwin terminal so it is compiled with the MSYS/Cygwin toolchain.

MinGW appears to be split into two distributions -- MinGW (creates 32-bit binaries) and MinGW-w64 (creates both 32-bit and 64-bit binaries). Either one is generally acceptable.

Cygwin packages

The default g++ compiler for Cygwin targets Cygwin itself, but Cygwin also packages MinGW-w64 compilers. As of this writing, the necessary packages are:

  • Either mingw64-i686-gcc-g++ or mingw64-x86_64-gcc-g++. Select the appropriate compiler for your CPU architecture.
  • gcc-g++
  • make

As of this writing (2016-01-23), only the MinGW-w64 compiler is acceptable. The MinGW compiler (e.g. from the mingw-gcc-g++ package) is no longer maintained and is too buggy.

MSYS packages

For the original MSYS, use the mingw-get tool (MinGW Installation Manager), and select at least these components:

  • mingw-developer-toolkit
  • mingw32-base
  • mingw32-gcc-g++
  • msys-base
  • msys-system-builder

When running ./configure, make sure that mingw32-g++ is in your PATH. It will be in the C:\MinGW\bin directory.

MSYS2 packages

For MSYS2, use pacman and install at least these packages:

  • msys/gcc
  • mingw32/mingw-w64-i686-gcc or mingw64/mingw-w64-x86_64-gcc. Select the appropriate compiler for your CPU architecture.
  • make

MSYS2 provides three start menu shortcuts for starting MSYS2:

  • MinGW-w64 Win32 Shell
  • MinGW-w64 Win64 Shell
  • MSYS2 Shell

To build winpty, use the MinGW-w64 {Win32,Win64} shortcut of the architecture matching MSYS2. These shortcuts will put the g++ compiler from the {mingw32,mingw64}/mingw-w64-{i686,x86_64}-gcc packages into the PATH.

Alternatively, instead of installing mingw32/mingw-w64-i686-gcc or mingw64/mingw-w64-x86_64-gcc, install the mingw-w64-cross-gcc and mingw-w64-cross-crt-git packages. These packages install cross-compilers into /opt/bin, and then any of the three shortcuts will work.

Building the Unix adapter

In the project directory, run ./configure, then make, then make install. By default, winpty is installed into /usr/local. Pass PREFIX=<path> to make install to override this default.

Using the Unix adapter

To run a Windows console program in mintty or Cygwin sshd, prepend winpty to the command-line:

$ winpty powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\rprichard\proj\winpty> 10 + 20
30
PS C:\rprichard\proj\winpty> exit

Embedding winpty / MSVC compilation

See src/include/winpty.h for the prototypes of functions exported by winpty.dll.

Only the winpty.exe binary uses Cygwin; all the other binaries work without it and can be compiled with either MinGW or MSVC. To compile using MSVC, download gyp and run gyp -I configurations.gypi in the src subdirectory. This will generate a winpty.sln and associated project files. See the src/winpty.gyp and src/configurations.gypi files for notes on dealing with MSVC versions and different architectures.

Compiling winpty with MSVC currently requires MSVC 2013 or newer.

Debugging winpty

winpty comes with a tool for collecting timestamped debugging output. To use it:

  1. Run winpty-debugserver.exe on the same computer as winpty.
  2. Set the WINPTY_DEBUG environment variable to trace for the winpty.exe process and/or the process using libwinpty.dll.

winpty also recognizes a WINPTY_SHOW_CONSOLE environment variable. Set it to 1 to prevent winpty from hiding the console window.

This project is distributed under the MIT license (see the LICENSE file in the project root).

By submitting a pull request for this project, you agree to license your contribution under the MIT license to this project.