-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite resize logic, introduce "direct mode", and tweak scroll scrap…
…ing. * Unfreeze the console while changing the buffer size. Changing the buffer size hangs conhost.exe. See: - #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 #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.
- Loading branch information
Showing
14 changed files
with
485 additions
and
119 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include <windows.h> | ||
#include <cassert> | ||
|
||
#include "../shared/DebugClient.cc" | ||
#include "TestUtil.cc" | ||
|
||
void dumpInfoToTrace() { | ||
CONSOLE_SCREEN_BUFFER_INFO info; | ||
assert(GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info)); | ||
trace("win=(%d,%d,%d,%d)", | ||
(int)info.srWindow.Left, | ||
(int)info.srWindow.Top, | ||
(int)info.srWindow.Right, | ||
(int)info.srWindow.Bottom); | ||
trace("buf=(%d,%d)", | ||
(int)info.dwSize.X, | ||
(int)info.dwSize.Y); | ||
trace("cur=(%d,%d)", | ||
(int)info.dwCursorPosition.X, | ||
(int)info.dwCursorPosition.Y); | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
if (argc == 1) { | ||
startChildProcess(L"CHILD"); | ||
return 0; | ||
} | ||
|
||
setWindowPos(0, 0, 1, 1); | ||
|
||
if (false) { | ||
// Reducing the buffer height can move the window up. | ||
setBufferSize(80, 25); | ||
setWindowPos(0, 20, 80, 5); | ||
Sleep(2000); | ||
setBufferSize(80, 10); | ||
} | ||
|
||
if (false) { | ||
// Reducing the buffer height moves the window up and the buffer | ||
// contents up too. | ||
setBufferSize(80, 25); | ||
setWindowPos(0, 20, 80, 5); | ||
setCursorPos(0, 20); | ||
printf("TEST1\nTEST2\nTEST3\nTEST4\n"); | ||
fflush(stdout); | ||
Sleep(2000); | ||
setBufferSize(80, 10); | ||
} | ||
|
||
if (false) { | ||
// Reducing the buffer width can move the window left. | ||
setBufferSize(80, 25); | ||
setWindowPos(40, 0, 40, 25); | ||
Sleep(2000); | ||
setBufferSize(60, 25); | ||
} | ||
|
||
if (false) { | ||
// Sometimes the buffer contents are shifted up; sometimes they're | ||
// shifted down. It seems to depend on the cursor position? | ||
|
||
// setBufferSize(80, 25); | ||
// setWindowPos(0, 20, 80, 5); | ||
// setCursorPos(0, 20); | ||
// printf("TESTa\nTESTb\nTESTc\nTESTd\nTESTe"); | ||
// fflush(stdout); | ||
// setCursorPos(0, 0); | ||
// printf("TEST1\nTEST2\nTEST3\nTEST4\nTEST5"); | ||
// fflush(stdout); | ||
// setCursorPos(0, 24); | ||
// Sleep(5000); | ||
// setBufferSize(80, 24); | ||
|
||
setBufferSize(80, 20); | ||
setWindowPos(0, 10, 80, 10); | ||
setCursorPos(0, 18); | ||
|
||
printf("TEST1\nTEST2"); | ||
fflush(stdout); | ||
setCursorPos(0, 18); | ||
|
||
Sleep(2000); | ||
setBufferSize(80, 18); | ||
} | ||
|
||
dumpInfoToTrace(); | ||
Sleep(30000); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// A test program for CreateConsoleScreenBuffer / SetConsoleActiveScreenBuffer | ||
// | ||
|
||
#include <windows.h> | ||
#include <stdio.h> | ||
#include <conio.h> | ||
#include <io.h> | ||
#include <cassert> | ||
|
||
#include "../shared/DebugClient.cc" | ||
#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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
|
||
for i in range(1, int(sys.argv[1]) + 1): | ||
print i, "X" * 78 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <windows.h> | ||
|
||
#include "TestUtil.cc" | ||
#include "../shared/DebugClient.cc" | ||
|
||
int main(int argc, char *argv[]) { | ||
int col = atoi(argv[1]); | ||
int row = atoi(argv[2]); | ||
setCursorPos(col, row); | ||
return 0; | ||
} |
Oops, something went wrong.