Commit Graph

562 Commits

Author SHA1 Message Date
Ryan Prichard
8d90670fcc Use the proper built-in va_copy with MSVC 2013 and up. 2015-10-15 05:00:04 -05:00
Ryan Prichard
6ac6db2e51 Refactoring: improve syncMarkerText safety 2015-10-15 04:59:30 -05:00
Ryan Prichard
efb10c4fcf Use Erase-in-Line more carefully
Instead of erasing a whole line before writing a line, simply write the
line.  At the end of the line, issue a CSI 0K to erase from the cursor to
the end of the line.  The erasing serves two purposes:

 * It can clear characters beyond the right end of the terminal, which
   have been obscured by a terminal resize.

 * It sets the background color for the trailing whitespace.

Doing the erasing like so has two benefits:

 * It's more correct.  Previously, the trailing whitespace was colored
   arbitrarily.  Now, it is correctly colored to the last color on the
   line.

 * It should eliminate a lot of flicker.
2015-10-14 04:39:52 -05:00
Ryan Prichard
d4a5d0f5a0 Turn on -O2 when building the agent and libwinpty. 2015-10-14 04:12:19 -05:00
Ryan Prichard
fd8737d3f0 Behave somewhat more sensibly with UTF-16 surrogate pairs
* On output: detect them and transcode them properly into UTF-8.

 * On input: create input records for both halfs of the surrogate pair.

I tested by copying-and-pasting U+20000 (D840 DC00) into a mintty bash
shell.  It works, but the Windows console thinks the character occupies
four cells when it really occupies two, so the cursor position is wrong.
When I press backspace, it doesn't delete the whole character -- instead,
it replaces it with a '?', because it becomes an invalid surrogate pair.

Still, the behavior seems like an improvement.
2015-10-14 04:11:32 -05:00
Ryan Prichard
04d5c1051f Factor out outputSetColor and fixConsolePopupBoxArt functions. 2015-10-13 05:07:44 -05:00
Ryan Prichard
bde8922e08 Fix a C++11 issue: separate string literals and macros with a space. 2015-10-13 04:32:51 -05:00
Ryan Prichard
dd438a9505 Reset the SGR parameters before clearing the terminal on Terminal::reset. 2015-10-13 04:31:26 -05:00
Ryan Prichard
4338e7b687 Add a Bash script that tests terminal color handling 2015-10-13 04:09:44 -05:00
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
208d084c81 Convert UnicodeWideTest1.cc from CRLF to LF for consistency.
The repository probably should be configured somehow to ensure line ending
consistency, particularly across Cygwin and MSYS git.
2015-10-12 04:33:40 -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
a66de7dc28 Add more tests of full-width characters and rename one of the tests.
* Fix the -std=c++11 narrowing warnings in TestUtil.cc.
2015-10-11 22:44:22 -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
31ee484b29 Add notes on fonts, code pages, and East Asian character widths 2015-10-10 19:25:20 -05:00
Ryan Prichard
085aa0a9f0 s/UnicodeTest1/Utf16Echo/ and output arbitrary UTF-16 codepoints. 2015-10-10 15:04:48 -05:00
Ryan Prichard
1ef25fb6c6 Fix UnicodeTest1 to work with TrueType fonts 2015-10-10 04:31:58 -05:00
Ryan Prichard
2751488f18 Fix a build failure 2015-10-10 03:30:58 -05:00
Ryan Prichard
c3701e60d9 Automatically test all three common fonts 2015-10-10 02:29:47 -05:00
Ryan Prichard
f5b15bf274 Fix UnicodeDoubleWidthTest font name output. 2015-10-10 02:22:53 -05:00
Ryan Prichard
fe26bfda5f Create a test program to explore the U+30FC width problem w/Lucida Console 2015-10-10 02:14:31 -05:00
Ryan Prichard
b0b79e1b1e Improve Unicode handling of SetFont arguments. 2015-10-09 18:52:20 -05:00
Ryan Prichard
5beb4c1cbb Add a new test program, QueryFont, and expand SetFont. 2015-10-09 17:42:18 -05:00
Ryan Prichard
44ee1cc7ea Updates to the UnicodeVariableWidthChars test program 2015-10-09 01:32:17 -05:00
Ryan Prichard
ac00ac8315 Updates to the UnicodeVariableWidthChars test program 2015-10-07 02:00:11 -05:00
Ryan Prichard
22164a090a Also print U+30FC and print it many times.
* With Lucida Console 10px, U+30FC is handled as a halfwidth character.
   With Lucida Console 12px, it is instead handled as a fullwidth
   character.
2015-10-06 23:51:12 -05:00
Ryan Prichard
80cc3b9096 Add a test case that writes and reads half-width vs full-width characters. 2015-10-05 01:01:24 -05:00
Ryan Prichard
db12b07706 Add winpty-debugserver.exe and document debugging environment variables. 2015-10-01 03:17:38 -05:00
Ryan Prichard
11ac33ef88 Fix a formatting problem in the README 2015-09-30 04:18:22 -05:00
Ryan Prichard
76bc37f307 Add make to the MSYS2 and Cygwin package lists. 2015-09-30 04:00:32 -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
e19c29bd03 Avoid setting lpDesktop if there we didn't actually create a new desktop.
* Add debug information.

 * This change fixed a bug where the new winpty-agent.exe process
   successfully started, but immediately exited without reaching main().
   The bug occurred while SSH'ing into the Cygwin SSH server.
2015-09-29 02:32:57 -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
6c9c7bb985 Allow col and row to be specified to VeryLargeRead.cc and add server OSs 2015-09-26 00:13:31 -05:00
Ryan Prichard
9fc1b70fa4 Fix a character-handling defect in TestUtil.cc, startChildProcess
- Formatting a wchar_t* argument with %s does not work with MinGW's
   swprintf.  (Apparently it does with MSVC?  Sigh.)  AFAICT, %ls does
   the right thing with both MinGW and MSVC.  (I didn't test MSVC.)
2015-09-25 23:41:08 -05:00
Ryan Prichard
f4ef2a0d0b Document the largest allowed ReadConsoleOutputW call on various client OSs 2015-09-25 05:51:34 -05:00
Ryan Prichard
0907855b87 Make VeryLargeRead.cc work better on Windows XP.
Avoid zero-initializing the buffer to accommodate VMs that have
little RAM.  Use a smaller buffer size (9000x9000 ==> 324MB
buffer) that still demonstrates the read-size limit on XP.
2015-09-25 00:25:51 -07:00
Ryan Prichard
3a4a602ac8 Add a test case that performs a very large read. 2015-09-24 23:58:31 -07: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
6122f0d989 Expand on the Win10ResizeWhileFrozen comment. 2015-09-24 23:58:28 -07:00
Ryan Prichard
06a81be1fc Add a setCursorPos convenience function. 2015-09-24 23:58:26 -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
bb5edfb2fd Add a test program that writes and reads a non-ASCII character. 2015-09-23 17:38:12 -05:00
Ryan Prichard
72557cb8c4 Read and write UTF-16, not Ascii. 2015-09-23 17:37:35 -05:00