installed pty
[VSoRC/.git] / node_modules / node-pty / deps / winpty / misc / Win32Test2.cc
1 /*
2  * This test demonstrates that putting a console into selection mode does not
3  * block the low-level console APIs, even though it blocks WriteFile.
4  */
5
6 #define _WIN32_WINNT 0x0501
7 #include "../src/shared/DebugClient.cc"
8 #include <windows.h>
9 #include <stdio.h>
10
11 const int SC_CONSOLE_MARK = 0xFFF2;
12
13 CALLBACK DWORD writerThread(void*)
14 {
15     CHAR_INFO xChar, fillChar;
16     memset(&xChar, 0, sizeof(xChar));
17     xChar.Char.AsciiChar = 'X';
18     xChar.Attributes = 7;
19     memset(&fillChar, 0, sizeof(fillChar));
20     fillChar.Char.AsciiChar = ' ';
21     fillChar.Attributes = 7;
22     COORD oneCoord = { 1, 1 };
23     COORD zeroCoord = { 0, 0 };
24
25     while (true) {
26         SMALL_RECT writeRegion = { 5, 5, 5, 5 };
27         WriteConsoleOutput(GetStdHandle(STD_OUTPUT_HANDLE),
28                            &xChar, oneCoord,
29                            zeroCoord,
30                            &writeRegion);
31         Sleep(500);
32         SMALL_RECT scrollRect = { 1, 1, 20, 20 };
33         COORD destCoord = { 0, 0 };
34         ScrollConsoleScreenBuffer(GetStdHandle(STD_OUTPUT_HANDLE),
35                                   &scrollRect,
36                                   NULL,
37                                   destCoord,
38                                   &fillChar);
39     }
40 }
41
42 int main()
43 {
44     CreateThread(NULL, 0, writerThread, NULL, 0, NULL);
45     trace("marking console");
46     HWND hwnd = GetConsoleWindow();
47     PostMessage(hwnd, WM_SYSCOMMAND, SC_CONSOLE_MARK, 0);
48
49     Sleep(2000);
50
51     trace("reading output");
52     CHAR_INFO buf[1];
53     COORD bufSize = { 1, 1 };
54     COORD zeroCoord = { 0, 0 };
55     SMALL_RECT readRect = { 0, 0, 0, 0 };
56     ReadConsoleOutput(GetStdHandle(STD_OUTPUT_HANDLE),
57                       buf,
58                       bufSize,
59                       zeroCoord,
60                       &readRect);
61     trace("done reading output");
62
63     Sleep(2000);
64
65     PostMessage(hwnd, WM_CHAR, 27, 0x00010001);
66
67     Sleep(1100);
68
69     return 0;
70 }