A Windows software package providing an interface similar to a Unix pty-master for communicating with Windows console programs.
Go to file
Ryan Prichard d4640890cf Rewrite resize logic, introduce "direct mode", and tweak scroll scraping.
* Unfreeze the console while changing the buffer size.  Changing the
   buffer size hangs conhost.exe.  See:
    - https://github.com/rprichard/winpty/issues/31
    - https://wpdev.uservoice.com/forums/266908-command-prompt/suggestions/9941292-conhost-exe-hangs-in-win10-if-setconsolescreenbuff

 * Detect buffer size changes and switch to a "direct mode".  Direct mode
   makes no attempt to track incremental console changes.  Instead, the
   content of the current console window is printed.  This mode is
   intended for full-screen apps that resize the console.

 * Reopen CONOUT$, which detects apps that change the active screen buffer.
   Fixes https://github.com/rprichard/winpty/issues/34.

 * In the scroll scraping (scrollingScrapeOutput), consider a line changed
   if the new content is truncated relative to the content previously
   output.  Previously, we only compared against the line-buffer up to the
   current console width.  e.g.

   If this:
      |C:\Program|

   turns into:
      |C:\Prog|
      |ram    |

   we previously left |C:\Program| in the line-buffer for the first line
   and did not re-output the first line.

   We *should* reoutput the first line at this point so that, if the line
   scrolls upward, and the terminal is later expanded, we will have
   output an "Erase in Line" CSI command to clear the obscured "ram" text.

   We need to update the line-buffer for the sake of Windows 10 combined
   with terminals like xterm and putty.  On such a terminal, if the
   terminal later widened, Windows 10 will restore the console to the
   first state.  At that point, we need to reoutput the line, because
   xterm and putty do not save and restore truncated line content extending
   past the current terminal width.
2015-09-29 02:32:49 -05:00
agent Rewrite resize logic, introduce "direct mode", and tweak scroll scraping. 2015-09-29 02:32:49 -05:00
build Replace build/.placeholder with build/.gitkeep. 2012-03-23 03:48:40 -07:00
include Add support for a non-terminal console mode 2013-12-06 15:32:23 +01:00
libwinpty Allow winpty to function with a visible console. 2015-08-23 23:13:20 -05:00
misc Rewrite resize logic, introduce "direct mode", and tweak scroll scraping. 2015-09-29 02:32:49 -05:00
shared Allow winpty to function with a visible console. 2015-08-23 23:13:20 -05:00
tests Fix trivial_test 2015-08-23 23:13:20 -05:00
unix-adapter Set the appropriate locale 2015-09-23 15:39:41 +00:00
.gitattributes Create a configure script. 2012-03-25 15:55:03 -07:00
.gitignore Add a gyp project that can build winpty-agent and libwinpty.dll with MSVC. 2012-12-20 04:20:09 -08:00
config.mk MSVC compatibility: Remove the {Agent,WinPty}DebugClient.cc hack. 2012-12-20 04:07:57 -08:00
configure Fix configure for 64-bit Cygwin. 2014-09-01 13:37:26 +08:00
LICENSE Actually say which license this is (MIT) 2013-07-18 10:22:22 +02:00
Makefile Add a test program. 2015-08-23 16:02:23 -07:00
Notes.txt Stop sending trailing whitespace in Terminal::sendLine. 2012-03-28 03:10:37 -07:00
README.rst Remove trailing whitespace. 2014-09-17 14:57:03 -07:00
winpty.gyp Add a gyp project that can build winpty-agent and libwinpty.dll with MSVC. 2012-12-20 04:20:09 -08:00

======
winpty
======

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.

Prerequisites
=============

You need the following to build winpty:

* A Cygwin or MSYS installation
* GNU make
* A MinGW 32-bit g++ toolchain, v4 or later, to build ``winpty.dll`` and
  ``winpty-agent.exe``
* A g++ toolchain targeting Cygwin or MSYS, v3 or later, to build
  ``console.exe``

Winpty requires two g++ toolchains as it is split into two parts. The
binaries winpty.dll and winpty-agent.exe interface with the native Windows
command prompt window so they are compiled with the native MinGW toolchain.
The console.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 acceptable, but the compiler must be v4 or later and produce 32-bit
binaries.

Cygwin packages
---------------

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

* Either ``mingw-gcc-g++`` or ``mingw64-i686-gcc-g++`` (but not
  ``mingw64-x86_64-gcc-g++``)
* ``gcc-g++``

MinGW packages
--------------

The default g++ compiler for MinGW targets native Windows, but the MinGW
project also packages compilers to target the MSYS environment itself. The
required packages are:

* ``mingw32-make``
* ``g++``
* ``msys-dvlpr``


Build
=====

In the project directory, run ``./configure``, then ``make``.

This will produce three binaries:

* ``build/winpty.dll``
* ``build/winpty-agent.exe``
* ``build/console.exe``

Using the Unix adapter
======================

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

    $ build/console.exe c:/Python27/python.exe
    Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 10 + 20
    30
    >>> exit()
    $