Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,41 @@ Notable changes to this project are documented in this file. The format is based
## [Unreleased]

Breaking changes:
- Removed `setLineHandler` and `LineHandler` type alias (#34 by @JordanMartinez)

`setLineHandler` was previously implemented as
```js
readline.removeAllListeners("line");
readline.on("line", cb);

With the addition of bindings from `EventEmitter`,
this can be done using `on`
```purs
example = do
removeListener <- interface # on lineH \line -> do
...
...
removeListener
```

New features:
- Added missing `createInterface` options (#35 by @JordanMartinez)

- history
- removeHistoryDuplicates
- prompt
- crlfDelay
- escapeCodeTimeout
- tabSize
- Added missing APIs (#35 by @JordanMartinez)

- `pause`/`resume`
- `getPrompt`
- `write` exposed as `writeData` and `writeKey`
- `line`, `cursor`
- `getCursorPos`, `clearLine` variants, `clearScreenDown` variants
- `cursorTo` variants, `moveCursor` variants
- `emitKeyPressEvents`

Bugfixes:

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

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

Expand Down
5 changes: 3 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"dependencies": {
"purescript-effect": "^4.0.0",
"purescript-foreign": "^7.0.0",
"purescript-node-process": "^10.0.0",
"purescript-node-streams": "^7.0.0",
"purescript-node-event-emitter": "https://github.com/purescript-node/purescript-node-event-emitter.git#^3.0.0",
"purescript-node-process": "^11.0.1",
"purescript-node-streams": "^8.0.0",
"purescript-options": "^7.0.0",
"purescript-prelude": "^6.0.0"
}
Expand Down
51 changes: 40 additions & 11 deletions src/Node/ReadLine.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
// module Node.ReadLine
// module Node.rl

import { createInterface } from "readline";
import readline from "node:readline";

export const createInterfaceImpl = (options) => createInterface({
export const createInterfaceImpl = (options) => readline.createInterface({
input: options.input,
output: options.output,
completer: options.completer && (line => {
const res = options.completer(line)();
return [res.completions, res.matched];
}),
terminal: options.terminal,
history: options.history,
historySize: options.historySize,
removeHistoryDuplicates: options.removeHistoryDuplicates,
prompt: options.prompt,
crlDelay: options.crlDelay,
escapeCodeTimeout: options.escapeCodeTimeout,
tabSize: options.tabSize,
signal: options.signal
});

export const closeImpl = (readline) => readline.close();
export const promptImpl = (readline) => readline.prompt();
export const questionImpl = (readline, text, cb) => readline.question(text, cb);
export const setPromptImpl = (readline, prompt) => readline.setPrompt(prompt);
export const setLineHandlerImpl = (readline, cb) => {
readline.removeAllListeners("line");
readline.on("line", cb);
};
export const closeImpl = (rl) => rl.close();
export const pauseImpl = (rl) => rl.pause();
export const promptImpl = (rl) => rl.prompt();
export const promptOptsImpl = (rl, cursor) => rl.prompt(cursor);
export const questionImpl = (rl, text, cb) => rl.question(text, cb);
export const resumeImpl = (rl) => rl.resume();
export const setPromptImpl = (rl, prompt) => rl.setPrompt(prompt);
export const getPromptImpl = (rl) => rl.getPrompt();
export const writeDataImpl = (rl, dataStr) => rl.write(dataStr);
export const writeKeyImpl = (rl, keySeqObj) => rl.write(null, keySeqObj);
export const lineImpl = (rl) => rl.line;
export const cursorImpl = (rl) => rl.cursor;
export const getCursorPosImpl = (rl) => rl.getCursorPos();

export const clearLineLeftImpl = (w) => readline.clearLine(w, -1);
export const clearLineLeftCbImpl = (w, cb) => readline.clearLine(w, -1, cb);
export const clearLineRightImpl = (w) => readline.clearLine(w, 1);
export const clearLineRightCbImpl = (w, cb) => readline.clearLine(w, 1, cb);
export const clearEntireLineImpl = (w) => readline.clearLine(w, 0);
export const clearEntireLineCbImpl = (w, cb) => readline.clearLine(w, 0, cb);
export const clearScreenDownImpl = (w) => readline.clearScreenDown(w);
export const clearScreenDownCbImpl = (w, cb) => readline.clearScreenDown(w, cb);
export const cursorToXImpl = (w, x) => readline.cursorTo(w, x);
export const cursorToXCbImpl = (w, x, cb) => readline.cursorTo(w, x, cb);
export const cursorToXYImpl = (w, x, y) => readline.cursorTo(w, x, y);
export const cursorToXYCbImpl = (w, x, y, cb) => readline.cursorTo(w, x, y, cb);
export const emitKeyPressEventsImpl = (r) => readline.emitKeypressEvents(r);
export const emitKeyPressEventsIfaceImpl = (r, iface) => readline.emitKeypressEvents(r, iface);
export const moveCursorXYImpl = (w, x, y) => readline.moveCursor(w, x, y);
export const moveCursorXYCbImpl = (w, x, y, cb) => readline.moveCursor(w, x, y, cb);
Loading