necessary 13.6.7 → 14.0.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/README.md +2 -12
- package/package.json +1 -1
- package/src/utilities/shell.js +0 -29
package/README.md
CHANGED
|
@@ -147,20 +147,10 @@ Note that the `headers` argument is not optional this time.
|
|
|
147
147
|
|
|
148
148
|
## Shell utilities
|
|
149
149
|
|
|
150
|
-
- `onETX()`
|
|
151
150
|
- `prompt()`
|
|
152
151
|
|
|
153
|
-
Functions
|
|
154
|
-
|
|
155
|
-
* The `onETX()` function takes a handler which is invoked whenever the `ETX` character code is encountered in the `stdin` stream, which typically happens when the user presses `Ctrl-C`. This function is therefore useful for exiting a console application immediately upon the user's behest, if it is passed `process.exit`. It also returns a function that can be called to remove the listener at some later point in time:
|
|
156
|
-
|
|
157
|
-
```
|
|
158
|
-
const offEXT = onEXT(process.exit);
|
|
159
|
-
|
|
160
|
-
...
|
|
161
|
-
|
|
162
|
-
offEXT();
|
|
163
|
-
```
|
|
152
|
+
Functions for applications running on a shell such as Bash or ZSH.
|
|
153
|
+
In fact there is only one currently.
|
|
164
154
|
|
|
165
155
|
* The `prompt()` function is meant for use in shell applications. It takes a plain old JavaScript `options` object and a `callback` function as its first and second arguments, respectively:
|
|
166
156
|
|
package/package.json
CHANGED
package/src/utilities/shell.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import { whilst } from "../utilities/asynchronous";
|
|
4
4
|
|
|
5
5
|
import { DATA } from "../constants";
|
|
6
|
-
import { UTF8_ENCODING } from "../encodings";
|
|
7
6
|
import { DEFAULT_ENCODING, DEFAULT_ATTEMPTS, DEFAULT_INITIAL_ANSWER } from "../defaults";
|
|
8
7
|
import { UP_CHARACTER,
|
|
9
8
|
ETX_CHARACTER,
|
|
@@ -15,33 +14,6 @@ import { UP_CHARACTER,
|
|
|
15
14
|
BACKSPACE_CHARACTER,
|
|
16
15
|
CARRIAGE_RETURN_CHARACTER } from "../characters";
|
|
17
16
|
|
|
18
|
-
export function onETX(handler) {
|
|
19
|
-
if (process.stdin.setRawMode) {
|
|
20
|
-
const rawMode = true,
|
|
21
|
-
encoding = UTF8_ENCODING;
|
|
22
|
-
|
|
23
|
-
process.stdin.setRawMode(rawMode);
|
|
24
|
-
|
|
25
|
-
process.stdin.setEncoding(encoding);
|
|
26
|
-
|
|
27
|
-
process.stdin.addListener(DATA, listener);
|
|
28
|
-
|
|
29
|
-
process.stdin.resume();
|
|
30
|
-
|
|
31
|
-
return offExt;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function offExt() {
|
|
35
|
-
process.stdin.removeListener(DATA, listener);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function listener(character) {
|
|
39
|
-
if (character === ETX_CHARACTER) {
|
|
40
|
-
handler();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
17
|
export function prompt(options, callback) {
|
|
46
18
|
let { answer = null } = options;
|
|
47
19
|
|
|
@@ -66,7 +38,6 @@ export function prompt(options, callback) {
|
|
|
66
38
|
}
|
|
67
39
|
|
|
68
40
|
export default {
|
|
69
|
-
onETX,
|
|
70
41
|
prompt
|
|
71
42
|
}
|
|
72
43
|
|