Commit Graph

63 Commits

Author SHA1 Message Date
Ryan Prichard
a998bcf207 Rewrite the color translation heuristic.
* Use the Bold(1) SGR parameter in only one case -- White-on-Black.

 * Use the 0x9X and 0x10X SGR parameters to set intense/bright colors for
   both foreground and background.

Detailed changes:

 * DkGray background:
    - Previously, this background was handled identically to the Black
      background.
    - Now it is treated like the non-grayscale colors, and the
      foreground/background are set exactly.

 * Black background:
    - LtGray foreground is unchanged: default text colors
    - White foreground is unchanged: text is bolded
    - DkGray is fixed: instead of concealing the text, set the foreground
      to DkGray, falling back to LtGray.

 * LtGray background:
    - Previously, this background was handled exactly the same way as the
      White background.
    - Now it is treated like any other non-grayscale color.

 * White background:
    - Black foreground is unchanged: only an Invert is output.
    - LtGray: previously, the text was concealed.  Now it is handled like
      Black, and only an Invert is output.
    - DkGray: previously only Invert was output.  Now DkGray is also
      output.
    - White is effectively unchanged; it is still concealed if possible.

Also: set the console colors to LtGray-on-Black on startup.  The
heuristic makes little sense with other colors.

Fixes https://github.com/rprichard/winpty/issues/39
2015-10-13 02:12:59 -05:00
Ryan Prichard
9cf6972860 Fix the Console Popup line-art in Japanese and Korean locales. 2015-10-13 01:05:06 -05:00
Ryan Prichard
cce293dd40 Don't output the second CHAR_INFO of a full-width pair.
The second cell can still have a different color than the first cell, and
*maybe* we want to output it.  I'm unsure.  It could perhaps matter for a
character appearing at the end of a line, but it seems unlikely to matter
in practice.

Fixes https://github.com/rprichard/winpty/issues/41
2015-10-11 23:04:07 -05:00
Ryan Prichard
c3999b5043 Rewrite console font changing.
* Remove the old "Vista" code path in favor of two code paths:
    - setSmallFontVista: sets a TrueType font to match the code page
    - setSmallFontXP: uses SetConsoleFont to activate the smallest
      viable font in the console's font table

 * Selecting a CJK-specific TrueType font is important so that double-width
   characters occupy two cells in the console, which is important for
   maintaining consistency between the console and the Unix terminal.
   (Perfect consistency here might be impossible, but using the appropriate
   font improves things.)  winpty currently duplicates double-width
   characters, but that will be fixed soon.
2015-10-11 04:42:36 -05:00
Ryan Prichard
2ecc596f8b Update winpty to work with MSYS, MSYS2, and Cygwin.
* MSYS is 32-bit only.

 * MSYS2 and Cygwin are either 32-bit or 64-bit.  On 64-bit MSYS2/Cygwin,
   we use the same architecture for all generated binaries.

 * Prefer mingw-w64 to mingw.  mingw-w64 seems to be more up-to-date.
   It is the only option for 64-bit Windows, so stop looking for
   x86_64-pc-mingw32-g++.

 * Also pass -static when linking binaries.  Otherwise, a pthreads DLL
   is linked dynamically.
2015-09-30 03:34:16 -05:00
Ryan Prichard
9da12b25c5 Handle Shift-Tab.
* Fixes https://github.com/rprichard/winpty/issues/19
2015-09-29 05:41:44 -05:00
Ryan Prichard
a0dea2ed4d Comment out ConsoleInput trace lines. 2015-09-29 05:05:19 -05:00
Ryan Prichard
1082c3ded2 Factor out line content tracking into a ConsoleLine class.
* Make line content tracking a little more aggressive about outputting
   lines that were previously truncated.
2015-09-29 04:53:43 -05:00
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
Ryan Prichard
6121265f58 Refactor cursorPosition to use bufferInfo(). 2015-09-24 23:58:30 -07:00
Ryan Prichard
f605aaf4de Factor out a Win32Console::bufferInfo() function.
I don't know if this is necessary, but an atomic accessor function
returning buffer size and window position seems like it could be
convenient.
2015-09-24 23:58:29 -07:00
Ryan Prichard
fb95353703 Improve setSmallConsoleFontVista debug output 2015-09-24 05:43:40 -05:00
Ryan Prichard
bf34a4d8fa Rewrite Win32Console::setSmallFont for better Unicode compatibility.
Try to use a TrueType font rather than a raster font.  The strategy is:
 - [NEW] Try to use 6pt Consolas, then
 - [NEW] Try to use 6pt Lucida Console, then
 - Try to use the smallest font using SetCurrentConsoleFontEx, then
 - Try to use the smallest font using the undocumented SetConsoleFont
   XP API.

When a raster font is active, the console turns most/all non-ASCII
characters into '?' characters.  We need to select a TrueType font to
preserve these characters.
2015-09-24 05:09:40 -05:00
Ryan Prichard
72557cb8c4 Read and write UTF-16, not Ascii. 2015-09-23 17:37:35 -05:00
Ryan Prichard
6591f03d55 Include the sync marker counter in two debugging messages. 2015-08-23 23:13:20 -05:00
Ryan Prichard
947548215d When setting a sync marker, clear the lines containing the marker.
* This behavior is necessary for Windows 10 to ensure that line rewrapping
   does not corrupt the marker.
2015-08-23 23:13:20 -05:00
Christian Howe
fd1e76de5d Include <algorithm> for std::min and std::max 2014-08-07 21:20:16 -04:00
Ryan Prichard
7b878ad2e8 Propagate the console title to the terminal. 2014-05-12 10:53:44 +01:00
Uwe Stieber
c170d6167f Add support for a non-terminal console mode
If a process is running under control of winpty, the output of the process is decorated with ESC sequences to control a terminal to print the process output nicely. In some environments however, the client showing the output to the user is not a full terminal emulation, the Eclipse CDT debug console view in example, and the ESC sequences are printed as output additional to the real process output. This commit is adding an API function to switch into a mode where winpty is not decorating the process output with ESC sequences. The console mode is designated to pass on the process output to the client as is.
2013-12-06 15:32:23 +01:00
Uwe Stieber
6f1d6a5dbe Fixed indentation
Fixed indentation by replacing TABs by 4 spaces.
2013-09-24 13:37:00 +02:00
Uwe Stieber
d6498a63b8 Simplify patch by using GetProcessId
GetProcessId simplifies the code as it avoids to add the additional member variable 'm_childProcessId'. Cleaned up the indentation.
2013-09-24 13:11:48 +02:00
Uwe Stieber
03fbed5fc2 Add API to access the process id of the started process
Added new agent message "GetProcessId" and a API "winpty_get_process_id"
to allow access to the process id of the started process. The process id
is needed to integrate "winpty" with Eclipse CDT to launch native Windows
console applications inside the Eclipse UI.
2013-09-24 10:09:01 +02:00
Ryan Prichard
274086bbf5 In winpty-agent, print an error message if the arguments are invalid.
* Some users might think they could run winpty-agent.exe.

 * Right now, when I run winpty-agent.exe from a cmd.exe command prompt
   window, it looks like winpty-agent.exe is segfaulting.  It *ought* to
   print an assertion failed dialog box.
2012-12-20 04:20:10 -08:00
Ryan Prichard
d02cccb256 MSVC compatibility: Remove the {Agent,WinPty}DebugClient.cc hack.
* With this hack, it's impossible to add all the .cc files to an MSVC
   project, because MSVC understandably thinks that
   agent/AgentDebugClient.cc and shared/DebugClient.cc are two separate
   C++ translation units.  I could rename DebugClient.cc, but it's better
   to just fix the problem with the Makefile.
2012-12-20 04:07:57 -08:00
Ryan Prichard
a7bc8fcf9d Rename Shared to shared and Misc to misc. 2012-04-01 02:13:21 -07:00
Ryan Prichard
8eb2da5850 Fix a typo. 2012-04-01 02:00:37 -07:00
Ryan Prichard
80d005e33e Start the agent's child process on the libwinpty client's desktop.
If I run a GUI program inside mintty using winpty, the GUI's window should
appear on the same desktop as mintty, not on the hidden desktop containing
the winpty console.

Even though STARTUPINFO.lpDesktop's type is LPTSTR (instead of LPCTSTR),
the documentation doesn't say anything about CreateProcess modifying the
lpDesktop string, so I didn't bother making a copy of desktop.c_str().
2012-03-31 00:55:49 -07:00
Ryan Prichard
b44bd6b655 Remove a piece of old Qt code from this Makefile. 2012-03-28 03:12:22 -07:00
Ryan Prichard
7eae3d9e33 Send "\r" instead of "\x1b[1G" because carriage return is simpler.
There's no other motivating reason for this change.  AFAIK, both of them
work equally well and do the same thing.
2012-03-28 03:12:13 -07:00
Ryan Prichard
6a29852ace Stop sending trailing whitespace in Terminal::sendLine.
* The intent of having the length variable was to avoid sending trailing
   whitespace for each line, but the previous code never read the variable.
   Instead, every line it sent was the width of the terminal window.

 * There was a bug where running console.exe inside a TERM=cygwin terminal
   resulted in excessive line feeds.  This change mitigates that bug, but
   doesn't fix it.  The problem is that the agent assumes that after it
   writes to the last column of a line, the cursor is still on the same
   line, but this isn't true for the TERM=cygwin terminal.
2012-03-28 03:10:37 -07:00
Ryan Prichard
0427aedadd Remove unused console font code from Win32Console::setSmallFont. 2012-03-28 01:09:52 -07:00
Ryan Prichard
dbc2d51fec Select a small console font on agent startup.
This maximizes the possible console size in terms of rows * cols.
2012-03-28 01:05:26 -07:00
Ryan Prichard
6585b72375 Use STD_{INPUT,OUTPUT}_HANDLE instead of reopening CONIN$ and CONOUT$.
Reopening the files is unnecessary.
2012-03-28 01:05:14 -07:00
Ryan Prichard
71aa4a59bb Rename pconsole to winpty.
* This avoids a name conflict with an existing unrelated project.

 * I think winpty is a better name anyway.  (i) It's more obviously
   Windows-related.  (ii) I think it more accurately describes what it
   does.  A "pseudo-console" ought to mirror the console API and allow
   replacing the implementation built-in to Windows.  This project is only
   trying to provide functionality similar to using the master interface of
   a Unix pty, but for native console programs.
2012-03-25 02:29:37 -07:00
Ryan Prichard
5010f5e1a6 Print an error message when CreateProcess fails.
I suspect that the library API (pconsole_open) should not be calling exit
if it can't start the agent process, but I don't want to deal with that
right now.
2012-03-24 17:19:55 -07:00
Ryan Prichard
32627354df Work on the agent debugging code.
* Suppress debug output unless the PCONSOLEDBG enviroment variable is
   set.

 * Rename Trace to trace to be consistent with the camelCaps naming
   convention.
2012-03-24 16:43:50 -07:00
Ryan Prichard
f75800fae6 Replace assert with ASSERT. 2012-03-24 16:41:15 -07:00
Ryan Prichard
44554d5e9d Add an MIT copyright notice to all the source files. 2012-03-23 03:11:34 -07:00
Ryan Prichard
d3667e38a8 Review the named pipe setup code.
The goal is to setup pipes between the libpconsole process and the new
agent process in a way that's secure and doesn't create an unnecessary
burden on the library's user.  This is apparently hard.

I think this code is good enough.
2012-03-23 02:19:09 -07:00
Ryan Prichard
d568fbdeb4 Add DsrSender.h. 2012-03-21 03:31:34 -07:00
Ryan Prichard
d418679741 Include stdint.h to provide int32_t.
* This fixed a libpconsole build error that happened with mingw-w64.
2012-03-21 03:30:18 -07:00
Ryan Prichard
0afc69c733 Move the three output binaries into a build directory. 2012-03-21 00:13:46 -07:00
Ryan Prichard
4cfb5e1c73 Expand a comment. 2012-03-20 23:46:12 -07:00
Ryan Prichard
0260b423a3 Continue working on console input.
* Remove most of the encoding table and instead generate the KeyDescriptor
   entries dynamically at startup.

 * I think I'm handling input tolerably well for TERM=xterm terminals, but
   I removed the support I had for rxvt for now.  I don't think it makes
   sense to fill out the table, but the new code I have for TERM=xterm is
   also bloated.
2012-03-20 04:15:25 -07:00
Ryan Prichard
1fdda9e1d4 Work on console input handling.
* If bytes are still queued after processing as many keypresses as
   possible, send a DSR to the console.  The console should respond with
   a DSR reply, which will flush out the input buffer without having to
   wait for a timeout.

 * Add ah hoc code for ALT-<character> rather than listing every character
   in the table.

 * When keypresses have Alt/Ctrl/Shift modifiers, generate extra
   INPUT_RECORDS to press and release each modifier.  EDIT.COM seemed to
   require these for some Ctrl-<key> keypresses I tried.
2012-03-20 02:04:46 -07:00
Ryan Prichard
d32e36032d Fix an bug in ConsoleInput::appendChar: set dwControlKeyState. 2012-03-19 22:14:34 -07:00
Ryan Prichard
98970ead5c Use ESC and CSI macros in ConsoleInput::keyDescriptorTable. 2012-03-19 22:14:06 -07:00
Ryan Prichard
ac76cbcc20 Initial checkin of improved console input handling.
* Generate Ctrl-C events by calling GenerateConsoleCtrlEvent.

   I noticed that calls to this routine don't behave exactly the same as
   a real Ctrl-C keypress.  In Python, pressing Ctrl-C immediately
   displays a new "KeyboardInterrupt" line.  Calling
   GenerateConsoleCtrlEvent has no immediate effect, but after pressing
   Enter, Python displays a stack trace where a KeyboardInterrupt was
   raised.  After some testing, I suspect the issue is that a real Ctrl-C
   keypress interrupts a blocking console read, but
   GenerateConsoleCtrlEvent does not.

   I also tried synthesizing Ctrl-C using (a) PostMessage with
   WM_{CHAR,KEYDOWN}, and (b) SendInput.  I couldn't get either to work.

 * Recognize ESC sequences.  The set of recognized sequences is ad hoc.

 * Recognize UTF-8-encoded characters and convert them to UTF-16.

 * The code currently uses a timeout to differentiate between pressing ESC
   and pressing a key that generates an ESC sequence.  I have a theory that
   I can use the "Device Status Report" ESC sequences to avoid this
   timeout.
2012-03-19 21:30:16 -07:00
Ryan Prichard
0554f9fbde In Agent::handleStartProcessPacket, call GetLastError immediately after
CreateProcess.
2012-03-19 21:17:43 -07:00
Ryan Prichard
6b87c54d0d Try to improve the way color works in the agent.
* Assume that either:
    - The console has a white-on-black color scheme.  This could be set
      at agent startup.
    - The remote terminal also has a white-on-black color scheme, OR...
    - With a different color scheme, the white/black colors could be
      reversed, but the console is still usable.

 * The COMMON_LVB_REVERSE_VIDEO flag apparently has no effect in a Windows
   console, so ignore it in the agent too.

 * Start handling Unicode characters.  I noticed that box drawing
   characters (mc.exe / edit.com) are displayed correctly now.  I'm calling
   WideCharToMultiByte once per character, though, and I'm wondering if
   this is inefficient.
2012-03-15 04:08:58 -07:00