Skip to content

Commit 0ffe1e4

Browse files
committed
Added close function.
1 parent 8b53591 commit 0ffe1e4

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/Node/ReadLine.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,11 @@ exports.createInterface = function(completer) {
4545
}
4646
});
4747
};
48-
};
48+
};
49+
50+
exports.close = function(readline) {
51+
return function() {
52+
readline.close();
53+
return readline;
54+
};
55+
};

src/Node/ReadLine.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ foreign import setPrompt :: forall eff. String -> Int -> Interface -> Eff (conso
3333
-- | Create an interface with the specified completion function.
3434
foreign import createInterface :: forall eff. Completer eff -> Eff (console :: CONSOLE | eff) Interface
3535

36+
-- | Close the specified `Interface`.
37+
foreign import close :: forall eff. Interface -> Eff (console :: CONSOLE | eff) Interface
38+
3639
-- | A completion function which offers no completions.
3740
noCompletion :: forall eff. Completer eff
3841
noCompletion s = return { completions: [], matched: s }

test/Main.purs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ main = do
1212

1313
let
1414
lineHandler s = do
15-
log $ "You typed: " ++ s
16-
prompt interface
15+
if s == "quit"
16+
then do
17+
close interface
18+
else do
19+
log $ "You typed: " ++ s
20+
prompt interface
1721

1822
setPrompt "> " 2 interface
1923
prompt interface

0 commit comments

Comments
 (0)