|
1 | | -"use strict"; |
2 | | - |
3 | 1 | // module Node.ReadLine |
4 | 2 |
|
5 | | -exports.createInterfaceImpl = function (options) { |
6 | | - return function () { |
7 | | - var readline = require("readline"); |
8 | | - return readline.createInterface({ |
9 | | - input: options.input, |
10 | | - output: options.output, |
11 | | - completer: |
12 | | - options.completer && |
13 | | - function (line) { |
14 | | - var res = options.completer(line)(); |
15 | | - return [res.completions, res.matched]; |
16 | | - }, |
17 | | - terminal: options.terminal, |
18 | | - historySize: options.historySize, |
19 | | - }); |
20 | | - }; |
21 | | -}; |
| 3 | +import { createInterface } from "readline"; |
22 | 4 |
|
23 | | -exports.close = function (readline) { |
24 | | - return function () { |
| 5 | +export function createInterfaceImpl(options) { |
| 6 | + return () => createInterface({ |
| 7 | + input: options.input, |
| 8 | + output: options.output, |
| 9 | + completer: options.completer && (line => { |
| 10 | + const res = options.completer(line)(); |
| 11 | + return [res.completions, res.matched]; |
| 12 | + }), |
| 13 | + terminal: options.terminal, |
| 14 | + historySize: options.historySize, |
| 15 | + }); |
| 16 | +} |
| 17 | + |
| 18 | +export function close(readline) { |
| 19 | + return () => { |
25 | 20 | readline.close(); |
26 | 21 | }; |
27 | | -}; |
| 22 | +} |
28 | 23 |
|
29 | | -exports.prompt = function (readline) { |
30 | | - return function () { |
| 24 | +export function prompt(readline) { |
| 25 | + return () => { |
31 | 26 | readline.prompt(); |
32 | 27 | }; |
33 | | -}; |
| 28 | +} |
34 | 29 |
|
35 | | -exports.question = function (text) { |
36 | | - return function (callback) { |
37 | | - return function (readline) { |
38 | | - return function () { |
39 | | - readline.question(text, function (result) { |
40 | | - callback(result)(); |
41 | | - }); |
42 | | - }; |
43 | | - }; |
| 30 | +export function question(text) { |
| 31 | + return callback => readline => () => { |
| 32 | + readline.question(text, result => { |
| 33 | + callback(result)(); |
| 34 | + }); |
44 | 35 | }; |
45 | | -}; |
| 36 | +} |
46 | 37 |
|
47 | | -exports.setPrompt = function (prompt) { |
48 | | - return function (readline) { |
49 | | - return function () { |
50 | | - readline.setPrompt(prompt); |
51 | | - }; |
| 38 | +export function setPrompt(prompt) { |
| 39 | + return readline => () => { |
| 40 | + readline.setPrompt(prompt); |
52 | 41 | }; |
53 | | -}; |
| 42 | +} |
54 | 43 |
|
55 | | -exports.setLineHandler = function (callback) { |
56 | | - return function (readline) { |
57 | | - return function () { |
58 | | - readline.removeAllListeners("line"); |
59 | | - readline.on("line", function (line) { |
60 | | - callback(line)(); |
61 | | - }); |
62 | | - }; |
| 44 | +export function setLineHandler(callback) { |
| 45 | + return readline => () => { |
| 46 | + readline.removeAllListeners("line"); |
| 47 | + readline.on("line", line => { |
| 48 | + callback(line)(); |
| 49 | + }); |
63 | 50 | }; |
64 | | -}; |
| 51 | +} |
0 commit comments