Commit Graph

476 Commits

Author SHA1 Message Date
Ryan Prichard
ebefb91e80 Update test programs for font/resizing work
* Rename QueryFont.exe to GetFont.exe -- it's shorted.  Make font table
   output shorter.  Make the program work on XP.

 * Add IsNewConsole.exe

 * Add GetBufferInfo.exe

 * Clear the executable bit on some .cc files
2016-06-04 21:10:19 -05:00
Ryan Prichard
d0ae4cbb28 Add a missing header include to OsModule.h 2016-06-04 21:07:12 -05:00
Ryan Prichard
52abfbb908 Add misc/MoveConsoleWindow test program 2016-06-04 02:48:11 -05:00
Ryan Prichard
3854d04282 Add misc/SetBufferSize.exe and misc/SetWindowRect.exe test programs 2016-06-04 02:35:03 -05:00
Ryan Prichard
0f6de50111 Get a bunch of misc test programs compiling again 2016-06-03 22:17:37 -05:00
Ryan Prichard
71405ba1d4 Revert the requirement that pipes have been opened by winpty_spawn time.
The immediate problem is that the implementation has a race condition.  We
service the control pipe before the other pipes, so we can see the
winpty_spawn RPC request before noticing that the I/O pipes are connected.
(This situation actually happened and caused a pty4j test to fail.)

There are a few ways to fix this problem, such as by adding special calls
to service the I/O pipes in handleStartProcessPacket.

It occurred to me, though, that ensuring that pipes are connected before
calling winpty_spawn might be difficult in some environments that provide
high-level I/O systems.  I'm specifically thinking of nodejs/libuv, where,
IIRC, it was difficult to guarantee that the CreateFile API would be called
synchronously.

It turns out to be easy to relax the restriction, anyway, so just do that.

I also think that CONIN and CONOUT/CONERR are sufficiently different that
perhaps CONIN should have been exempted.
2016-06-02 01:52:46 -05:00
Ryan Prichard
139a4dfe53 Add WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN to guard against leaking agents 2016-06-02 00:52:59 -05:00
Ryan Prichard
e0cbe70600 Add a script specifically for building pty4j's libpty hierarchy. 2016-06-01 23:31:48 -05:00
Ryan Prichard
7c9a7c8745 Factor some code out of make_msvc_package.py into a simpler vcbuild.bat 2016-06-01 23:09:36 -05:00
Ryan Prichard
ce5c95cd4f make_msvc_package.py: clear the "-dev" version suffix
With MSVC, converting an empty macro value with STRINGIFY doesn't seem to
work.  (Maybe it's producing nothing rather than the blank literal, ""?)
Work around it by allowing __none__ as a substitute for blank.
2016-06-01 21:42:36 -05:00
Ryan Prichard
4130c88619 Also build for 64-bit XP.
I verified that the normal binaries did not work on a Windows Server 2003
R2 64-bit VM from AWS EC2.
2016-06-01 20:42:49 -05:00
Ryan Prichard
3539b806e9 Build/package winpty for embedding using gyp and MSVC 2016-06-01 20:01:37 -05:00
Ryan Prichard
bd58e14b17 Check in a forgotten file: misc/EnableExtendedFlags.txt 2016-06-01 19:48:11 -05:00
Ryan Prichard
24a1548ab7 Fix trivial test: open the CONIN pipe too
Also: close the I/O handles
2016-06-01 17:57:39 -05:00
Ryan Prichard
f9046dac82 Remove the redundant "-data" from the I/O pipe names
e.g. replace

\\.\pipe\winpty-data-conin-7752-1-1d1bbc851f1b21e-03b22efd16c217582b421ec555292c69

with

\\.\pipe\winpty-conin-7752-1-1d1bbc851f1b21e-03b22efd16c217582b421ec555292c69
2016-06-01 00:43:21 -05:00
Ryan Prichard
8e4810c5e1 Require that all I/O pipes are connected before calling winpty_spawn. 2016-06-01 00:40:35 -05:00
Ryan Prichard
a6fa61c17d Zero-initialize the EXPLICIT_ACCESSW objects.
This may have fixed a segfault in winpty_open.

Fixes https://github.com/rprichard/winpty/issues/80
2016-05-31 19:34:57 -05:00
Ryan Prichard
87436ca8ae Improvement to the ship/ship.py script
* Reorder ship targets to prefer MSYS, then MSYS2, then Cygwin

   The MSYS build is much more likely to fail, both because its Cygwin
   environment is poor (e.g. no C++11, no std::wstring) and because its
   MinGW environment is poor (e.g. missing/broken SDDL APIs)

 * Use PowerShell instead of the pefile module, because it's much faster,
   even with the extra overhead of starting PowerShell.

 * For MSYS, instead of disabling parallel make, use mingw32-make.exe.
   Apparently, with this change, it's necessary to use forward slashes when
   passing the PREFIX to make, so change that as well.
2016-05-30 15:09:28 -05:00
Ryan Prichard
bfa441f30c Only activate the terminal's mouse mode if ENABLE_EXTENDED_FLAGS is set
Previously, starting any Cygwin program (e.g. bash.exe, python2.7.exe)
would activate the terminal's mouse mode.

Move the ENABLE_EXTENDED_FLAGS note into a separate file.
2016-05-30 05:43:56 -05:00
Ryan Prichard
5974ed1895 Disable QuickEdit mode with WINPTY_MOUSE_MODE_NONE
There's really no reason to leave the mode ON, and disabling it makes
it easier to make mouse input work.  WINPTY_MOUSE_MODE_NONE doesn't mean,
"stop mouse input"; it means, "the agent will not configure your
terminal's mouse output".
2016-05-30 05:00:15 -05:00
Ryan Prichard
4815d6f9f2 Add a missing header to BackgroundDesktop.cc 2016-05-30 04:19:40 -05:00
Ryan Prichard
e60ef0101a Change the default way winpty enters the terminal's mouse mode.
By default, winpty now puts a new console into QuickEdit mode.  If the
agents detects that the console has disabled QuickEdit and enabled
ENABLE_MOUSE_INPUT, then it puts the terminal into mouse mode.

This convention doesn't work with all Windows programs -- it does work
with Far Manager and "winpty-agent.exe --show-input --with-mouse".  The
practice is described in one of Raymond Chen's posts[1].

For other programs, winpty.exe still has a --mouse option, and I wrote a
script in misc/ConinMode.ps1 that controls the QuickEdit (and InsertMode)
flags from the command-line, which is useful, because the console
properties dialog is inaccessible from within winpty.

[1] https://blogs.msdn.microsoft.com/oldnewthing/20130506-00/?p=4453
2016-05-30 04:10:49 -05:00
Ryan Prichard
cf39c31ff6 Create a PowerShell script for controlling the console input mode. 2016-05-30 02:18:13 -05:00
Ryan Prichard
8015db36e0 Implement a special agent invocation for creating background desktops
Calling SetProcessWindowStation in winpty_open isn't thread-safe -- another
thread may be doing something with the window station.  The call also
appears to interfere with the clipboard, which has affected IntelliJ.

A previous commit disabled the use of the background desktop for Windows 7
and up, where it seems unnecessary.  This commit fixes the issue for XP
and Vista by spawning the agent twice in winpty_open:
 1. winpty_open first spawns an agent with no attached console, which
    creates the background desktop and sends its name back on the control
    pipe.
 2. Then it spawns the primary agent invocation as usual.
 3. Once the primary agent's control pipe is connected, winty_open allows
    the first agent to exit.

Fixes https://github.com/rprichard/winpty/issues/58
2016-05-29 00:20:03 -05:00
Ryan Prichard
75ad04155f Fix PendingIo: CancelIo should be passed the HANDLE, not the OVERLAPPED 2016-05-28 22:18:13 -05:00
Ryan Prichard
982e8051a5 Reduce redundant terminal output and make plain+color flags work 2016-05-27 21:36:08 -05:00
Ryan Prichard
d1b9522444 Get misc/SetCursorPos.exe compiling again 2016-05-27 20:19:49 -05:00
Ryan Prichard
d4856b26a8 Fix memory unsafety bug 2016-05-27 02:19:15 -05:00
Ryan Prichard
222ecb9f44 Add undocumented -X<flag> switches to winpty.exe for testing
-Xallow-non-tty:    allow stdin/stdout to not be ttys
-Xconerr:           test the new CONERR mode (connect it to STDERR_FILENO)
-Xplain:            enter plain, unescaped, mode
-Xcolor:            force generation of color escapes, even with -Xplain

Also: with "winpty.exe --showkey", stop trying to put stdout into raw
terminal mode, and ignore whether it is a tty.
2016-05-26 21:34:20 -05:00
Ryan Prichard
5b57d37bdc Simplify the API: remove error params from 2 winpty_config_set_XXX setters 2016-05-26 21:29:11 -05:00
Ryan Prichard
ccb11afd62 Split out Scraper class from Agent; add a "CONERR" mode
If the WINPTY_FLAG_CONERR flag is specified when starting the agent, the
agent creates a separate, inactive console buffer to use for collecting
error output.  The buffer is passed to children using
STARTUPINFO.hStdError.  The agent scrapes from both the initial STDOUT
screen buffer and the new error buffer using two Scraper objects, two
Terminal objects, and two NamedPipe objects.

Clients connect to the CONERR pipe just as they would connect to the CONOUT
pipe.  There is a winpty_conerr_name function for querying the CONERR
pipe's name.

Console frozenness is a property of the entire console, rather than a
screen buffer, so it is consolidated into the Win32Console class.  During a
typical output poll, the console is frozen, then both buffers are scraped,
then the console is unfrozen.

Related: previously CONOUT$ was reopening at each poll timeout.  Now, the
buffer is only open for the duration is is needed.  (i.e. It is closed at
the end of the resizing/scraping operation.)  This new behavior might be
more correct in scenarios where programs change the active screen buffer.
If a program activates its own screen buffer, then exits, the screen buffer
is destroyed because no program references it.  When it is destroyed, a
different buffer is activated.  By opening CONOUT$, winpty can accidentally
prevent a screen buffer from being destroyed, at least temporarily.
2016-05-26 21:26:58 -05:00
Ryan Prichard
f453c9ca1d Remove wstringToUtf8String; it's redundant with utf8FromWide. 2016-05-26 20:56:03 -05:00
Ryan Prichard
265fc67ff0 Split Win32Console into Win32Console and Win32ConsoleBuffer 2016-05-26 20:56:02 -05:00
Ryan Prichard
6a253ee5a8 Factor some input handling out of Agent/Win32Console into ConsoleInput 2016-05-26 20:56:02 -05:00
Ryan Prichard
ab26c8b0d0 Remove some dead code 2016-05-26 20:56:01 -05:00
Ryan Prichard
880c00c69e Replace the libwinpty API.
The new API improves upon the old API in a number of ways:

 * The old API provided a single data pipe for input and output, and it
   provided the pipe in the form of a HANDLE opened with
   FILE_FLAG_OVERLAPPED.  Using a bare HANDLE is difficult in higher-level
   languages, and overlapped/asynchronous I/O is hard to get right.
   winpty_close closed the data pipe, which also didn't help things, though
   I think the handle could have been duplicated.

   Using a single handle for input and output complicates shutdown.  When
   the child process exits, the agent scrapes the final output, then closes
   the data pipe once its written.  It's possible that a winpty client will
   first detect the closed pipe when it's writing *input* rather than
   reading output, which seems wrong.  (On the other hand, the agent
   doesn't implement "backpressure" for either input or output (yet), and
   if it did, it's possible that post-exit shutdown should interrupt a
   blocked write into the console input queue.  I need to think about it
   more.)

   The new API splits the data pipe into CONIN and CONOUT pipes, which are
   accessed by filename.  After `winpty_open` returns, the client queries
   pipe names using `winpty_conin_name` and `winpty_conout_name`, then
   opens them using any mechanism, low-level or high-level, blocking or
   overlapped.

 * The old libwinpty handled errors by killing the process.  The new
   libwinpty uses C++ exceptions internally and translates exceptions at
   API boundaries using:

    - a boolean error result (e.g. BOOL, NULL-vs-non-NULL)
    - a potentially heap-allocated winpty_error_t object returned via an
      optional winpty_error_ptr_t parameter.  That parameter can be NULL.
      If it isn't, then an error code and message can be queried from the
      error object.  The winpty_error_t object must be freed with
      winpty_error_free.

 * winpty_start_process is renamed to winpty_spawn.  winpty_open and
   winpty_spawn accept a "config" object which holds parameters.  New
   configuration options can be added without disturbing the source or
   binary API.

 * The winpty_get_exit_code and winpty_get_process_id APIs are removed.
   The winpty_spawn function has an out parameter providing the child's
   process and thread HANDLEs (duplicated from the agent via
   DuplicateHandle).  The winpty client can call GetExitCodeProcess and
   GetProcessId (as well as the WaitForXXX APIs to wait for child exit).
2016-05-26 20:56:01 -05:00
Ryan Prichard
5e9325f7b2 Stylistic changes in agent: s/socket/pipe/, use C++11 language features 2016-05-25 17:50:45 -05:00
Ryan Prichard
215885fc44 Split out libwinpty/AgentLocation.cc from libwinpty/winpty.cc 2016-05-25 17:50:45 -05:00
Ryan Prichard
6d9dda19af Harmonize use of ASSERT over assert in libwinpty 2016-05-25 17:50:44 -05:00
Ryan Prichard
3f42e83207 Ensure that the agent aborts if the console window is NULL
It should guard against a recurrence of
https://youtrack.jetbrains.com/issue/IDEA-156228.
2016-05-25 17:50:44 -05:00
Ryan Prichard
21eaf31141 Reduce the likelihood of collision for some src/shared header guards 2016-05-25 17:50:44 -05:00
Ryan Prichard
97c4253cfb Bump the version 2016-05-25 17:50:43 -05:00
Ryan Prichard
ee20ae4731 Update the release notes for 0.3.0 2016-05-20 18:05:59 -05:00
Ryan Prichard
0648342e42 Convert U+001B (ESCAPE) to a '?' when it appears in a screen buffer cell
Fixes https://github.com/rprichard/winpty/issues/47.
2016-05-20 17:49:35 -05:00
Ryan Prichard
de8f7b512a Add a note about using the correct MinGW-w64 shortcut for MSYS2
Fixes https://github.com/rprichard/winpty/issues/75.
2016-05-20 17:18:37 -05:00
Ryan Prichard
b7cfafcbb9 Improve the error message when winpty.exe can't start its child process
Fixes https://github.com/rprichard/winpty/issues/76.
2016-05-20 17:18:37 -05:00
Ryan Prichard
179d1af900 In winpty.exe, clear the TERM environment variable
Fixes https://github.com/rprichard/winpty/issues/43.
2016-05-20 17:18:37 -05:00
Ryan Prichard
671360a539 Change the initial console title to a single space.
Fixes https://github.com/rprichard/winpty/issues/74
2016-04-21 02:30:22 -07:00
Ryan Prichard
5a65fdc11c Use more sensible executable flags for source files
My motivation at the moment is that I'm trying to share a
git checkout between multiple VMs using VirtualBox's Shared
Folders feature.  git in the guest VM isn't able to see the
executable bits from the host due to the VirtualBox/SMB/CIFS
layer.  Instead, it thinks text files are non-executable,
unless they have a shebang line.  That's a sensible way to
set the flags anyway, so set them like that.

With this commit, there's still one file that isn't handled:
src/shared/GetCommitHash.cmd.  It's still marked executable,
but it lacks a shebang line, so the guest thinks it's
non-executable.  I'm not sure it should be changed.
2016-04-20 21:44:44 -07:00
Ryan Prichard
2e661f15fd Add a test case exploring freeze behavior on an inactive console buffer
So far, I've only tested it on Windows 7.  The test passed on that OS:
creating a screen buffer isn't blocked by selection, but writing to an
inactive buffer *is* blocked, regardless of whether the buffer was created
before or after selection began.  The use of Mark or SelectAll doesn't
affect behavior.
2016-04-19 15:00:39 -07:00