bare-tty 5.2.0 → 5.2.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/README.md CHANGED
@@ -16,6 +16,10 @@ const stdout = new tty.WriteStream(1)
16
16
  stdout.write('Hello world!\n')
17
17
  ```
18
18
 
19
+ ## API
20
+
21
+ See the [`bare-tty` reference](https://docs.pears.com/reference/bare/modules/bare-tty).
22
+
19
23
  ## License
20
24
 
21
25
  Apache-2.0
package/binding.c CHANGED
@@ -557,6 +557,7 @@ bare_tty_exports(js_env_t *env, js_value_t *exports) {
557
557
 
558
558
  V("MODE_NORMAL", UV_TTY_MODE_NORMAL)
559
559
  V("MODE_RAW", UV_TTY_MODE_RAW)
560
+ V("MODE_RAW_VT", UV_TTY_MODE_RAW_VT)
560
561
  #ifndef _WIN32
561
562
  V("MODE_IO", UV_TTY_MODE_IO)
562
563
  #endif
package/index.d.ts CHANGED
@@ -7,14 +7,22 @@ interface ReadStreamOptions extends ReadableOptions {
7
7
  }
8
8
 
9
9
  interface ReadStream extends Readable {
10
+ /** The stream's underlying file descriptor. */
10
11
  readonly fd: number
12
+ /** Always `true`, identifying the stream as a TTY. */
11
13
  readonly isTTY: true
12
14
 
15
+ /** Set the TTY mode directly, using one of the `constants.mode` values. Returns the stream. */
13
16
  setMode(mode: number): this
17
+ /**
18
+ * Enable or disable raw mode. In raw mode, input is delivered byte-by-byte without line buffering
19
+ * or special key processing. Returns the stream.
20
+ */
14
21
  setRawMode(mode: boolean): this
15
22
  }
16
23
 
17
24
  declare class ReadStream extends Readable {
25
+ /** Create a `ReadStream` for the TTY file descriptor `fd`. */
18
26
  constructor(fd: number, opts?: ReadStreamOptions)
19
27
  }
20
28
 
@@ -23,18 +31,28 @@ interface WriteStreamEvents extends WritableEvents {
23
31
  }
24
32
 
25
33
  interface WriteStream<M extends WriteStreamEvents = WriteStreamEvents> extends Writable<M> {
34
+ /** The stream's underlying file descriptor. */
26
35
  readonly fd: number
36
+ /** Always `true`, identifying the stream as a TTY. */
27
37
  readonly isTTY: true
38
+ /** The current number of columns in the TTY. */
28
39
  readonly columns: number
40
+ /** The current number of rows in the TTY. */
29
41
  readonly rows: number
30
42
 
43
+ /** Return the current TTY dimensions as `[width, height]`. */
31
44
  getWindowSize(): [width: number, height: number]
32
45
  }
33
46
 
34
47
  declare class WriteStream<M extends WriteStreamEvents = WriteStreamEvents> extends Writable<M> {
48
+ /** Create a `WriteStream` for the TTY file descriptor `fd`. */
35
49
  constructor(fd: number, opts?: WritableOptions)
36
50
  }
37
51
 
52
+ /**
53
+ * Return whether `fd` refers to a TTY.
54
+ * @param fd - The file descriptor to check.
55
+ */
38
56
  declare function isTTY(fd: number): boolean
39
57
 
40
58
  export {
package/index.js CHANGED
@@ -6,7 +6,12 @@ const errors = require('./lib/errors')
6
6
 
7
7
  const defaultReadBufferSize = 65536
8
8
  const empty = Buffer.alloc(0)
9
- const modes = new Set([constants.mode.NORMAL, constants.mode.RAW, constants.mode.IO])
9
+ const modes = new Set([
10
+ constants.mode.NORMAL,
11
+ constants.mode.RAW,
12
+ constants.mode.RAW_VT,
13
+ constants.mode.IO
14
+ ])
10
15
 
11
16
  exports.ReadStream = class TTYReadStream extends Readable {
12
17
  constructor(fd, opts = {}) {
@@ -45,7 +50,7 @@ exports.ReadStream = class TTYReadStream extends Readable {
45
50
  }
46
51
 
47
52
  setRawMode(enabled) {
48
- return this.setMode(enabled ? constants.mode.RAW : constants.mode.NORMAL)
53
+ return this.setMode(enabled ? constants.mode.RAW_VT : constants.mode.NORMAL)
49
54
  }
50
55
 
51
56
  _alive() {
@@ -99,7 +104,10 @@ exports.ReadStream = class TTYReadStream extends Readable {
99
104
  return
100
105
  }
101
106
 
102
- const copy = Buffer.allocUnsafe(read)
107
+ // Unpooled, as a read too small to be given a buffer of its own would
108
+ // otherwise pin the whole pool it came from for as long as its consumer
109
+ // holds on to it.
110
+ const copy = Buffer.allocUnsafeSlow(read)
103
111
  copy.set(this._buffer.subarray(0, read))
104
112
 
105
113
  if (this.push(copy) === false && this.destroying === false) {
@@ -1,5 +1,9 @@
1
+ /**
2
+ * Native mode and internal state flags used by `ReadStream`/`WriteStream`, such as `mode.NORMAL`
3
+ * and `mode.RAW`.
4
+ */
1
5
  declare const constants: {
2
- mode: { NORMAL: number; RAW: number; IO: number }
6
+ mode: { NORMAL: number; RAW: number; RAW_VT: number; IO: number }
3
7
  state: { READING: number; CLOSING: number; CLOSED: number }
4
8
  }
5
9
 
package/lib/constants.js CHANGED
@@ -4,6 +4,7 @@ module.exports = exports = {
4
4
  mode: {
5
5
  NORMAL: binding.MODE_NORMAL,
6
6
  RAW: binding.MODE_RAW,
7
+ RAW_VT: binding.MODE_RAW_VT,
7
8
  IO: binding.MODE_IO || 0
8
9
  },
9
10
 
@@ -18,5 +19,7 @@ module.exports = exports = {
18
19
  exports.MODE_NORMAL = exports.mode.NORMAL
19
20
  /** @deprecated Use `mode.RAW` */
20
21
  exports.MODE_RAW = exports.mode.RAW
22
+ /** @deprecated Use `mode.RAW_VT` */
23
+ exports.MODE_RAW_VT = exports.mode.RAW_VT
21
24
  /** @deprecated Use `mode.IO` */
22
25
  exports.MODE_IO = exports.mode.IO
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-tty",
3
- "version": "5.2.0",
3
+ "version": "5.2.2",
4
4
  "description": "Native TTY streams for JavaScript",
5
5
  "exports": {
6
6
  "./package": "./package.json",
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file