11module Node.ReadLine where
22
3- import Data.Tuple
43import Control.Monad.Eff
54
65foreign import data Console :: !
@@ -13,21 +12,22 @@ foreign import data OutputStream :: *
1312
1413foreign import process :: { stderr :: OutputStream , stdout :: OutputStream , stdin :: InputStream }
1514
16- type Completer eff = String -> Eff eff ( Tuple [String ] String )
15+ type Completer eff = String -> Eff eff { completions :: [String ], matched :: String }
1716
18- type LineHandler eff = String -> Eff eff Unit
17+ type LineHandler eff a = String -> Eff eff a
1918
2019foreign import setLineHandler
2120 " function setLineHandler(callback) {\
2221 \ return function(readline) {\
2322 \ return function() {\
23+ \ readline.removeAllListeners('line');\
2424 \ readline.on('line', function (line) {\
2525 \ callback(line)();\
2626 \ });\
2727 \ return readline;\
2828 \ };\
2929 \ };\
30- \};" :: forall eff . LineHandler eff -> Interface -> Eff (console :: Console | eff ) Interface
30+ \};" :: forall eff a . LineHandler eff a -> Interface -> Eff (console :: Console | eff ) Interface
3131
3232foreign import prompt
3333 " function prompt(readline) {\
@@ -59,13 +59,15 @@ foreign import createInterface
5959 \ input: input,\
6060 \ output: output,\
6161 \ completer: function(line) {\
62- \ var completions = completer(line)();\
63- \ return completions.values ;\
62+ \ var res = completer(line)();\
63+ \ return [res. completions, res.suffix] ;\
6464 \ }\
6565 \ });\
6666 \ };\
6767 \ };\
6868 \ };\
6969 \}" :: forall eff . InputStream -> OutputStream -> Completer eff -> Eff (console :: Console | eff ) Interface
7070
71+ noCompletion :: forall eff . Completer eff
72+ noCompletion s = return { completions: [] , matched: s }
7173
0 commit comments