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 07:32:49 +00:00
|
|
|
// A test program for CreateConsoleScreenBuffer / SetConsoleActiveScreenBuffer
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <conio.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include <cassert>
|
|
|
|
|
2016-01-15 09:08:10 +00:00
|
|
|
#include "../src/shared/DebugClient.cc"
|
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 07:32:49 +00:00
|
|
|
#include "TestUtil.cc"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
HANDLE origBuffer = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
HANDLE childBuffer = CreateConsoleScreenBuffer(
|
|
|
|
GENERIC_READ | GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
|
|
|
|
|
|
|
|
SetConsoleActiveScreenBuffer(childBuffer);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
char buf[1024];
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
|
|
|
|
|
|
|
assert(GetConsoleScreenBufferInfo(origBuffer, &info));
|
|
|
|
trace("child.size=(%d,%d)", (int)info.dwSize.X, (int)info.dwSize.Y);
|
|
|
|
trace("child.cursor=(%d,%d)", (int)info.dwCursorPosition.X, (int)info.dwCursorPosition.Y);
|
|
|
|
trace("child.window=(%d,%d,%d,%d)",
|
|
|
|
(int)info.srWindow.Left, (int)info.srWindow.Top,
|
|
|
|
(int)info.srWindow.Right, (int)info.srWindow.Bottom);
|
|
|
|
trace("child.maxSize=(%d,%d)", (int)info.dwMaximumWindowSize.X, (int)info.dwMaximumWindowSize.Y);
|
|
|
|
|
|
|
|
int ch = getch();
|
|
|
|
sprintf(buf, "%02x\n", ch);
|
|
|
|
DWORD actual = 0;
|
|
|
|
WriteFile(childBuffer, buf, strlen(buf), &actual, NULL);
|
|
|
|
if (ch == 0x1b/*ESC*/ || ch == 0x03/*CTRL-C*/)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (ch == 'b') {
|
|
|
|
setBufferSize(origBuffer, 40, 25);
|
|
|
|
} else if (ch == 'w') {
|
|
|
|
setWindowPos(origBuffer, 1, 1, 38, 23);
|
|
|
|
} else if (ch == 'c') {
|
|
|
|
setCursorPos(origBuffer, 10, 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetConsoleActiveScreenBuffer(origBuffer);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|