Skip to content

Commit

Permalink
Merge pull request #16 from purescript-node/compiler/0.12
Browse files Browse the repository at this point in the history
Compiler/0.12
  • Loading branch information
kritzcreek authored May 29, 2018
2 parents 2a4628c + cf66311 commit 72bed94
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 57 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
language: node_js
dist: trusty
sudo: required
node_js: 6
node_js: stable
env:
- PATH=$HOME/purescript:$PATH
install:
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
- chmod a+x $HOME/purescript
- npm install -g bower
- npm install
script:
- bower install --production
- npm run -s build
- bower install
after_success:
- >-
test $TRAVIS_TAG &&
Expand Down
14 changes: 9 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
"bower.json",
"package.json"
],
"devDependencies": {
"purescript-console": "^4.0.0"
},
"dependencies": {
"purescript-console": "^3.0.0",
"purescript-node-streams": "^3.0.0",
"purescript-node-process": ">= 4.0.0 <6.0.0",
"purescript-options": "^3.0.0",
"purescript-foreign": "^4.0.0"
"purescript-node-streams": "^4.0.0",
"purescript-node-process": "^6.0.0",
"purescript-options": "^v4.0.0",
"purescript-foreign": "^5.0.0",
"purescript-prelude": "^v4.0.0",
"purescript-effect": "^2.0.0"
}
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"eslint": "^3.17.1",
"pulp": "^11.0.0",
"purescript-psa": "^0.5.0",
"purescript": "^0.11.1",
"rimraf": "^2.5.4"
}
}
68 changes: 24 additions & 44 deletions src/Node/ReadLine.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module Node.ReadLine
( Interface
, READLINE
, InterfaceOptions
, Completer
, LineHandler
Expand All @@ -22,11 +21,9 @@ module Node.ReadLine

import Prelude

import Control.Monad.Eff (kind Effect, Eff)
import Control.Monad.Eff.Console (CONSOLE)
import Control.Monad.Eff.Exception (EXCEPTION)
import Effect (Effect)

import Data.Foreign (Foreign)
import Foreign (Foreign)
import Data.Options (Options, Option, (:=), options, opt)

import Node.Process (stdin, stdout)
Expand All @@ -37,21 +34,15 @@ import Node.Stream (Readable, Writable)
-- | A handle can be created with the `createInterface` function.
foreign import data Interface :: Type

-- | The effect of interacting with a stream via an `Interface`
foreign import data READLINE :: Effect

foreign import createInterfaceImpl
:: forall eff
. Foreign
-> Eff ( readline :: READLINE | eff ) Interface
foreign import createInterfaceImpl :: Foreign -> Effect Interface

-- | Options passed to `readline`'s `createInterface`
data InterfaceOptions
foreign import data InterfaceOptions :: Type

output :: forall w eff. Option InterfaceOptions (Writable w eff)
output :: forall w. Option InterfaceOptions (Writable w)
output = opt "output"

completer :: forall eff. Option InterfaceOptions (Completer eff)
completer :: Option InterfaceOptions Completer
completer = opt "completer"

terminal :: Option InterfaceOptions Boolean
Expand All @@ -64,73 +55,62 @@ historySize = opt "historySize"
-- |
-- | This function takes the partial command as input, and returns a collection of
-- | completions, as well as the matched portion of the input string.
type Completer eff
type Completer
= String
-> Eff eff
-> Effect
{ completions :: Array String
, matched :: String
}

-- | Builds an interface with the specified options.
createInterface
:: forall r eff
. Readable r (readline :: READLINE | eff)
:: forall r
. Readable r
-> Options InterfaceOptions
-> Eff (readline :: READLINE | eff) Interface
-> Effect Interface
createInterface input opts = createInterfaceImpl
$ options $ opts
<> opt "input" := input

-- | Create an interface with the specified completion function.
createConsoleInterface
:: forall eff
. Completer (readline :: READLINE, console :: CONSOLE, exception :: EXCEPTION | eff)
-> Eff (readline :: READLINE, console :: CONSOLE, exception :: EXCEPTION | eff) Interface
createConsoleInterface :: Completer -> Effect Interface
createConsoleInterface compl =
createInterface stdin
$ output := stdout
<> completer := compl

-- | A completion function which offers no completions.
noCompletion :: forall eff. Completer eff
noCompletion :: Completer
noCompletion s = pure { completions: [], matched: s }

-- | Prompt the user for input on the specified `Interface`.
foreign import prompt
:: forall eff
. Interface
-> Eff (readline :: READLINE | eff) Unit
foreign import prompt :: Interface -> Effect Unit

-- | Writes a query to the output, waits
-- | for user input to be provided on input, then invokes
-- | the callback function
foreign import question
:: forall eff
. String
-> (String -> Eff (readline :: READLINE | eff) Unit)
:: String
-> (String -> Effect Unit)
-> Interface
-> Eff (readline :: READLINE | eff) Unit
-> Effect Unit

-- | Set the prompt.
foreign import setPrompt
:: forall eff
. String
:: String
-> Int
-> Interface
-> Eff (readline :: READLINE | eff) Unit
-> Effect Unit

-- | Close the specified `Interface`.
foreign import close
:: forall eff
. Interface
-> Eff (readline :: READLINE | eff) Unit
foreign import close :: Interface -> Effect Unit

-- | A function which handles each line of input.
type LineHandler eff a = String -> Eff eff a
type LineHandler a = String -> Effect a

-- | Set the current line handler function.
foreign import setLineHandler
:: forall eff a
:: forall a
. Interface
-> LineHandler (readline :: READLINE | eff) a
-> Eff (readline :: READLINE | eff) Unit
-> LineHandler a
-> Effect Unit
9 changes: 4 additions & 5 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ module Test.Main where

import Prelude

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Control.Monad.Eff.Exception (EXCEPTION)
import Effect (Effect)
import Effect.Console (log)

import Node.ReadLine (READLINE, prompt, close, setLineHandler, setPrompt, noCompletion, createConsoleInterface)
import Node.ReadLine (prompt, close, setLineHandler, setPrompt, noCompletion, createConsoleInterface)

main :: forall eff. Eff (readline :: READLINE, console :: CONSOLE, exception :: EXCEPTION | eff) Unit
main :: Effect Unit
main = do
interface <- createConsoleInterface noCompletion
setPrompt "> " 2 interface
Expand Down

0 comments on commit 72bed94

Please sign in to comment.