bare-tty 5.0.3 → 5.1.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.
package/CMakeLists.txt CHANGED
@@ -1,4 +1,4 @@
1
- cmake_minimum_required(VERSION 3.25)
1
+ cmake_minimum_required(VERSION 4.0)
2
2
 
3
3
  find_package(cmake-bare REQUIRED PATHS node_modules/cmake-bare)
4
4
 
package/index.d.ts CHANGED
@@ -1,16 +1,11 @@
1
- import {
2
- Readable,
3
- ReadableOptions,
4
- Writable,
5
- WritableEvents,
6
- WritableOptions
7
- } from 'bare-stream'
1
+ import { Readable, ReadableOptions, Writable, WritableEvents, WritableOptions } from 'bare-stream'
2
+ import constants from './lib/constants'
8
3
 
9
4
  interface ReadStream extends Readable {
5
+ readonly fd: number
10
6
  readonly isTTY: true
11
7
 
12
8
  setMode(mode: number): this
13
-
14
9
  setRawMode(mode: boolean): this
15
10
  }
16
11
 
@@ -22,8 +17,8 @@ interface WriteStreamEvents extends WritableEvents {
22
17
  resize: []
23
18
  }
24
19
 
25
- interface WriteStream<M extends WriteStreamEvents = WriteStreamEvents>
26
- extends Writable<M> {
20
+ interface WriteStream<M extends WriteStreamEvents = WriteStreamEvents> extends Writable<M> {
21
+ readonly fd: number
27
22
  readonly isTTY: true
28
23
  readonly columns: number
29
24
  readonly rows: number
@@ -31,17 +26,10 @@ interface WriteStream<M extends WriteStreamEvents = WriteStreamEvents>
31
26
  getWindowSize(): [width: number, height: number]
32
27
  }
33
28
 
34
- declare class WriteStream<
35
- M extends WriteStreamEvents = WriteStreamEvents
36
- > extends Writable<M> {
29
+ declare class WriteStream<M extends WriteStreamEvents = WriteStreamEvents> extends Writable<M> {
37
30
  constructor(fd: number, opts?: WritableOptions)
38
31
  }
39
32
 
40
33
  declare function isTTY(fd: number): boolean
41
34
 
42
- declare const constants: {
43
- mode: { NORMAL: number; RAW: number; IO: number }
44
- state: { READING: number; CLOSING: number }
45
- }
46
-
47
35
  export { ReadStream, WriteStream, isTTY, isTTY as isatty, constants }
package/index.js CHANGED
@@ -1,34 +1,29 @@
1
- /* global Bare */
2
1
  const { Readable, Writable } = require('bare-stream')
3
2
  const Signal = require('bare-signals')
4
3
  const binding = require('./binding')
5
4
  const constants = require('./lib/constants')
6
5
 
7
6
  const defaultReadBufferSize = 65536
7
+ const empty = Buffer.alloc(0)
8
8
 
9
9
  exports.ReadStream = class TTYReadStream extends Readable {
10
10
  constructor(fd, opts = {}) {
11
11
  super()
12
12
 
13
- const { readBufferSize = defaultReadBufferSize, allowHalfOpen = true } =
14
- opts
13
+ const { readBufferSize = defaultReadBufferSize, allowHalfOpen = true } = opts
15
14
 
15
+ this._fd = fd
16
16
  this._state = 0
17
-
18
17
  this._allowHalfOpen = allowHalfOpen
18
+ this._buffer = Buffer.alloc(readBufferSize)
19
19
 
20
20
  this._pendingDestroy = null
21
21
 
22
- this._buffer = Buffer.alloc(readBufferSize)
22
+ this._handle = binding.init(fd, this._buffer, this, noop, this._onread, this._onclose)
23
+ }
23
24
 
24
- this._handle = binding.init(
25
- fd,
26
- this._buffer,
27
- this,
28
- noop,
29
- this._onread,
30
- this._onclose
31
- )
25
+ get fd() {
26
+ return this._fd
32
27
  }
33
28
 
34
29
  get isTTY() {
@@ -47,6 +42,7 @@ exports.ReadStream = class TTYReadStream extends Readable {
47
42
  _read() {
48
43
  if ((this._state & constants.state.READING) === 0) {
49
44
  this._state |= constants.state.READING
45
+
50
46
  binding.resume(this._handle)
51
47
  }
52
48
  }
@@ -54,13 +50,16 @@ exports.ReadStream = class TTYReadStream extends Readable {
54
50
  _predestroy() {
55
51
  if (this._state & constants.state.CLOSING) return
56
52
  this._state |= constants.state.CLOSING
53
+
57
54
  binding.close(this._handle)
58
55
  }
59
56
 
60
57
  _destroy(err, cb) {
61
58
  if (this._state & constants.state.CLOSING) return cb(err)
62
59
  this._state |= constants.state.CLOSING
60
+
63
61
  this._pendingDestroy = cb
62
+
64
63
  binding.close(this._handle)
65
64
  }
66
65
 
@@ -88,12 +87,14 @@ exports.ReadStream = class TTYReadStream extends Readable {
88
87
 
89
88
  if (this.push(copy) === false && this.destroying === false) {
90
89
  this._state &= ~constants.state.READING
90
+
91
91
  binding.pause(this._handle)
92
92
  }
93
93
  }
94
94
 
95
95
  _onclose() {
96
96
  this._handle = null
97
+
97
98
  this._continueDestroy()
98
99
  }
99
100
  }
@@ -102,27 +103,26 @@ exports.WriteStream = class TTYWriteStream extends Writable {
102
103
  constructor(fd, opts = {}) {
103
104
  super()
104
105
 
106
+ this._fd = fd
105
107
  this._state = 0
106
108
  this._size = null
107
109
 
108
110
  this._pendingWrite = null
109
111
  this._pendingDestroy = null
110
112
 
111
- this._handle = binding.init(
112
- fd,
113
- empty,
114
- this,
115
- this._onwrite,
116
- noop,
117
- this._onclose
118
- )
113
+ this._handle = binding.init(fd, empty, this, this._onwrite, noop, this._onclose)
119
114
 
120
115
  this._size = this.getWindowSize()
121
116
 
122
117
  if (TTYWriteStream._streams.size === 0) TTYWriteStream._resize.start()
118
+
123
119
  TTYWriteStream._streams.add(this)
124
120
  }
125
121
 
122
+ get fd() {
123
+ return this._fd
124
+ }
125
+
126
126
  get isTTY() {
127
127
  return true
128
128
  }
@@ -141,6 +141,7 @@ exports.WriteStream = class TTYWriteStream extends Writable {
141
141
 
142
142
  _writev(batch, cb) {
143
143
  this._pendingWrite = [cb, batch]
144
+
144
145
  binding.writev(
145
146
  this._handle,
146
147
  batch.map(({ chunk }) => chunk)
@@ -150,17 +151,24 @@ exports.WriteStream = class TTYWriteStream extends Writable {
150
151
  _predestroy() {
151
152
  if (this._state & constants.state.CLOSING) return
152
153
  this._state |= constants.state.CLOSING
154
+
153
155
  binding.close(this._handle)
156
+
154
157
  TTYWriteStream._streams.delete(this)
158
+
155
159
  if (TTYWriteStream._streams.size === 0) TTYWriteStream._resize.stop()
156
160
  }
157
161
 
158
162
  _destroy(err, cb) {
159
163
  if (this._state & constants.state.CLOSING) return cb(err)
160
164
  this._state |= constants.state.CLOSING
165
+
161
166
  this._pendingDestroy = cb
167
+
162
168
  binding.close(this._handle)
169
+
163
170
  TTYWriteStream._streams.delete(this)
171
+
164
172
  if (TTYWriteStream._streams.size === 0) TTYWriteStream._resize.stop()
165
173
  }
166
174
 
@@ -184,11 +192,13 @@ exports.WriteStream = class TTYWriteStream extends Writable {
184
192
 
185
193
  _onclose() {
186
194
  this._handle = null
195
+
187
196
  this._continueDestroy()
188
197
  }
189
198
 
190
199
  _onresize() {
191
200
  this._size = this.getWindowSize()
201
+
192
202
  this.emit('resize')
193
203
  }
194
204
 
@@ -211,6 +221,4 @@ exports.WriteStream._resize
211
221
  })
212
222
  .unref()
213
223
 
214
- const empty = Buffer.alloc(0)
215
-
216
224
  function noop() {}
@@ -0,0 +1,6 @@
1
+ declare const constants: {
2
+ mode: { NORMAL: number; RAW: number; IO: number }
3
+ state: { READING: number; CLOSING: number }
4
+ }
5
+
6
+ export = constants
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-tty",
3
- "version": "5.0.3",
3
+ "version": "5.1.0",
4
4
  "description": "Native TTY streams for JavaScript",
5
5
  "exports": {
6
6
  ".": {
@@ -45,6 +45,6 @@
45
45
  "brittle": "^3.2.1",
46
46
  "cmake-bare": "^1.1.6",
47
47
  "prettier": "^3.4.1",
48
- "prettier-config-standard": "^7.0.0"
48
+ "prettier-config-holepunch": "^2.0.0"
49
49
  }
50
50
  }