@shitiandmw/node-pty 1.1.0-agent.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/LICENSE +69 -0
  2. package/README.md +170 -0
  3. package/binding.gyp +111 -0
  4. package/deps/.editorconfig +2 -0
  5. package/deps/winpty/.drone.yml +17 -0
  6. package/deps/winpty/.gitattributes +19 -0
  7. package/deps/winpty/LICENSE +21 -0
  8. package/deps/winpty/Makefile +166 -0
  9. package/deps/winpty/README.md +151 -0
  10. package/deps/winpty/RELEASES.md +280 -0
  11. package/deps/winpty/VERSION.txt +1 -0
  12. package/deps/winpty/configure +167 -0
  13. package/deps/winpty/misc/BufferResizeTests.cc +90 -0
  14. package/deps/winpty/misc/ChangeScreenBuffer.cc +53 -0
  15. package/deps/winpty/misc/ClearConsole.cc +72 -0
  16. package/deps/winpty/misc/ConinMode.cc +117 -0
  17. package/deps/winpty/misc/ConinMode.ps1 +116 -0
  18. package/deps/winpty/misc/ConoutMode.cc +113 -0
  19. package/deps/winpty/misc/DebugClient.py +42 -0
  20. package/deps/winpty/misc/DebugServer.py +63 -0
  21. package/deps/winpty/misc/DumpLines.py +5 -0
  22. package/deps/winpty/misc/EnableExtendedFlags.txt +46 -0
  23. package/deps/winpty/misc/Font-Report-June2016/CP437-Consolas.txt +528 -0
  24. package/deps/winpty/misc/Font-Report-June2016/CP437-Lucida.txt +633 -0
  25. package/deps/winpty/misc/Font-Report-June2016/CP932.txt +630 -0
  26. package/deps/winpty/misc/Font-Report-June2016/CP936.txt +630 -0
  27. package/deps/winpty/misc/Font-Report-June2016/CP949.txt +630 -0
  28. package/deps/winpty/misc/Font-Report-June2016/CP950.txt +630 -0
  29. package/deps/winpty/misc/Font-Report-June2016/MinimumWindowWidths.txt +16 -0
  30. package/deps/winpty/misc/Font-Report-June2016/Results.txt +4 -0
  31. package/deps/winpty/misc/Font-Report-June2016/Windows10SetFontBugginess.txt +144 -0
  32. package/deps/winpty/misc/FontSurvey.cc +100 -0
  33. package/deps/winpty/misc/FormatChar.h +21 -0
  34. package/deps/winpty/misc/FreezePerfTest.cc +62 -0
  35. package/deps/winpty/misc/GetCh.cc +20 -0
  36. package/deps/winpty/misc/GetConsolePos.cc +41 -0
  37. package/deps/winpty/misc/GetFont.cc +261 -0
  38. package/deps/winpty/misc/IdentifyConsoleWindow.ps1 +51 -0
  39. package/deps/winpty/misc/IsNewConsole.cc +87 -0
  40. package/deps/winpty/misc/MouseInputNotes.txt +90 -0
  41. package/deps/winpty/misc/MoveConsoleWindow.cc +34 -0
  42. package/deps/winpty/misc/Notes.txt +219 -0
  43. package/deps/winpty/misc/OSVersion.cc +27 -0
  44. package/deps/winpty/misc/ScreenBufferFreezeInactive.cc +101 -0
  45. package/deps/winpty/misc/ScreenBufferTest.cc +671 -0
  46. package/deps/winpty/misc/ScreenBufferTest2.cc +151 -0
  47. package/deps/winpty/misc/SelectAllTest.cc +45 -0
  48. package/deps/winpty/misc/SetBufferSize.cc +32 -0
  49. package/deps/winpty/misc/SetCursorPos.cc +10 -0
  50. package/deps/winpty/misc/SetFont.cc +145 -0
  51. package/deps/winpty/misc/SetWindowRect.cc +36 -0
  52. package/deps/winpty/misc/ShowArgv.cc +12 -0
  53. package/deps/winpty/misc/ShowConsoleInput.cc +40 -0
  54. package/deps/winpty/misc/Spew.py +5 -0
  55. package/deps/winpty/misc/TestUtil.cc +172 -0
  56. package/deps/winpty/misc/UnicodeDoubleWidthTest.cc +102 -0
  57. package/deps/winpty/misc/UnicodeWideTest1.cc +246 -0
  58. package/deps/winpty/misc/UnicodeWideTest2.cc +130 -0
  59. package/deps/winpty/misc/UnixEcho.cc +89 -0
  60. package/deps/winpty/misc/Utf16Echo.cc +46 -0
  61. package/deps/winpty/misc/VeryLargeRead.cc +122 -0
  62. package/deps/winpty/misc/VkEscapeTest.cc +56 -0
  63. package/deps/winpty/misc/Win10ResizeWhileFrozen.cc +52 -0
  64. package/deps/winpty/misc/Win10WrapTest1.cc +57 -0
  65. package/deps/winpty/misc/Win10WrapTest2.cc +30 -0
  66. package/deps/winpty/misc/Win32Echo1.cc +26 -0
  67. package/deps/winpty/misc/Win32Echo2.cc +19 -0
  68. package/deps/winpty/misc/Win32Test1.cc +46 -0
  69. package/deps/winpty/misc/Win32Test2.cc +70 -0
  70. package/deps/winpty/misc/Win32Test3.cc +78 -0
  71. package/deps/winpty/misc/Win32Write1.cc +44 -0
  72. package/deps/winpty/misc/WindowsBugCrashReader.cc +27 -0
  73. package/deps/winpty/misc/WriteConsole.cc +106 -0
  74. package/deps/winpty/misc/build32.sh +9 -0
  75. package/deps/winpty/misc/build64.sh +9 -0
  76. package/deps/winpty/misc/color-test.sh +212 -0
  77. package/deps/winpty/misc/font-notes.txt +300 -0
  78. package/deps/winpty/misc/winbug-15048.cc +201 -0
  79. package/deps/winpty/ship/build-pty4j-libpty.bat +36 -0
  80. package/deps/winpty/ship/common_ship.py +53 -0
  81. package/deps/winpty/ship/make_msvc_package.py +165 -0
  82. package/deps/winpty/ship/ship.py +108 -0
  83. package/deps/winpty/src/agent/Agent.cc +613 -0
  84. package/deps/winpty/src/agent/Agent.h +103 -0
  85. package/deps/winpty/src/agent/AgentCreateDesktop.cc +84 -0
  86. package/deps/winpty/src/agent/AgentCreateDesktop.h +28 -0
  87. package/deps/winpty/src/agent/ConsoleFont.cc +632 -0
  88. package/deps/winpty/src/agent/ConsoleFont.h +28 -0
  89. package/deps/winpty/src/agent/ConsoleInput.cc +852 -0
  90. package/deps/winpty/src/agent/ConsoleInput.h +109 -0
  91. package/deps/winpty/src/agent/ConsoleInputReencoding.cc +121 -0
  92. package/deps/winpty/src/agent/ConsoleInputReencoding.h +36 -0
  93. package/deps/winpty/src/agent/ConsoleLine.cc +152 -0
  94. package/deps/winpty/src/agent/ConsoleLine.h +41 -0
  95. package/deps/winpty/src/agent/Coord.h +87 -0
  96. package/deps/winpty/src/agent/DebugShowInput.cc +239 -0
  97. package/deps/winpty/src/agent/DebugShowInput.h +32 -0
  98. package/deps/winpty/src/agent/DefaultInputMap.cc +422 -0
  99. package/deps/winpty/src/agent/DefaultInputMap.h +28 -0
  100. package/deps/winpty/src/agent/DsrSender.h +30 -0
  101. package/deps/winpty/src/agent/EventLoop.cc +99 -0
  102. package/deps/winpty/src/agent/EventLoop.h +47 -0
  103. package/deps/winpty/src/agent/InputMap.cc +246 -0
  104. package/deps/winpty/src/agent/InputMap.h +114 -0
  105. package/deps/winpty/src/agent/LargeConsoleRead.cc +71 -0
  106. package/deps/winpty/src/agent/LargeConsoleRead.h +68 -0
  107. package/deps/winpty/src/agent/NamedPipe.cc +378 -0
  108. package/deps/winpty/src/agent/NamedPipe.h +125 -0
  109. package/deps/winpty/src/agent/Scraper.cc +699 -0
  110. package/deps/winpty/src/agent/Scraper.h +103 -0
  111. package/deps/winpty/src/agent/SimplePool.h +75 -0
  112. package/deps/winpty/src/agent/SmallRect.h +143 -0
  113. package/deps/winpty/src/agent/Terminal.cc +535 -0
  114. package/deps/winpty/src/agent/Terminal.h +69 -0
  115. package/deps/winpty/src/agent/UnicodeEncoding.h +157 -0
  116. package/deps/winpty/src/agent/UnicodeEncodingTest.cc +189 -0
  117. package/deps/winpty/src/agent/Win32Console.cc +107 -0
  118. package/deps/winpty/src/agent/Win32Console.h +67 -0
  119. package/deps/winpty/src/agent/Win32ConsoleBuffer.cc +193 -0
  120. package/deps/winpty/src/agent/Win32ConsoleBuffer.h +99 -0
  121. package/deps/winpty/src/agent/main.cc +114 -0
  122. package/deps/winpty/src/agent/subdir.mk +61 -0
  123. package/deps/winpty/src/configurations.gypi +60 -0
  124. package/deps/winpty/src/debugserver/DebugServer.cc +117 -0
  125. package/deps/winpty/src/debugserver/subdir.mk +41 -0
  126. package/deps/winpty/src/include/winpty.h +242 -0
  127. package/deps/winpty/src/include/winpty_constants.h +131 -0
  128. package/deps/winpty/src/libwinpty/AgentLocation.cc +75 -0
  129. package/deps/winpty/src/libwinpty/AgentLocation.h +28 -0
  130. package/deps/winpty/src/libwinpty/LibWinptyException.h +54 -0
  131. package/deps/winpty/src/libwinpty/WinptyInternal.h +72 -0
  132. package/deps/winpty/src/libwinpty/subdir.mk +46 -0
  133. package/deps/winpty/src/libwinpty/winpty.cc +970 -0
  134. package/deps/winpty/src/shared/AgentMsg.h +38 -0
  135. package/deps/winpty/src/shared/BackgroundDesktop.cc +122 -0
  136. package/deps/winpty/src/shared/BackgroundDesktop.h +73 -0
  137. package/deps/winpty/src/shared/Buffer.cc +103 -0
  138. package/deps/winpty/src/shared/Buffer.h +102 -0
  139. package/deps/winpty/src/shared/DebugClient.cc +187 -0
  140. package/deps/winpty/src/shared/DebugClient.h +38 -0
  141. package/deps/winpty/src/shared/GenRandom.cc +138 -0
  142. package/deps/winpty/src/shared/GenRandom.h +55 -0
  143. package/deps/winpty/src/shared/GetCommitHash.bat +13 -0
  144. package/deps/winpty/src/shared/Mutex.h +54 -0
  145. package/deps/winpty/src/shared/OsModule.h +63 -0
  146. package/deps/winpty/src/shared/OwnedHandle.cc +36 -0
  147. package/deps/winpty/src/shared/OwnedHandle.h +45 -0
  148. package/deps/winpty/src/shared/PrecompiledHeader.h +43 -0
  149. package/deps/winpty/src/shared/StringBuilder.h +227 -0
  150. package/deps/winpty/src/shared/StringBuilderTest.cc +114 -0
  151. package/deps/winpty/src/shared/StringUtil.cc +55 -0
  152. package/deps/winpty/src/shared/StringUtil.h +80 -0
  153. package/deps/winpty/src/shared/TimeMeasurement.h +63 -0
  154. package/deps/winpty/src/shared/UnixCtrlChars.h +45 -0
  155. package/deps/winpty/src/shared/UpdateGenVersion.bat +20 -0
  156. package/deps/winpty/src/shared/WindowsSecurity.cc +460 -0
  157. package/deps/winpty/src/shared/WindowsSecurity.h +104 -0
  158. package/deps/winpty/src/shared/WindowsVersion.cc +252 -0
  159. package/deps/winpty/src/shared/WindowsVersion.h +29 -0
  160. package/deps/winpty/src/shared/WinptyAssert.cc +55 -0
  161. package/deps/winpty/src/shared/WinptyAssert.h +64 -0
  162. package/deps/winpty/src/shared/WinptyException.cc +57 -0
  163. package/deps/winpty/src/shared/WinptyException.h +43 -0
  164. package/deps/winpty/src/shared/WinptyVersion.cc +42 -0
  165. package/deps/winpty/src/shared/WinptyVersion.h +27 -0
  166. package/deps/winpty/src/shared/winpty_snprintf.h +99 -0
  167. package/deps/winpty/src/subdir.mk +5 -0
  168. package/deps/winpty/src/tests/subdir.mk +28 -0
  169. package/deps/winpty/src/tests/trivial_test.cc +158 -0
  170. package/deps/winpty/src/unix-adapter/InputHandler.cc +114 -0
  171. package/deps/winpty/src/unix-adapter/InputHandler.h +56 -0
  172. package/deps/winpty/src/unix-adapter/OutputHandler.cc +80 -0
  173. package/deps/winpty/src/unix-adapter/OutputHandler.h +53 -0
  174. package/deps/winpty/src/unix-adapter/Util.cc +86 -0
  175. package/deps/winpty/src/unix-adapter/Util.h +31 -0
  176. package/deps/winpty/src/unix-adapter/WakeupFd.cc +70 -0
  177. package/deps/winpty/src/unix-adapter/WakeupFd.h +42 -0
  178. package/deps/winpty/src/unix-adapter/main.cc +729 -0
  179. package/deps/winpty/src/unix-adapter/subdir.mk +41 -0
  180. package/deps/winpty/src/winpty.gyp +234 -0
  181. package/deps/winpty/vcbuild.bat +83 -0
  182. package/lib/conpty_console_list_agent.js +16 -0
  183. package/lib/conpty_console_list_agent.js.map +1 -0
  184. package/lib/eventEmitter2.js +47 -0
  185. package/lib/eventEmitter2.js.map +1 -0
  186. package/lib/eventEmitter2.test.js +30 -0
  187. package/lib/eventEmitter2.test.js.map +1 -0
  188. package/lib/index.js +52 -0
  189. package/lib/index.js.map +1 -0
  190. package/lib/interfaces.js +7 -0
  191. package/lib/interfaces.js.map +1 -0
  192. package/lib/shared/conout.js +11 -0
  193. package/lib/shared/conout.js.map +1 -0
  194. package/lib/terminal.js +190 -0
  195. package/lib/terminal.js.map +1 -0
  196. package/lib/terminal.test.js +139 -0
  197. package/lib/terminal.test.js.map +1 -0
  198. package/lib/testUtils.test.js +28 -0
  199. package/lib/testUtils.test.js.map +1 -0
  200. package/lib/types.js +7 -0
  201. package/lib/types.js.map +1 -0
  202. package/lib/unixTerminal.js +346 -0
  203. package/lib/unixTerminal.js.map +1 -0
  204. package/lib/unixTerminal.test.js +351 -0
  205. package/lib/unixTerminal.test.js.map +1 -0
  206. package/lib/utils.js +39 -0
  207. package/lib/utils.js.map +1 -0
  208. package/lib/windowsConoutConnection.js +125 -0
  209. package/lib/windowsConoutConnection.js.map +1 -0
  210. package/lib/windowsPtyAgent.js +320 -0
  211. package/lib/windowsPtyAgent.js.map +1 -0
  212. package/lib/windowsPtyAgent.test.js +90 -0
  213. package/lib/windowsPtyAgent.test.js.map +1 -0
  214. package/lib/windowsTerminal.js +199 -0
  215. package/lib/windowsTerminal.js.map +1 -0
  216. package/lib/windowsTerminal.test.js +219 -0
  217. package/lib/windowsTerminal.test.js.map +1 -0
  218. package/lib/worker/conoutSocketWorker.js +22 -0
  219. package/lib/worker/conoutSocketWorker.js.map +1 -0
  220. package/package.json +68 -0
  221. package/prebuilds/darwin-arm64/pty.node +0 -0
  222. package/prebuilds/darwin-arm64/spawn-helper +0 -0
  223. package/prebuilds/darwin-x64/pty.node +0 -0
  224. package/prebuilds/darwin-x64/spawn-helper +0 -0
  225. package/prebuilds/win32-arm64/conpty/OpenConsole.exe +0 -0
  226. package/prebuilds/win32-arm64/conpty/conpty.dll +0 -0
  227. package/prebuilds/win32-arm64/conpty.node +0 -0
  228. package/prebuilds/win32-arm64/conpty.pdb +0 -0
  229. package/prebuilds/win32-arm64/conpty_console_list.node +0 -0
  230. package/prebuilds/win32-arm64/conpty_console_list.pdb +0 -0
  231. package/prebuilds/win32-arm64/pty.node +0 -0
  232. package/prebuilds/win32-arm64/pty.pdb +0 -0
  233. package/prebuilds/win32-arm64/winpty-agent.exe +0 -0
  234. package/prebuilds/win32-arm64/winpty-agent.pdb +0 -0
  235. package/prebuilds/win32-arm64/winpty.dll +0 -0
  236. package/prebuilds/win32-arm64/winpty.pdb +0 -0
  237. package/prebuilds/win32-x64/conpty/OpenConsole.exe +0 -0
  238. package/prebuilds/win32-x64/conpty/conpty.dll +0 -0
  239. package/prebuilds/win32-x64/conpty.node +0 -0
  240. package/prebuilds/win32-x64/conpty.pdb +0 -0
  241. package/prebuilds/win32-x64/conpty_console_list.node +0 -0
  242. package/prebuilds/win32-x64/conpty_console_list.pdb +0 -0
  243. package/prebuilds/win32-x64/pty.node +0 -0
  244. package/prebuilds/win32-x64/pty.pdb +0 -0
  245. package/prebuilds/win32-x64/winpty-agent.exe +0 -0
  246. package/prebuilds/win32-x64/winpty-agent.pdb +0 -0
  247. package/prebuilds/win32-x64/winpty.dll +0 -0
  248. package/prebuilds/win32-x64/winpty.pdb +0 -0
  249. package/scripts/gen-compile-commands.js +8 -0
  250. package/scripts/increment-version.js +54 -0
  251. package/scripts/post-install.js +99 -0
  252. package/scripts/prebuild.js +39 -0
  253. package/scripts/sync-prebuild.js +31 -0
  254. package/scripts/verify-darwin-fd-leak.js +63 -0
  255. package/src/conpty_console_list_agent.ts +15 -0
  256. package/src/eventEmitter2.test.ts +30 -0
  257. package/src/eventEmitter2.ts +48 -0
  258. package/src/index.ts +52 -0
  259. package/src/interfaces.ts +130 -0
  260. package/src/native.d.ts +54 -0
  261. package/src/shared/conout.ts +15 -0
  262. package/src/terminal.test.ts +119 -0
  263. package/src/terminal.ts +211 -0
  264. package/src/testUtils.test.ts +23 -0
  265. package/src/tsconfig.json +22 -0
  266. package/src/types.ts +15 -0
  267. package/src/unix/pty.cc +808 -0
  268. package/src/unix/spawn-helper.cc +23 -0
  269. package/src/unixTerminal.test.ts +367 -0
  270. package/src/unixTerminal.ts +388 -0
  271. package/src/utils.ts +29 -0
  272. package/src/win/conpty.cc +583 -0
  273. package/src/win/conpty.h +41 -0
  274. package/src/win/conpty_console_list.cc +44 -0
  275. package/src/win/path_util.cc +95 -0
  276. package/src/win/path_util.h +26 -0
  277. package/src/win/winpty.cc +333 -0
  278. package/src/windowsConoutConnection.ts +82 -0
  279. package/src/windowsPtyAgent.test.ts +94 -0
  280. package/src/windowsPtyAgent.ts +321 -0
  281. package/src/windowsTerminal.test.ts +229 -0
  282. package/src/windowsTerminal.ts +203 -0
  283. package/src/worker/conoutSocketWorker.ts +22 -0
  284. package/third_party/conpty/1.23.251008001/win10-arm64/OpenConsole.exe +0 -0
  285. package/third_party/conpty/1.23.251008001/win10-arm64/conpty.dll +0 -0
  286. package/third_party/conpty/1.23.251008001/win10-x64/OpenConsole.exe +0 -0
  287. package/third_party/conpty/1.23.251008001/win10-x64/conpty.dll +0 -0
  288. package/typings/node-pty.d.ts +211 -0
@@ -0,0 +1,51 @@
1
+ #
2
+ # Usage: powershell <path>\IdentifyConsoleWindow.ps1
3
+ #
4
+ # This script determines whether the process has a console attached, whether
5
+ # that console has a non-NULL window (e.g. HWND), and whether the window is on
6
+ # the current window station.
7
+ #
8
+
9
+ $signature = @'
10
+ [DllImport("kernel32.dll", SetLastError=true)]
11
+ public static extern IntPtr GetConsoleWindow();
12
+
13
+ [DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
14
+ public static extern bool SetConsoleTitle(String title);
15
+
16
+ [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
17
+ public static extern int GetWindowText(IntPtr hWnd,
18
+ System.Text.StringBuilder lpString,
19
+ int nMaxCount);
20
+ '@
21
+
22
+ $WinAPI = Add-Type -MemberDefinition $signature `
23
+ -Name WinAPI -Namespace IdentifyConsoleWindow -PassThru
24
+
25
+ if (!$WinAPI::SetConsoleTitle("ConsoleWindowScript")) {
26
+ echo "error: could not change console title -- is a console attached?"
27
+ exit 1
28
+ } else {
29
+ echo "note: successfully set console title to ""ConsoleWindowScript""."
30
+ }
31
+
32
+ $hwnd = $WinAPI::GetConsoleWindow()
33
+ if ($hwnd -eq 0) {
34
+ echo "note: GetConsoleWindow returned NULL."
35
+ } else {
36
+ echo "note: GetConsoleWindow returned 0x$($hwnd.ToString("X"))."
37
+ $sb = New-Object System.Text.StringBuilder -ArgumentList 4096
38
+ if ($WinAPI::GetWindowText($hwnd, $sb, $sb.Capacity)) {
39
+ $title = $sb.ToString()
40
+ echo "note: GetWindowText returned ""${title}""."
41
+ if ($title -eq "ConsoleWindowScript") {
42
+ echo "success!"
43
+ } else {
44
+ echo "error: expected to see ""ConsoleWindowScript""."
45
+ echo " (Perhaps the console window is on a different window station?)"
46
+ }
47
+ } else {
48
+ echo "error: GetWindowText could not read the window title."
49
+ echo " (Perhaps the console window is on a different window station?)"
50
+ }
51
+ }
@@ -0,0 +1,87 @@
1
+ // Determines whether this is a new console by testing whether MARK moves the
2
+ // cursor.
3
+ //
4
+ // WARNING: This test program may behave erratically if run under winpty.
5
+ //
6
+
7
+ #include <windows.h>
8
+
9
+ #include <stdio.h>
10
+ #include <string.h>
11
+
12
+ #include "TestUtil.cc"
13
+
14
+ const int SC_CONSOLE_MARK = 0xFFF2;
15
+ const int SC_CONSOLE_SELECT_ALL = 0xFFF5;
16
+
17
+ static COORD getWindowPos(HANDLE conout) {
18
+ CONSOLE_SCREEN_BUFFER_INFO info = {};
19
+ BOOL ret = GetConsoleScreenBufferInfo(conout, &info);
20
+ ASSERT(ret && "GetConsoleScreenBufferInfo failed");
21
+ return { info.srWindow.Left, info.srWindow.Top };
22
+ }
23
+
24
+ static COORD getWindowSize(HANDLE conout) {
25
+ CONSOLE_SCREEN_BUFFER_INFO info = {};
26
+ BOOL ret = GetConsoleScreenBufferInfo(conout, &info);
27
+ ASSERT(ret && "GetConsoleScreenBufferInfo failed");
28
+ return {
29
+ static_cast<short>(info.srWindow.Right - info.srWindow.Left + 1),
30
+ static_cast<short>(info.srWindow.Bottom - info.srWindow.Top + 1)
31
+ };
32
+ }
33
+
34
+ static COORD getCursorPos(HANDLE conout) {
35
+ CONSOLE_SCREEN_BUFFER_INFO info = {};
36
+ BOOL ret = GetConsoleScreenBufferInfo(conout, &info);
37
+ ASSERT(ret && "GetConsoleScreenBufferInfo failed");
38
+ return info.dwCursorPosition;
39
+ }
40
+
41
+ static void setCursorPos(HANDLE conout, COORD pos) {
42
+ BOOL ret = SetConsoleCursorPosition(conout, pos);
43
+ ASSERT(ret && "SetConsoleCursorPosition failed");
44
+ }
45
+
46
+ int main() {
47
+ const HANDLE conout = openConout();
48
+ const HWND hwnd = GetConsoleWindow();
49
+ ASSERT(hwnd != NULL && "GetConsoleWindow() returned NULL");
50
+
51
+ // With the legacy console, the Mark command moves the the cursor to the
52
+ // top-left cell of the visible console window. Determine whether this
53
+ // is the new console by seeing if the cursor moves.
54
+
55
+ const auto windowSize = getWindowSize(conout);
56
+ if (windowSize.X <= 1) {
57
+ printf("Error: console window must be at least 2 columns wide\n");
58
+ trace("Error: console window must be at least 2 columns wide");
59
+ return 1;
60
+ }
61
+
62
+ bool cursorMoved = false;
63
+ const auto initialPos = getCursorPos(conout);
64
+
65
+ const auto windowPos = getWindowPos(conout);
66
+ setCursorPos(conout, { static_cast<short>(windowPos.X + 1), windowPos.Y });
67
+
68
+ {
69
+ const auto posA = getCursorPos(conout);
70
+ SendMessage(hwnd, WM_SYSCOMMAND, SC_CONSOLE_MARK, 0);
71
+ const auto posB = getCursorPos(conout);
72
+ cursorMoved = memcmp(&posA, &posB, sizeof(posA)) != 0;
73
+ SendMessage(hwnd, WM_CHAR, 27, 0x00010001); // Send ESCAPE
74
+ }
75
+
76
+ setCursorPos(conout, initialPos);
77
+
78
+ if (cursorMoved) {
79
+ printf("Legacy console (i.e. MARK moved cursor)\n");
80
+ trace("Legacy console (i.e. MARK moved cursor)");
81
+ } else {
82
+ printf("Windows 10 new console (i.e MARK did not move cursor)\n");
83
+ trace("Windows 10 new console (i.e MARK did not move cursor)");
84
+ }
85
+
86
+ return 0;
87
+ }
@@ -0,0 +1,90 @@
1
+ Introduction
2
+ ============
3
+
4
+ The only specification I could find describing mouse input escape sequences
5
+ was the /usr/share/doc/xterm/ctlseqs.txt.gz file installed on my Ubuntu
6
+ machine.
7
+
8
+ Here are the relevant escape sequences:
9
+
10
+ * [ON] CSI '?' M 'h' Enable mouse input mode M
11
+ * [OFF] CSI '?' M 'l' Disable mouse input mode M
12
+ * [EVT] CSI 'M' F X Y Mouse event (default or mode 1005)
13
+ * [EVT6] CSI '<' F ';' X ';' Y 'M' Mouse event with mode 1006
14
+ * [EVT6] CSI '<' F ';' X ';' Y 'm' Mouse event with mode 1006 (up)
15
+ * [EVT15] CSI F ';' X ';' Y 'M' Mouse event with mode 1015
16
+
17
+ The first batch of modes affect what events are reported:
18
+
19
+ * 9: Presses only (not as well-supported as the other modes)
20
+ * 1000: Presses and releases
21
+ * 1002: Presses, releases, and moves-while-pressed
22
+ * 1003: Presses, releases, and all moves
23
+
24
+ The next batch of modes affect the encoding of the mouse events:
25
+
26
+ * 1005: The X and Y coordinates are UTF-8 codepoints rather than bytes.
27
+ * 1006: Use the EVT6 sequences instead of EVT
28
+ * 1015: Use the EVT15 sequence instead of EVT (aka URVXT-mode)
29
+
30
+ Support for modes in existing terminals
31
+ =======================================
32
+
33
+ | 9 1000 1002 1003 | 1004 | overflow | defhi | 1005 1006 1015
34
+ ---------------------------------+---------------------+------+--------------+-------+----------------
35
+ Eclipse TM Terminal (Neon) | _ _ _ _ | _ | n/a | n/a | _ _ _
36
+ gnome-terminal 3.6.2 | X X X X | _ | suppressed*b | 0x07 | _ X X
37
+ iTerm2 2.1.4 | _ X X X | OI | wrap*z | n/a | X X X
38
+ jediterm/IntelliJ | _ X X X | _ | ch='?' | 0xff | X X X
39
+ Konsole 2.13.2 | _ X X *a | _ | suppressed | 0xff | X X X
40
+ mintty 2.2.2 | X X X X | OI | ch='\0' | 0xff | X X X
41
+ putty 0.66 | _ X X _ | _ | suppressed | 0xff | _ X X
42
+ rxvt 2.7.10 | X X _ _ | _ | wrap*z | n/a | _ _ _
43
+ screen(under xterm) | X X X X | _ | suppressed | 0xff | _ _ _
44
+ urxvt 9.21 | X X X X | _ | wrap*z | n/a | X _ X
45
+ xfce4-terminal 0.6.3 (GTK2 VTE) | X X X X | _ | wrap | n/a | _ _ _
46
+ xterm | X X X X | OI | ch='\0' | 0xff | X X X
47
+
48
+ *a: Mode 1003 is handled the same way as 1002.
49
+ *b: The coordinate wraps from 0xff to 0x00, then maxs out at 0x07. I'm
50
+ guessing this behavior is a bug? I'm using the Xubuntu 14.04
51
+ gnome-terminal.
52
+ *z: These terminals have a bug where column 224 (and row 224, presumably)
53
+ yields a truncated escape sequence. 224 + 32 is 0, so it would normally
54
+ yield `CSI 'M' F '\0' Y`, but the '\0' is interpreted as a NUL-terminator.
55
+
56
+ Problem 1: How do these flags work?
57
+ ===================================
58
+
59
+ Terminals accept the OFF sequence with any of the input modes. This makes
60
+ little sense--there are two multi-value settings, not seven independent flags!
61
+
62
+ All the terminals handle Granularity the same way. ON-Granularity sets
63
+ Granularity to the specified value, and OFF-Granularity sets Granularity to
64
+ OFF.
65
+
66
+ Terminals vary in how they handle the Encoding modes. For example:
67
+
68
+ * xterm. ON-Encoding sets Encoding. OFF-Encoding with a non-active Encoding
69
+ has no effect. OFF-Encoding otherwise resets Encoding to Default.
70
+
71
+ * mintty (tested 2.2.2), iTerm2 2.1.4, and jediterm. ON-Encoding sets
72
+ Encoding. OFF-Encoding resets Encoding to Default.
73
+
74
+ * Konsole (tested 2.13.2) seems to configure each encoding method
75
+ independently. The effective Encoding is the first enabled encoding in this
76
+ list:
77
+ - Mode 1006
78
+ - Mode 1015
79
+ - Mode 1005
80
+ - Default
81
+
82
+ * gnome-terminal (tested 3.6.2) also configures each encoding method
83
+ independently. The effective Encoding is the first enabled encoding in
84
+ this list:
85
+ - Mode 1006
86
+ - Mode 1015
87
+ - Default
88
+ Mode 1005 is not supported.
89
+
90
+ * xfce4 terminal 0.6.3 (GTK2 VTE) always outputs the default encoding method.
@@ -0,0 +1,34 @@
1
+ #include <windows.h>
2
+
3
+ #include "TestUtil.cc"
4
+
5
+ int main(int argc, char *argv[]) {
6
+ if (argc != 3 && argc != 5) {
7
+ printf("Usage: %s x y\n", argv[0]);
8
+ printf("Usage: %s x y width height\n", argv[0]);
9
+ return 1;
10
+ }
11
+
12
+ HWND hwnd = GetConsoleWindow();
13
+
14
+ const int x = atoi(argv[1]);
15
+ const int y = atoi(argv[2]);
16
+
17
+ int w = 0, h = 0;
18
+ if (argc == 3) {
19
+ RECT r = {};
20
+ BOOL ret = GetWindowRect(hwnd, &r);
21
+ ASSERT(ret && "GetWindowRect failed on console window");
22
+ w = r.right - r.left;
23
+ h = r.bottom - r.top;
24
+ } else {
25
+ w = atoi(argv[3]);
26
+ h = atoi(argv[4]);
27
+ }
28
+
29
+ BOOL ret = MoveWindow(hwnd, x, y, w, h, TRUE);
30
+ trace("MoveWindow: ret=%d", ret);
31
+ printf("MoveWindow: ret=%d\n", ret);
32
+
33
+ return 0;
34
+ }
@@ -0,0 +1,219 @@
1
+ Test programs
2
+ -------------
3
+
4
+ Cygwin
5
+ emacs
6
+ vim
7
+ mc (Midnight Commander)
8
+ lynx
9
+ links
10
+ less
11
+ more
12
+ wget
13
+
14
+ Capturing the console output
15
+ ----------------------------
16
+
17
+ Initial idea:
18
+
19
+ In the agent, keep track of the remote terminal state for N lines of
20
+ (window+history). Also keep track of the terminal size. Regularly poll for
21
+ changes to the console screen buffer, then use some number of edits to bring
22
+ the remote terminal into sync with the console.
23
+
24
+ This idea seems to have trouble when a Unix terminal is resized. When the
25
+ server receives a resize notification, it can have a hard time figuring out
26
+ what the terminal did. Race conditions might also be a problem.
27
+
28
+ The behavior of the terminal can be tricky:
29
+
30
+ - When the window is expanded by one line, does the terminal add a blank line
31
+ to the bottom or move a line from the history into the top?
32
+
33
+ - When the window is shrunk by one line, does the terminal delete the topmost
34
+ or the bottommost line? Can it delete the line with the cursor?
35
+
36
+ Some popular behaviors for expanding:
37
+ - [all] If there are no history lines, then add a line at the bottom.
38
+ - [konsole] Always add a line at the bottom.
39
+ - [putty,xterm,rxvt] Pull in a history line from the top.
40
+ - [g-t] I can't tell. It seems to add a blank line, until the program writes
41
+ to stdout or until I click the scroll bar, then the output "snaps" back down,
42
+ pulling lines out of the history. I thought I saw different behavior
43
+ between Ubuntu 10.10 and 11.10, so maybe GNOME 3 changed something. Avoid
44
+ using "bash" to test this behavior because "bash" apparently always writes
45
+ the prompt after terminal resize.
46
+
47
+ Some popular behaviors for shrinking:
48
+ - [konsole,putty,xterm,rxvt] If the line at the bottom is blank, then delete
49
+ it. Otherwise, move the topmost line into history.
50
+ - [g-t] If the line at the bottom has not been touched, then delete it.
51
+ Otherwise, move the topmost line into history.
52
+
53
+ (TODO: I need to test my theories about the terminal behavior better still.
54
+ It's interesting to see how g-t handles clear differently than every other
55
+ terminal.)
56
+
57
+ There is an ANSI escape sequence (DSR) that sends the current cursor location
58
+ to the terminal's input. One idea I had was to use this code to figure out how
59
+ the terminal had handled a resize. I currently think this idea won't work due
60
+ to race conditions.
61
+
62
+ Newer idea:
63
+
64
+ Keep track of the last N lines that have been sent to the remote terminal.
65
+ Poll for changes to console output. When the output changes, send just the
66
+ changed content to the terminal. In particular:
67
+ - Don't send a cursor position (CUP) code. Instead, if the line that's 3
68
+ steps up from the latest line changes, send a relative cursor up (CUU)
69
+ code. It's OK to send an absolute column number code (CHA).
70
+ - At least in general, don't try to send complete screenshots of the current
71
+ console window.
72
+
73
+ The idea is that sending just the changes should have good behavior for streams
74
+ of output, even when those streams modify the output (e.g. an archiver, or
75
+ maybe a downloader/packager/wget). I need to think about whether this works
76
+ for full-screen programs (e.g. emacs, less, lynx, the above list of programs).
77
+
78
+ I noticed that console programs don't typically modify the window or buffer
79
+ coordinates. edit.com is an exception.
80
+
81
+ I tested the pager in native Python (more?), and I verified that ENTER and SPACE
82
+ both paid no attention to the location of the console window within the screen
83
+ buffer. This makes sense -- why would they care? The Cygwin less, on the other
84
+ hand, does care. If I scroll the window up, then Cygwin less will write to a
85
+ position within the window. I didn't really expect this behavior, but it
86
+ doesn't seem to be a problem.
87
+
88
+ Setting up a TestNetServer service
89
+ ----------------------------------
90
+
91
+ First run the deploy.sh script to copy files into deploy. Make sure
92
+ TestNetServer.exe will run in a bare environment (no MinGW or Qt in the path).
93
+
94
+ Install the Windows Server 2003 Resource Kit. It will have two programs in it,
95
+ instsrv and srvany.
96
+
97
+ Run:
98
+
99
+ InstSrv TestNetServer <path-to-srvany>\srvany.exe
100
+
101
+ This creates a service named "TestNetServer" that uses the Microsoft service
102
+ wrapper. To configure the new service to run TestNetServer, set a registry
103
+ value:
104
+
105
+ [HKLM\SYSTEM\CurrentControlSet\Services\TestNetServer\Parameters]
106
+ Application=<full-path>\TestNetServer.exe
107
+
108
+ Also see http://www.iopus.com/guides/srvany.htm.
109
+
110
+ To remove the service, run:
111
+
112
+ InstSrv TestNetServer REMOVE
113
+
114
+ TODO
115
+ ----
116
+
117
+ Agent: When resizing the console, consider whether to add lines to the top
118
+ or bottom. I remember thinking the current behavior was wrong for some
119
+ application, but I forgot which one.
120
+
121
+ Make the font as small as possible. The console window dimensions are limited by
122
+ the screen size, so making the font small reduces an unnecessary limitation on the
123
+ PseudoConsole size. There's a documented Vista/Win7 API for this
124
+ (SetCurrentConsoleFontEx), and apparently WinXP has an undocumented API
125
+ (SetConsoleFont):
126
+ http://blogs.microsoft.co.il/blogs/pavely/archive/2009/07/23/changing-console-fonts.aspx
127
+
128
+ Make the agent work with DOS programs like edit and qbasic.
129
+ - Detect that the terminal program has resized the window/buffer and enter a
130
+ simple just-scrape-and-dont-resize mode. Track the client window size and
131
+ send the intersection of the console and the agent's client.
132
+ - I also need to generate keyboard scan codes.
133
+ - Solve the NTVDM.EXE console shutdown problem, probably by ignoring NTVDM.EXE
134
+ when it appears on the GetConsoleProcessList list.
135
+
136
+ Rename the agent? Is the term "proxy" more accurate?
137
+
138
+ Optimize the polling. e.g. Use a longer poll interval when the console is idle.
139
+ Do a minimal poll that checks whether the sync marker or window has moved.
140
+
141
+ Increase the console buffer size to ~9000 lines. Beware making it so big that
142
+ reading the sync column exhausts the 32KB conhost<->agent heap.
143
+
144
+ Reduce the memory overhead of the agent. The agent's m_bufferData array can
145
+ be small (a few hundred lines?) relative to the console buffer size.
146
+
147
+ Try to handle console background color better.
148
+ Unix terminal emulators have a user-configurable foreground and background
149
+ color, and for best results, the agent really needs to avoid changing the colors,
150
+ especially the background color. It's undesirable/ugly to SSH into a machine
151
+ and see the command prompt change the colors. It's especially ugly that the
152
+ terminal retains its original colors and only drawn cells get the new colors.
153
+ (e.g. Resizing the window to the right uses the local terminal colors rather
154
+ than the remote colors.) It's especially ugly in gnome-terminal, which draws
155
+ user-configurable black as black, but VT100 black as dark-gray.
156
+ If there were a way to query the terminal emulator's colors, then I could
157
+ match the console's colors to the terminal and everything would just work. As
158
+ far as I know, that's not possible.
159
+ I thought of a kludge that might work. Instead of translating console white
160
+ and black to VT/100 white and black, I would translate them to "reset" and
161
+ "invert". I'd translate other colors normally. This approach should produce
162
+ ideal results for command-line work and tolerable results for full-screen
163
+ programs without configuration. Configuring the agent for black-on-white or
164
+ white-on-black would produce ideal results in all situations.
165
+ This kludge only really applies to the SSH application. For a Win32 Konsole
166
+ application, it should be easy to get the colors right all the time.
167
+
168
+ Try using the screen reader API:
169
+ - To eliminate polling.
170
+ - To detect when a line wraps. When a line wraps, it'd be nice not to send a
171
+ CRLF to the terminal emulator so copy-and-paste works better.
172
+ - To detect hard tabs with Cygwin.
173
+
174
+ Implement VT100/ANSI escape sequence recognition for input. Decide where this
175
+ functionality belongs. PseudoConsole.dll? Disambiguating ESC from an escape
176
+ sequence might be tricky. For the SSH server, I was thinking that when a small
177
+ SSH payload ended with an ESC character, I could assume the character was really
178
+ an ESC keypress, on the assumption that if it were an escape sequence, the
179
+ payload would probably contain the whole sequence. I'm not sure this works,
180
+ especially if there's a lot of other traffic multiplexed on the SSH socket.
181
+
182
+ Support Unicode.
183
+ - Some DOS programs draw using line/box characters. Can these characters be
184
+ translated to the Unicode equivalents?
185
+
186
+ Create automated tests.
187
+
188
+ Experiment with the Terminator emulator, an emulator that doesn't wrap lines.
189
+ How many columns does it report having? What column does it report the cursor
190
+ in as it's writing past the right end of the window? Will Terminator be a
191
+ problem if I implement line wrapping detection in the agent?
192
+
193
+ BUG: After the unix-adapter/pconsole.exe program exits, the blinking cursor is
194
+ replaced with a hidden cursor.
195
+
196
+ Fix assert() in the agent. If it fails, the failure message needs to be
197
+ reported somewhere. Pop up a dialog box? Maybe switch the active desktop,
198
+ then show a dialog box?
199
+
200
+ TODO: There's already a pconsole project on GitHub. Maybe rename this project
201
+ to something else? winpty?
202
+
203
+ TODO: Can the DebugServer system be replaced with OutputDebugString? How
204
+ do we decide whose processes' output to collect?
205
+
206
+ TODO: Three executables:
207
+ build/winpty-agent.exe
208
+ build/winpty.dll
209
+ build/console.exe
210
+
211
+ BUG: Run the pconsole.exe inside another console. As I type dir, I see this:
212
+ D:\rprichard\pconsole>
213
+ D:\rprichard\pconsole>d
214
+ D:\rprichard\pconsole>di
215
+ D:\rprichard\pconsole>dir
216
+ In the output of "dir", every other line is blank.
217
+ There was a bug in Terminal::sendLine that was causing this to happen
218
+ frequently. Now that I fixed it, this bug should only manifest on lines
219
+ whose last column is not a space (i.e. a full line).
@@ -0,0 +1,27 @@
1
+ #include <windows.h>
2
+
3
+ #include <assert.h>
4
+ #include <locale.h>
5
+ #include <stdio.h>
6
+
7
+ #include <iostream>
8
+
9
+ int main() {
10
+ setlocale(LC_ALL, "");
11
+
12
+ OSVERSIONINFOEXW info = {0};
13
+ info.dwOSVersionInfoSize = sizeof(info);
14
+ assert(GetVersionExW((OSVERSIONINFOW*)&info));
15
+
16
+ printf("dwMajorVersion = %d\n", (int)info.dwMajorVersion);
17
+ printf("dwMinorVersion = %d\n", (int)info.dwMinorVersion);
18
+ printf("dwBuildNumber = %d\n", (int)info.dwBuildNumber);
19
+ printf("dwPlatformId = %d\n", (int)info.dwPlatformId);
20
+ printf("szCSDVersion = %ls\n", info.szCSDVersion);
21
+ printf("wServicePackMajor = %d\n", info.wServicePackMajor);
22
+ printf("wServicePackMinor = %d\n", info.wServicePackMinor);
23
+ printf("wSuiteMask = 0x%x\n", (unsigned int)info.wSuiteMask);
24
+ printf("wProductType = 0x%x\n", (unsigned int)info.wProductType);
25
+
26
+ return 0;
27
+ }
@@ -0,0 +1,101 @@
1
+ //
2
+ // Verify that console selection blocks writes to an inactive console screen
3
+ // buffer. Writes TEST PASSED or TEST FAILED to the popup console window.
4
+ //
5
+
6
+ #include <windows.h>
7
+ #include <stdio.h>
8
+
9
+ #include <string>
10
+
11
+ #include "TestUtil.cc"
12
+
13
+ const int SC_CONSOLE_MARK = 0xFFF2;
14
+ const int SC_CONSOLE_SELECT_ALL = 0xFFF5;
15
+
16
+ bool g_useMark = false;
17
+
18
+ CALLBACK DWORD pausingThread(LPVOID dummy)
19
+ {
20
+ HWND hwnd = GetConsoleWindow();
21
+ trace("Sending selection to freeze");
22
+ SendMessage(hwnd, WM_SYSCOMMAND,
23
+ g_useMark ? SC_CONSOLE_MARK :
24
+ SC_CONSOLE_SELECT_ALL,
25
+ 0);
26
+ Sleep(1000);
27
+ trace("Sending escape WM_CHAR to unfreeze");
28
+ SendMessage(hwnd, WM_CHAR, 27, 0x00010001);
29
+ Sleep(1000);
30
+ }
31
+
32
+ static HANDLE createBuffer() {
33
+ HANDLE buf = CreateConsoleScreenBuffer(
34
+ GENERIC_READ | GENERIC_WRITE,
35
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
36
+ NULL,
37
+ CONSOLE_TEXTMODE_BUFFER,
38
+ NULL);
39
+ ASSERT(buf != INVALID_HANDLE_VALUE);
40
+ return buf;
41
+ }
42
+
43
+ static void runTest(bool useMark, bool createEarly) {
44
+ trace("=======================================");
45
+ trace("useMark=%d createEarly=%d", useMark, createEarly);
46
+ g_useMark = useMark;
47
+ HANDLE buf = INVALID_HANDLE_VALUE;
48
+
49
+ if (createEarly) {
50
+ buf = createBuffer();
51
+ }
52
+
53
+ CreateThread(NULL, 0,
54
+ pausingThread, NULL,
55
+ 0, NULL);
56
+ Sleep(500);
57
+
58
+ if (!createEarly) {
59
+ trace("Creating buffer");
60
+ TimeMeasurement tm1;
61
+ buf = createBuffer();
62
+ const double elapsed1 = tm1.elapsed();
63
+ if (elapsed1 >= 0.250) {
64
+ printf("!!! TEST FAILED !!!\n");
65
+ Sleep(2000);
66
+ return;
67
+ }
68
+ }
69
+
70
+ trace("Writing to aux buffer");
71
+ TimeMeasurement tm2;
72
+ DWORD actual = 0;
73
+ BOOL ret = WriteConsoleW(buf, L"HI", 2, &actual, NULL);
74
+ const double elapsed2 = tm2.elapsed();
75
+ trace("Writing to aux buffer: finished: ret=%d actual=%d (elapsed=%1.3f)", ret, actual, elapsed2);
76
+ if (elapsed2 < 0.250) {
77
+ printf("!!! TEST FAILED !!!\n");
78
+ } else {
79
+ printf("TEST PASSED\n");
80
+ }
81
+ Sleep(2000);
82
+ }
83
+
84
+ int main(int argc, char **argv) {
85
+ if (argc == 1) {
86
+ startChildProcess(L"child");
87
+ return 0;
88
+ }
89
+
90
+ std::string arg = argv[1];
91
+ if (arg == "child") {
92
+ for (int useMark = 0; useMark <= 1; useMark++) {
93
+ for (int createEarly = 0; createEarly <= 1; createEarly++) {
94
+ runTest(useMark, createEarly);
95
+ }
96
+ }
97
+ printf("done...\n");
98
+ Sleep(1000);
99
+ }
100
+ return 0;
101
+ }