Skip to content

Commit

Permalink
Merge pull request #1 from aspidites/close
Browse files Browse the repository at this point in the history
Added close function.
  • Loading branch information
paf31 committed Aug 10, 2015
2 parents a712652 + 7639208 commit 3cd5719
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions docs/Node/ReadLine.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/Node/ReadLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,10 @@ exports.createInterface = function(completer) {
});
};
};

exports.close = function(readline) {
return function() {
readline.close();
return readline;
};
};
3 changes: 3 additions & 0 deletions src/Node/ReadLine.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
9 changes: 6 additions & 3 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3cd5719

Please sign in to comment.