diff --git a/docs/Node/ReadLine.md b/docs/Node/ReadLine.md index b744c68..caf9905 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 diff --git a/src/Node/ReadLine.js b/src/Node/ReadLine.js index 899451b..0399450 100644 --- a/src/Node/ReadLine.js +++ b/src/Node/ReadLine.js @@ -46,3 +46,10 @@ exports.createInterface = function(completer) { }); }; }; + +exports.close = function(readline) { + return function() { + readline.close(); + return readline; + }; +}; diff --git a/src/Node/ReadLine.purs b/src/Node/ReadLine.purs index 6131ffa..7a58e3c 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 e1f1d9e..1cabb17 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -12,6 +12,9 @@ main = do setPrompt "> " 2 interface prompt interface - setLineHandler interface $ \s -> do - log $ "You typed: " ++ s - prompt interface + setLineHandler interface $ \s -> + if s == "quit" + then close interface + else do + log $ "You typed: " ++ s + prompt interface