From 0ffe1e4b6a7bee207d43abfed1f227aad64a262b Mon Sep 17 00:00:00 2001 From: aspidites Date: Mon, 3 Aug 2015 18:10:53 -0400 Subject: [PATCH 1/2] Added close function. --- src/Node/ReadLine.js | 9 ++++++++- src/Node/ReadLine.purs | 3 +++ test/Main.purs | 8 ++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Node/ReadLine.js b/src/Node/ReadLine.js index de0a2ac..62810d2 100644 --- a/src/Node/ReadLine.js +++ b/src/Node/ReadLine.js @@ -45,4 +45,11 @@ exports.createInterface = function(completer) { } }); }; -}; \ No newline at end of file +}; + +exports.close = function(readline) { + return function() { + readline.close(); + return readline; + }; +}; diff --git a/src/Node/ReadLine.purs b/src/Node/ReadLine.purs index 864ec50..74aa126 100644 --- a/src/Node/ReadLine.purs +++ b/src/Node/ReadLine.purs @@ -33,6 +33,9 @@ foreign import setPrompt :: forall eff. String -> Int -> Interface -> Eff (conso -- | Create an interface with the specified completion function. foreign import createInterface :: forall eff. Completer eff -> Eff (console :: CONSOLE | eff) Interface +-- | Close the specified `Interface`. +foreign import close :: forall eff. Interface -> Eff (console :: CONSOLE | eff) Interface + -- | A completion function which offers no completions. noCompletion :: forall eff. Completer eff noCompletion s = return { completions: [], matched: s } diff --git a/test/Main.purs b/test/Main.purs index 856af33..e851d41 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -12,8 +12,12 @@ main = do let lineHandler s = do - log $ "You typed: " ++ s - prompt interface + if s == "quit" + then do + close interface + else do + log $ "You typed: " ++ s + prompt interface setPrompt "> " 2 interface prompt interface From 584ce830181f00dbc8d19ebe46232ba7ab30730c Mon Sep 17 00:00:00 2001 From: aspidites Date: Mon, 3 Aug 2015 18:14:29 -0400 Subject: [PATCH 2/2] Regenerated docs. --- docs/Node/ReadLine.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/Node/ReadLine.md b/docs/Node/ReadLine.md index 97c32b4..db7287e 100644 --- a/docs/Node/ReadLine.md +++ b/docs/Node/ReadLine.md @@ -63,6 +63,14 @@ createInterface :: forall eff. Completer eff -> Eff (console :: CONSOLE | eff) I Create an interface with the specified completion function. +#### `close` + +``` purescript +close :: forall eff. Interface -> Eff (console :: CONSOLE | eff) Interface +``` + +Close the specified `Interface`. + #### `noCompletion` ``` purescript