|
1 | 1 | module Interface = {
|
2 | 2 | type t
|
3 |
| - type interfaceOptions |
4 |
| - @obj |
5 |
| - external interfaceOptions: ( |
6 |
| - ~input: Stream.Readable.subtype<Buffer.t, 'rtype>, |
7 |
| - ~output: Stream.Writable.subtype<Buffer.t, 'wtype>=?, |
8 |
| - ~completer: (string, (string, (array<string>, string)) => unit) => unit=?, |
9 |
| - ~terminal: bool=?, |
10 |
| - ~historySize: int=?, |
11 |
| - ~prompt: string=?, |
12 |
| - ~crlfDelay: int=?, |
13 |
| - ~removeHistoryDuplicates: bool=?, |
14 |
| - ~escapeCodeTimeout: int=?, |
15 |
| - unit, |
16 |
| - ) => interfaceOptions = "" |
17 |
| - @send external make: (t, interfaceOptions) => t = "createInterface" |
18 | 3 | @send external close: t => unit = "close"
|
19 | 4 | @send external pause: t => unit = "pause"
|
20 | 5 | @send external prompt: (t, Js.nullable<bool>) => unit = "prompt"
|
@@ -42,25 +27,59 @@ module Interface = {
|
42 | 27 | @get @return(nullable) external line: t => option<string> = "line"
|
43 | 28 | @get @return(nullable)
|
44 | 29 | external cursor: t => option<int> = "cursor"
|
45 |
| - @send |
46 |
| - external clearLine: (t, Stream.Writable.subtype<Buffer.t, 'ty>, int) => bool = "clearLine" |
47 |
| - @send |
48 |
| - external clearScreenDown: (t, Stream.Writable.subtype<Buffer.t, 'ty>, unit => unit) => bool = |
49 |
| - "clearScreenDown" |
50 |
| - @send |
51 |
| - external cursorTo: ( |
52 |
| - t, |
53 |
| - Stream.Writable.subtype<Buffer.t, 'ty>, |
54 |
| - int, |
55 |
| - Js.Undefined.t<int>, |
56 |
| - Js.Undefined.t<unit => unit>, |
57 |
| - ) => bool = "cursorTo" |
58 |
| - @send |
59 |
| - external moveCursor: ( |
60 |
| - t, |
61 |
| - Stream.Writable.subtype<Buffer.t, 'ty>, |
62 |
| - int, |
63 |
| - int, |
64 |
| - Js.Undefined.t<unit => unit>, |
65 |
| - ) => bool = "moveCursor" |
| 30 | + |
| 31 | + include EventEmitter.Impl({ |
| 32 | + type t = t |
| 33 | + }) |
| 34 | +} |
| 35 | + |
| 36 | +module Events = { |
| 37 | + open Interface |
| 38 | + let close: (t, unit => unit) => t = (rl, f) => rl->on(Event.fromString("close"), f) |
| 39 | + let line: (t, string => unit) => t = (rl, f) => rl->on(Event.fromString("line"), f) |
| 40 | + let history: (t, array<string> => unit) => t = (rl, f) => rl->on(Event.fromString("history"), f) |
66 | 41 | }
|
| 42 | + |
| 43 | +type interfaceOptions |
| 44 | +@obj |
| 45 | +external interfaceOptions: ( |
| 46 | + ~input: Stream.Readable.subtype<Buffer.t, 'rtype>, |
| 47 | + ~output: Stream.Writable.subtype<Buffer.t, 'wtype>=?, |
| 48 | + ~completer: (string, (string, (array<string>, string)) => unit) => unit=?, |
| 49 | + ~terminal: bool=?, |
| 50 | + ~historySize: int=?, |
| 51 | + ~prompt: string=?, |
| 52 | + ~crlfDelay: float=?, |
| 53 | + ~removeHistoryDuplicates: bool=?, |
| 54 | + ~escapeCodeTimeout: int=?, |
| 55 | + unit, |
| 56 | +) => interfaceOptions = "" |
| 57 | +@module("readline") external make: interfaceOptions => Interface.t = "createInterface" |
| 58 | + |
| 59 | +@module("readline") |
| 60 | +external clearLine: (Stream.Writable.subtype<Buffer.t, 'ty>, int, ~callback: unit => unit) => bool = |
| 61 | + "clearLine" |
| 62 | + |
| 63 | +@module("readline") |
| 64 | +external clearScreenDown: ( |
| 65 | + Stream.Writable.subtype<Buffer.t, 'ty>, |
| 66 | + ~callback: unit => unit, |
| 67 | +) => bool = "clearScreenDown" |
| 68 | + |
| 69 | +@module("readline") |
| 70 | +external cursorTo: ( |
| 71 | + Stream.Writable.subtype<Buffer.t, 'ty>, |
| 72 | + ~x: int, |
| 73 | + ~y: int=?, |
| 74 | + ~callback: unit => unit=?, |
| 75 | + @ignore unit, |
| 76 | +) => bool = "cursorTo" |
| 77 | + |
| 78 | +@module("readline") |
| 79 | +external moveCursor: ( |
| 80 | + Stream.Writable.subtype<Buffer.t, 'ty>, |
| 81 | + ~dx: int, |
| 82 | + ~dy: int, |
| 83 | + ~callback: unit => unit=?, |
| 84 | + @ignore unit, |
| 85 | +) => bool = "moveCursor" |
0 commit comments