Skip to content

Commit b44f936

Browse files
committed
Rename to .purs
1 parent 716e0d5 commit b44f936

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/Node/ReadLine.purs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
module Node.ReadLine where
2+
3+
import Data.Tuple
4+
import Control.Monad.Eff
5+
6+
foreign import data Console :: !
7+
8+
foreign import data Interface :: *
9+
10+
foreign import data InputStream :: *
11+
12+
foreign import data OutputStream :: *
13+
14+
foreign import process :: { stderr :: OutputStream, stdout :: OutputStream, stdin :: InputStream }
15+
16+
type Completer eff = String -> Eff eff (Tuple [String] String)
17+
18+
type LineHandler eff = String -> Eff eff {}
19+
20+
foreign import setLineHandler
21+
"function setLineHandler(callback) {\
22+
\ return function(readline) {\
23+
\ return function() {\
24+
\ readline.on('line', function (line) {\
25+
\ callback(line)();\
26+
\ });\
27+
\ return readline;\
28+
\ };\
29+
\ };\
30+
\};" :: forall eff. LineHandler eff -> Interface -> Eff (console :: Console | eff) Interface
31+
32+
foreign import prompt
33+
"function prompt(readline) {\
34+
\ return function() {\
35+
\ readline.prompt();\
36+
\ return readline;\
37+
\ };\
38+
\};" :: forall eff. Interface -> Eff (console :: Console | eff) Interface
39+
40+
foreign import setPrompt
41+
"function setPrompt(prompt) {\
42+
\ return function(length) {\
43+
\ return function(readline) {\
44+
\ return function() {\
45+
\ readline.setPrompt(prompt, length);\
46+
\ return readline;\
47+
\ };\
48+
\ };\
49+
\ };\
50+
\}" :: forall eff. Prim.String -> Prim.Number -> Interface -> Eff (console :: Console | eff) Interface
51+
52+
foreign import createInterface
53+
"function createInterface(input) {\
54+
\ return function(output) {\
55+
\ return function(completer) {\
56+
\ return function() {\
57+
\ var readline = require('readline');\
58+
\ return readline.createInterface({\
59+
\ input: input,\
60+
\ output: output,\
61+
\ completer: function(line) {\
62+
\ var completions = completer(line)();\
63+
\ return completions.values;\
64+
\ }\
65+
\ });\
66+
\ };\
67+
\ };\
68+
\ };\
69+
\}" :: forall eff. InputStream -> OutputStream -> Completer eff -> Eff (console :: Console | eff) Interface
70+
71+

0 commit comments

Comments
 (0)