@@ -20,11 +20,14 @@ module Node.ReadLine
2020 ) where
2121
2222import Prelude
23+
2324import Control.Monad.Eff (Eff )
2425import Control.Monad.Eff.Console (CONSOLE )
2526import Control.Monad.Eff.Exception (EXCEPTION )
27+
2628import Data.Foreign (Foreign )
2729import Data.Options (Options , Option , (:=), options , opt )
30+
2831import Node.Process (stdin , stdout )
2932import Node.Stream (Readable , Writable )
3033
@@ -36,11 +39,10 @@ foreign import data Interface :: *
3639-- | The effect of interacting with a stream via an `Interface`
3740foreign import data READLINE :: !
3841
39- foreign import createInterfaceImpl :: forall eff .
40- Foreign
41- -> Eff ( readline :: READLINE
42- | eff
43- ) Interface
42+ foreign import createInterfaceImpl
43+ :: forall eff
44+ . Foreign
45+ -> Eff ( readline :: READLINE | eff ) Interface
4446
4547-- | Options passed to `readline`'s `createInterface`
4648data InterfaceOptions
@@ -61,73 +63,63 @@ historySize = opt "historySize"
6163-- |
6264-- | This function takes the partial command as input, and returns a collection of
6365-- | completions, as well as the matched portion of the input string.
64- type Completer eff = String -> Eff eff { completions :: Array String
65- , matched :: String }
66+ type Completer eff
67+ = String
68+ -> Eff eff
69+ { completions :: Array String
70+ , matched :: String
71+ }
6672
6773-- | Builds an interface with the specified options.
68- createInterface :: forall r eff .
69- Readable r ( readline :: READLINE
70- | eff
71- )
72- -> Options InterfaceOptions
73- -> Eff ( readline :: READLINE
74- | eff
75- ) Interface
74+ createInterface
75+ :: forall r eff
76+ . Readable r (readline :: READLINE | eff )
77+ -> Options InterfaceOptions
78+ -> Eff (readline :: READLINE | eff ) Interface
7679createInterface input opts = createInterfaceImpl
7780 $ options $ opts
7881 <> opt " input" := input
7982
8083-- | Create an interface with the specified completion function.
81- createConsoleInterface :: forall eff .
82- Completer ( readline :: READLINE
83- , console :: CONSOLE
84- , err :: EXCEPTION
85- | eff
86- )
87- -> Eff ( readline :: READLINE
88- , console :: CONSOLE
89- , err :: EXCEPTION
90- | eff
91- ) Interface
92- createConsoleInterface compl = createInterface stdin $ output := stdout
93- <> completer := compl
84+ createConsoleInterface
85+ :: forall eff
86+ . Completer (readline :: READLINE , console :: CONSOLE , err :: EXCEPTION | eff )
87+ -> Eff (readline :: READLINE , console :: CONSOLE , err :: EXCEPTION | eff ) Interface
88+ createConsoleInterface compl =
89+ createInterface stdin
90+ $ output := stdout
91+ <> completer := compl
9492
9593-- | A completion function which offers no completions.
9694noCompletion :: forall eff . Completer eff
9795noCompletion s = pure { completions: [] , matched: s }
9896
9997-- | Prompt the user for input on the specified `Interface`.
100- foreign import prompt :: forall eff .
101- Interface
102- -> Eff ( readline :: READLINE
103- | eff
104- ) Unit
98+ foreign import prompt
99+ :: forall eff
100+ . Interface
101+ -> Eff (readline :: READLINE | eff ) Unit
105102
106103-- | Set the prompt.
107- foreign import setPrompt :: forall eff .
108- String
109- -> Int
110- -> Interface
111- -> Eff ( readline :: READLINE
112- | eff
113- ) Unit
104+ foreign import setPrompt
105+ :: forall eff
106+ . String
107+ -> Int
108+ -> Interface
109+ -> Eff (readline :: READLINE | eff ) Unit
114110
115111-- | Close the specified `Interface`.
116- foreign import close :: forall eff .
117- Interface
118- -> Eff ( readline :: READLINE
119- | eff
120- ) Unit
112+ foreign import close
113+ :: forall eff
114+ . Interface
115+ -> Eff (readline :: READLINE | eff ) Unit
121116
122117-- | A function which handles each line of input.
123118type LineHandler eff a = String -> Eff eff a
124119
125120-- | Set the current line handler function.
126- foreign import setLineHandler :: forall eff a .
127- Interface
128- -> LineHandler ( readline :: READLINE
129- | eff
130- ) a
131- -> Eff ( readline :: READLINE
132- | eff
133- ) Unit
121+ foreign import setLineHandler
122+ :: forall eff a
123+ . Interface
124+ -> LineHandler (readline :: READLINE | eff ) a
125+ -> Eff (readline :: READLINE | eff ) Unit
0 commit comments