Skip to content

Commit 76aa1fb

Browse files
Add missing APIs (#34)
* Bump node deps; add event-emitter dep * Implement all events * Remove setLineHandler & LineHandler * Fix node-process FFI issue * Add missing APIs * Update prompt to clarify how to stop in test * Add missing cb arg in FFI
1 parent c816d34 commit 76aa1fb

File tree

5 files changed

+459
-61
lines changed

5 files changed

+459
-61
lines changed

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,41 @@ Notable changes to this project are documented in this file. The format is based
55
## [Unreleased]
66

77
Breaking changes:
8+
- Removed `setLineHandler` and `LineHandler` type alias (#34 by @JordanMartinez)
9+
10+
`setLineHandler` was previously implemented as
11+
```js
12+
readline.removeAllListeners("line");
13+
readline.on("line", cb);
14+
15+
With the addition of bindings from `EventEmitter`,
16+
this can be done using `on`
17+
```purs
18+
example = do
19+
removeListener <- interface # on lineH \line -> do
20+
...
21+
...
22+
removeListener
23+
```
824

925
New features:
26+
- Added missing `createInterface` options (#35 by @JordanMartinez)
27+
28+
- history
29+
- removeHistoryDuplicates
30+
- prompt
31+
- crlfDelay
32+
- escapeCodeTimeout
33+
- tabSize
34+
- Added missing APIs (#35 by @JordanMartinez)
35+
36+
- `pause`/`resume`
37+
- `getPrompt`
38+
- `write` exposed as `writeData` and `writeKey`
39+
- `line`, `cursor`
40+
- `getCursorPos`, `clearLine` variants, `clearScreenDown` variants
41+
- `cursorTo` variants, `moveCursor` variants
42+
- `emitKeyPressEvents`
1043

1144
Bugfixes:
1245

@@ -15,6 +48,7 @@ Other improvements:
1548
- Update CI actions to `v3` (#31, #32 by @JordanMartinez)
1649
- Format code via `purs-tidy`; enforce formatting in CI (#31, #32 by @JordanMartinez)
1750
- Update FFI to use uncurried functions (#33 by @JordanMartinez)
51+
- Reordered export list (#35 by @JordanMartinez)
1852

1953
## [v7.0.0](https://github.com/purescript-node/purescript-node-readline/releases/tag/v7.0.0) - 2022-04-29
2054

bower.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
"dependencies": {
2222
"purescript-effect": "^4.0.0",
2323
"purescript-foreign": "^7.0.0",
24-
"purescript-node-process": "^10.0.0",
25-
"purescript-node-streams": "^7.0.0",
24+
"purescript-node-event-emitter": "https://github.com/purescript-node/purescript-node-event-emitter.git#^3.0.0",
25+
"purescript-node-process": "^11.0.1",
26+
"purescript-node-streams": "^8.0.0",
2627
"purescript-options": "^7.0.0",
2728
"purescript-prelude": "^6.0.0"
2829
}

src/Node/ReadLine.js

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,52 @@
1-
// module Node.ReadLine
1+
// module Node.rl
22

3-
import { createInterface } from "readline";
3+
import readline from "node:readline";
44

5-
export const createInterfaceImpl = (options) => createInterface({
5+
export const createInterfaceImpl = (options) => readline.createInterface({
66
input: options.input,
77
output: options.output,
88
completer: options.completer && (line => {
99
const res = options.completer(line)();
1010
return [res.completions, res.matched];
1111
}),
1212
terminal: options.terminal,
13+
history: options.history,
1314
historySize: options.historySize,
15+
removeHistoryDuplicates: options.removeHistoryDuplicates,
16+
prompt: options.prompt,
17+
crlDelay: options.crlDelay,
18+
escapeCodeTimeout: options.escapeCodeTimeout,
19+
tabSize: options.tabSize,
20+
signal: options.signal
1421
});
1522

16-
export const closeImpl = (readline) => readline.close();
17-
export const promptImpl = (readline) => readline.prompt();
18-
export const questionImpl = (readline, text, cb) => readline.question(text, cb);
19-
export const setPromptImpl = (readline, prompt) => readline.setPrompt(prompt);
20-
export const setLineHandlerImpl = (readline, cb) => {
21-
readline.removeAllListeners("line");
22-
readline.on("line", cb);
23-
};
23+
export const closeImpl = (rl) => rl.close();
24+
export const pauseImpl = (rl) => rl.pause();
25+
export const promptImpl = (rl) => rl.prompt();
26+
export const promptOptsImpl = (rl, cursor) => rl.prompt(cursor);
27+
export const questionImpl = (rl, text, cb) => rl.question(text, cb);
28+
export const resumeImpl = (rl) => rl.resume();
29+
export const setPromptImpl = (rl, prompt) => rl.setPrompt(prompt);
30+
export const getPromptImpl = (rl) => rl.getPrompt();
31+
export const writeDataImpl = (rl, dataStr) => rl.write(dataStr);
32+
export const writeKeyImpl = (rl, keySeqObj) => rl.write(null, keySeqObj);
33+
export const lineImpl = (rl) => rl.line;
34+
export const cursorImpl = (rl) => rl.cursor;
35+
export const getCursorPosImpl = (rl) => rl.getCursorPos();
36+
37+
export const clearLineLeftImpl = (w) => readline.clearLine(w, -1);
38+
export const clearLineLeftCbImpl = (w, cb) => readline.clearLine(w, -1, cb);
39+
export const clearLineRightImpl = (w) => readline.clearLine(w, 1);
40+
export const clearLineRightCbImpl = (w, cb) => readline.clearLine(w, 1, cb);
41+
export const clearEntireLineImpl = (w) => readline.clearLine(w, 0);
42+
export const clearEntireLineCbImpl = (w, cb) => readline.clearLine(w, 0, cb);
43+
export const clearScreenDownImpl = (w) => readline.clearScreenDown(w);
44+
export const clearScreenDownCbImpl = (w, cb) => readline.clearScreenDown(w, cb);
45+
export const cursorToXImpl = (w, x) => readline.cursorTo(w, x);
46+
export const cursorToXCbImpl = (w, x, cb) => readline.cursorTo(w, x, cb);
47+
export const cursorToXYImpl = (w, x, y) => readline.cursorTo(w, x, y);
48+
export const cursorToXYCbImpl = (w, x, y, cb) => readline.cursorTo(w, x, y, cb);
49+
export const emitKeyPressEventsImpl = (r) => readline.emitKeypressEvents(r);
50+
export const emitKeyPressEventsIfaceImpl = (r, iface) => readline.emitKeypressEvents(r, iface);
51+
export const moveCursorXYImpl = (w, x, y) => readline.moveCursor(w, x, y);
52+
export const moveCursorXYCbImpl = (w, x, y, cb) => readline.moveCursor(w, x, y, cb);

0 commit comments

Comments
 (0)