bare-tty 2.1.0 → 2.1.2
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.
- package/index.js +28 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -25,6 +25,8 @@ exports.ReadStream = class TTYReadStream extends Readable {
|
|
|
25
25
|
this._onread,
|
|
26
26
|
this._onclose
|
|
27
27
|
)
|
|
28
|
+
|
|
29
|
+
TTYReadStream._streams.add(this)
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
get isTTY () {
|
|
@@ -43,9 +45,17 @@ exports.ReadStream = class TTYReadStream extends Readable {
|
|
|
43
45
|
cb(null)
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
_predestroy () {
|
|
49
|
+
if (this._handle === null) return
|
|
50
|
+
binding.close(this._handle)
|
|
51
|
+
TTYReadStream._streams.delete(this)
|
|
52
|
+
}
|
|
53
|
+
|
|
46
54
|
_destroy (cb) {
|
|
55
|
+
if (this._handle === null) return cb(null)
|
|
47
56
|
this._pendingDestroy = cb
|
|
48
57
|
binding.close(this._handle)
|
|
58
|
+
TTYReadStream._streams.delete(this)
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
_continueDestroy () {
|
|
@@ -80,6 +90,8 @@ exports.ReadStream = class TTYReadStream extends Readable {
|
|
|
80
90
|
this._handle = null
|
|
81
91
|
this._continueDestroy()
|
|
82
92
|
}
|
|
93
|
+
|
|
94
|
+
static _streams = new Set()
|
|
83
95
|
}
|
|
84
96
|
|
|
85
97
|
exports.WriteStream = class TTYWriteStream extends Writable {
|
|
@@ -96,6 +108,8 @@ exports.WriteStream = class TTYWriteStream extends Writable {
|
|
|
96
108
|
noop,
|
|
97
109
|
this._onclose
|
|
98
110
|
)
|
|
111
|
+
|
|
112
|
+
TTYWriteStream._streams.add(this)
|
|
99
113
|
}
|
|
100
114
|
|
|
101
115
|
get isTTY () {
|
|
@@ -119,6 +133,7 @@ exports.WriteStream = class TTYWriteStream extends Writable {
|
|
|
119
133
|
_destroy (cb) {
|
|
120
134
|
this._pendingDestroy = cb
|
|
121
135
|
binding.close(this._handle)
|
|
136
|
+
TTYWriteStream._streams.delete(this)
|
|
122
137
|
}
|
|
123
138
|
|
|
124
139
|
_continueWrite (err) {
|
|
@@ -175,6 +190,8 @@ exports.WriteStream = class TTYWriteStream extends Writable {
|
|
|
175
190
|
this._handle = null
|
|
176
191
|
this._continueDestroy()
|
|
177
192
|
}
|
|
193
|
+
|
|
194
|
+
static _streams = new Set()
|
|
178
195
|
}
|
|
179
196
|
|
|
180
197
|
exports.constants = {
|
|
@@ -183,6 +200,17 @@ exports.constants = {
|
|
|
183
200
|
MODE_IO: binding.MODE_IO || 0
|
|
184
201
|
}
|
|
185
202
|
|
|
203
|
+
process
|
|
204
|
+
.on('exit', () => {
|
|
205
|
+
for (const stream of exports.ReadStream._streams) {
|
|
206
|
+
stream.destroy()
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
for (const stream of exports.WriteStream._streams) {
|
|
210
|
+
stream.destroy()
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
|
|
186
214
|
const empty = Buffer.alloc(0)
|
|
187
215
|
|
|
188
216
|
function noop () {}
|