Skip to content
This repository was archived by the owner on Oct 5, 2022. It is now read-only.

Commit 14927a3

Browse files
Merge pull request #3 from theia-ide/mp/uplift-0.9.0
uplift: 0.9.0
2 parents 20d498c + 921392d commit 14927a3

40 files changed

+1303
-279
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ npm-debug.log
1111
package-lock.json
1212
fixtures/space folder/
1313
.vscode/settings.json
14+
.vscode/ipch/

.vscode/launch.json

+35-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
11
{
2-
// Use IntelliSense to learn about possible attributes.
3-
// Hover to view descriptions of existing attributes.
4-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5-
"version": "0.2.0",
6-
"configurations": [
7-
{
8-
"type": "node",
9-
"request": "attach",
10-
"name": "Attach to process ID",
11-
"processId": "${command:PickProcess}"
12-
}
13-
]
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Unit Tests",
11+
"cwd": "${workspaceRoot}",
12+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/mocha",
13+
"windows": {
14+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/mocha.cmd"
15+
},
16+
"runtimeArgs": [
17+
"--colors",
18+
"--recursive",
19+
"${workspaceRoot}/lib/**/*.test.js"
20+
],
21+
"env": {
22+
"NODE_PATH": "${workspaceRoot}/lib"
23+
},
24+
"sourceMaps": true,
25+
"outFiles": [
26+
"${workspaceRoot}/lib/**/*.js"
27+
],
28+
"internalConsoleOptions": "openOnSessionStart"
29+
},
30+
{
31+
"type": "node",
32+
"request": "attach",
33+
"name": "Attach to process ID",
34+
"processId": "${command:PickProcess}"
35+
}
36+
]
1437
}

README.md

+45-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# node-pty
22

3-
[![Build Status](https://dev.azure.com/vscode/node-pty/_apis/build/status/Microsoft.node-pty)](https://dev.azure.com/vscode/node-pty/_apis/build/status/Microsoft.node-pty?branchName=master)
3+
[![Build Status](https://dev.azure.com/vscode/node-pty/_apis/build/status/Microsoft.node-pty)](https://dev.azure.com/vscode/node-pty/_build/latest?definitionId=11)
44

55
`forkpty(3)` bindings for node.js. This allows you to fork processes with pseudoterminal file descriptors. It returns a terminal object which allows reads and writes.
66

@@ -21,8 +21,14 @@ This is useful for:
2121
- [Script Runner](https://github.com/ioquatix/script-runner) for Atom.
2222
- [Theia](https://github.com/theia-ide/theia)
2323
- [FreeMAN](https://github.com/matthew-matvei/freeman) file manager
24-
- [atom-xterm](https://atom.io/packages/atom-xterm) - Atom plugin for providing terminals inside your Atom workspace.
25-
- [Termination](https://atom.io/packages/termination) - Another Atom plugin that provides terminals inside your Atom workspace.
24+
- [terminus](https://atom.io/packages/terminus) - An Atom plugin for providing terminals inside your Atom workspace.
25+
- [x-terminal](https://atom.io/packages/x-terminal) - Also an Atom plugin that provides terminals inside your Atom workspace.
26+
- [Termination](https://atom.io/packages/termination) - Also an Atom plugin that provides terminals inside your Atom workspace.
27+
- [atom-xterm](https://atom.io/packages/atom-xterm) - Also an Atom plugin that provides terminals inside your Atom workspace.
28+
- [electerm](https://github.com/electerm/electerm) Terminal/SSH/SFTP client(Linux, macOS, Windows).
29+
- [Extraterm](http://extraterm.org/)
30+
- [Wetty](https://github.com/krishnasrinivas/wetty) Browser based Terminal over HTTP and HTTPS
31+
- [nomad](https://github.com/lukebarnard1/nomad-term)
2632

2733
Do you use node-pty in your application as well? Please open a [Pull Request](https://github.com/Tyriar/node-pty/pulls) to include it here. We would love to have it in our list.
2834

@@ -68,6 +74,10 @@ npm run tsc
6874
sudo apt install -y make python build-essential
6975
```
7076

77+
The following are also needed:
78+
79+
- Node.JS 10+
80+
7181
### Windows
7282

7383
`npm install` requires some tools to be present in the system like Python and C++ compiler. Windows users can easily install them by running the following command in PowerShell as administrator. For more information see https://github.com/felixrieseberg/windows-build-tools:
@@ -76,7 +86,10 @@ sudo apt install -y make python build-essential
7686
npm install --global --production windows-build-tools
7787
```
7888

79-
The Windows SDK is also needed which can be [downloaded here](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk). Only the "Desktop C++ Apps" components are needed to be installed.
89+
The following are also needed:
90+
91+
- [Windows SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk) - only the "Desktop C++ Apps" components are needed to be installed
92+
- Node.JS 10+
8093

8194
## Debugging
8295

@@ -90,14 +103,41 @@ All processes launched from node-pty will launch at the same permission level of
90103

91104
Note that node-pty is not thread safe so running it across multiple worker threads in node.js could cause issues.
92105

106+
## Flow Control
107+
108+
Automatic flow control can be enabled by either providing `handleFlowControl = true` in the constructor options or setting it later on:
109+
110+
```js
111+
const PAUSE = '\x13'; // XOFF
112+
const RESUME = '\x11'; // XON
113+
114+
const ptyProcess = pty.spawn(shell, [], {handleFlowControl: true});
115+
116+
// flow control in action
117+
ptyProcess.write(PAUSE); // pty will block and pause the slave program
118+
...
119+
ptyProcess.write(RESUME); // pty will enter flow mode and resume the slave program
120+
121+
// temporarily disable/re-enable flow control
122+
ptyProcess.handleFlowControl = false;
123+
...
124+
ptyProcess.handleFlowControl = true;
125+
```
126+
127+
By default `PAUSE` and `RESUME` are XON/XOFF control codes (as shown above). To avoid conflicts in environments that use these control codes for different purposes the messages can be customized as `flowControlPause: string` and `flowControlResume: string` in the constructor options. `PAUSE` and `RESUME` are not passed to the underlying pseudoterminal if flow control is enabled.
128+
93129
## Troubleshooting
94130

95-
**Powershell gives error 8009001d**
131+
### Powershell gives error 8009001d
96132

97133
> Internal Windows PowerShell error. Loading managed Windows PowerShell failed with error 8009001d.
98134
99135
This happens when PowerShell is launched with no `SystemRoot` environment variable present.
100136

137+
### ConnectNamedPipe failed: Windows error 232
138+
139+
This error can occur due to anti-virus software intercepting winpty from creating a pty. To workaround this you can exclude this file from your anti-virus scanning `node-pty\build\Release\winpty-agent.exe`
140+
101141
## pty.js
102142

103143
This project is forked from [chjj/pty.js](https://github.com/chjj/pty.js) with the primary goals being to provide better support for later Node.JS versions and Windows.

azure-pipelines.yml

+61-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@ jobs:
77
- job: Linux
88
pool:
99
vmImage: 'ubuntu-16.04'
10+
strategy:
11+
matrix:
12+
node_8_x:
13+
node_version: 8.x
14+
node_9_x:
15+
node_version: 9.x
16+
node_10_x:
17+
node_version: 10.x
18+
node_11_x:
19+
node_version: 11.x
20+
node_12_x:
21+
node_version: 12.x
1022
steps:
1123
- task: NodeTool@0
1224
inputs:
13-
versionSpec: '8.x'
25+
versionSpec: $(node_version)
1426
displayName: 'Install Node.js'
1527
- script: |
1628
npm i
@@ -21,13 +33,26 @@ jobs:
2133
- script: |
2234
npm run lint
2335
displayName: 'Lint'
36+
2437
- job: macOS
2538
pool:
2639
vmImage: 'xcode9-macos10.13'
40+
strategy:
41+
matrix:
42+
node_8_x:
43+
node_version: 8.x
44+
node_9_x:
45+
node_version: 9.x
46+
node_10_x:
47+
node_version: 10.x
48+
node_11_x:
49+
node_version: 11.x
50+
node_12_x:
51+
node_version: 12.x
2752
steps:
2853
- task: NodeTool@0
2954
inputs:
30-
versionSpec: '8.x'
55+
versionSpec: $(node_version)
3156
displayName: 'Install Node.js'
3257
- script: |
3358
npm i
@@ -38,13 +63,26 @@ jobs:
3863
- script: |
3964
npm run lint
4065
displayName: 'Lint'
66+
4167
- job: Windows
4268
pool:
4369
vmImage: 'vs2017-win2016'
70+
strategy:
71+
matrix:
72+
node_8_x:
73+
node_version: 8.x
74+
node_9_x:
75+
node_version: 9.x
76+
node_10_x:
77+
node_version: 10.x
78+
node_11_x:
79+
node_version: 11.x
80+
node_12_x:
81+
node_version: 12.x
4482
steps:
4583
- task: NodeTool@0
4684
inputs:
47-
versionSpec: '8.x'
85+
versionSpec: $(node_version)
4886
displayName: 'Install Node.js'
4987
- script: |
5088
npm i
@@ -55,3 +93,23 @@ jobs:
5593
- script: |
5694
npm run lint
5795
displayName: 'Lint'
96+
97+
- job: Release
98+
dependsOn:
99+
- Linux
100+
- macOS
101+
- Windows
102+
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
103+
pool:
104+
vmImage: 'ubuntu-16.04'
105+
steps:
106+
- task: NodeTool@0
107+
inputs:
108+
versionSpec: '8.x'
109+
displayName: 'Install Node.js'
110+
- script: |
111+
npm i
112+
displayName: 'Install dependencies and build'
113+
- script: |
114+
NPM_AUTH_TOKEN="$(NPM_AUTH_TOKEN)" node ./scripts/publish.js
115+
displayName: 'Publish to npm'

binding.gyp

+1-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@
5555
'src/unix/pty.cc'
5656
],
5757
'libraries': [
58-
'-lutil',
59-
'-L/usr/lib',
60-
'-L/usr/local/lib'
58+
'-lutil'
6159
],
6260
'conditions': [
6361
# http://www.gnu.org/software/gnulib/manual/html_node/forkpty.html

deps/winpty/RELEASES.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# Next Version
2+
3+
Input handling changes:
4+
5+
* Improve Ctrl-C handling with programs that use unprocessed input. (e.g.
6+
Ctrl-C now cancels input with PowerShell on Windows 10.)
7+
[#116](https://github.com/rprichard/winpty/issues/116)
8+
* Fix a theoretical issue with input event ordering.
9+
[#117](https://github.com/rprichard/winpty/issues/117)
10+
* Ctrl/Shift+{Arrow,Home,End} keys now work with IntelliJ.
11+
[#118](https://github.com/rprichard/winpty/issues/118)
12+
113
# Version 0.4.3 (2017-05-17)
214

315
Input handling changes:

deps/winpty/VERSION.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.3
1+
0.4.4-dev

deps/winpty/src/agent/ConsoleInput.cc

+45-13
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,38 @@ void ConsoleInput::doWrite(bool isEof)
343343
idx += charSize;
344344
}
345345
m_byteQueue.erase(0, idx);
346+
flushInputRecords(records);
347+
}
348+
349+
void ConsoleInput::flushInputRecords(std::vector<INPUT_RECORD> &records)
350+
{
351+
if (records.size() == 0) {
352+
return;
353+
}
346354
DWORD actual = 0;
347-
if (records.size() > 0) {
348-
if (!WriteConsoleInputW(m_conin, records.data(), records.size(), &actual)) {
349-
trace("WriteConsoleInputW failed");
350-
}
355+
if (!WriteConsoleInputW(m_conin, records.data(), records.size(), &actual)) {
356+
trace("WriteConsoleInputW failed");
351357
}
358+
records.clear();
359+
}
360+
361+
// This behavior isn't strictly correct, because the keypresses (probably?)
362+
// adopt the keyboard state (e.g. Ctrl/Alt/Shift modifiers) of the current
363+
// window station's keyboard, which has no necessary relationship to the winpty
364+
// instance. It's unlikely to be an issue in practice, but it's conceivable.
365+
// (Imagine a foreground SSH server, where the local user holds down Ctrl,
366+
// while the remote user tries to use WSL navigation keys.) I suspect using
367+
// the BackgroundDesktop mechanism in winpty would fix the problem.
368+
//
369+
// https://github.com/rprichard/winpty/issues/116
370+
static void sendKeyMessage(HWND hwnd, bool isKeyDown, uint16_t virtualKey)
371+
{
372+
uint32_t scanCode = MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC);
373+
if (scanCode > 255) {
374+
scanCode = 0;
375+
}
376+
SendMessage(hwnd, isKeyDown ? WM_KEYDOWN : WM_KEYUP, virtualKey,
377+
(scanCode << 16) | 1u | (isKeyDown ? 0u : 0xc0000000u));
352378
}
353379

354380
int ConsoleInput::scanInput(std::vector<INPUT_RECORD> &records,
@@ -359,9 +385,20 @@ int ConsoleInput::scanInput(std::vector<INPUT_RECORD> &records,
359385
ASSERT(inputSize >= 1);
360386

361387
// Ctrl-C.
388+
//
389+
// In processed mode, use GenerateConsoleCtrlEvent so that Ctrl-C handlers
390+
// are called. GenerateConsoleCtrlEvent unfortunately doesn't interrupt
391+
// ReadConsole calls[1]. Using WM_KEYDOWN/UP fixes the ReadConsole
392+
// problem, but breaks in background window stations/desktops.
393+
//
394+
// In unprocessed mode, there's an entry for Ctrl-C in the SimpleEncoding
395+
// table in DefaultInputMap.
396+
//
397+
// [1] https://github.com/rprichard/winpty/issues/116
362398
if (input[0] == '\x03' && (inputConsoleMode() & ENABLE_PROCESSED_INPUT)) {
399+
flushInputRecords(records);
363400
trace("Ctrl-C");
364-
BOOL ret = GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
401+
const BOOL ret = GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
365402
trace("GenerateConsoleCtrlEvent: %d", ret);
366403
return 1;
367404
}
@@ -652,17 +689,12 @@ void ConsoleInput::appendKeyPress(std::vector<INPUT_RECORD> &records,
652689
virtualKey == VK_HOME ||
653690
virtualKey == VK_END) &&
654691
!ctrl && !leftAlt && !rightAlt && !shift) {
692+
flushInputRecords(records);
655693
if (hasDebugInput) {
656694
trace("sending keypress to console HWND");
657695
}
658-
uint32_t scanCode = MapVirtualKey(virtualKey, MAPVK_VK_TO_VSC);
659-
if (scanCode > 255) {
660-
scanCode = 0;
661-
}
662-
SendMessage(m_console.hwnd(), WM_KEYDOWN, virtualKey,
663-
(scanCode << 16) | 1u);
664-
SendMessage(m_console.hwnd(), WM_KEYUP, virtualKey,
665-
(scanCode << 16) | (1u | (1u << 30) | (1u << 31)));
696+
sendKeyMessage(m_console.hwnd(), true, virtualKey);
697+
sendKeyMessage(m_console.hwnd(), false, virtualKey);
666698
return;
667699
}
668700

deps/winpty/src/agent/ConsoleInput.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ConsoleInput
4848

4949
private:
5050
void doWrite(bool isEof);
51+
void flushInputRecords(std::vector<INPUT_RECORD> &records);
5152
int scanInput(std::vector<INPUT_RECORD> &records,
5253
const char *input,
5354
int inputSize,

0 commit comments

Comments
 (0)