22
33module Node.ReadLine
44 ( Interface
5- , READLINE
65 , InterfaceOptions
76 , Completer
87 , LineHandler
@@ -22,11 +21,9 @@ module Node.ReadLine
2221
2322import Prelude
2423
25- import Control.Monad.Eff (kind Effect , Eff )
26- import Control.Monad.Eff.Console (CONSOLE )
27- import Control.Monad.Eff.Exception (EXCEPTION )
24+ import Effect (Effect )
2825
29- import Data. Foreign (Foreign )
26+ import Foreign (Foreign )
3027import Data.Options (Options , Option , (:=), options , opt )
3128
3229import Node.Process (stdin , stdout )
@@ -37,21 +34,15 @@ import Node.Stream (Readable, Writable)
3734-- | A handle can be created with the `createInterface` function.
3835foreign import data Interface :: Type
3936
40- -- | The effect of interacting with a stream via an `Interface`
41- foreign import data READLINE :: Effect
42-
43- foreign import createInterfaceImpl
44- :: forall eff
45- . Foreign
46- -> Eff ( readline :: READLINE | eff ) Interface
37+ foreign import createInterfaceImpl :: Foreign -> Effect Interface
4738
4839-- | Options passed to `readline`'s `createInterface`
49- data InterfaceOptions
40+ foreign import data InterfaceOptions :: Type
5041
51- output :: forall w eff . Option InterfaceOptions (Writable w eff )
42+ output :: forall w . Option InterfaceOptions (Writable w )
5243output = opt " output"
5344
54- completer :: forall eff . Option InterfaceOptions ( Completer eff )
45+ completer :: Option InterfaceOptions Completer
5546completer = opt " completer"
5647
5748terminal :: Option InterfaceOptions Boolean
@@ -64,73 +55,62 @@ historySize = opt "historySize"
6455-- |
6556-- | This function takes the partial command as input, and returns a collection of
6657-- | completions, as well as the matched portion of the input string.
67- type Completer eff
58+ type Completer
6859 = String
69- -> Eff eff
60+ -> Effect
7061 { completions :: Array String
7162 , matched :: String
7263 }
7364
7465-- | Builds an interface with the specified options.
7566createInterface
76- :: forall r eff
77- . Readable r ( readline :: READLINE | eff )
67+ :: forall r
68+ . Readable r
7869 -> Options InterfaceOptions
79- -> Eff ( readline :: READLINE | eff ) Interface
70+ -> Effect Interface
8071createInterface input opts = createInterfaceImpl
8172 $ options $ opts
8273 <> opt " input" := input
8374
8475-- | Create an interface with the specified completion function.
85- createConsoleInterface
86- :: forall eff
87- . Completer (readline :: READLINE , console :: CONSOLE , exception :: EXCEPTION | eff )
88- -> Eff (readline :: READLINE , console :: CONSOLE , exception :: EXCEPTION | eff ) Interface
76+ createConsoleInterface :: Completer -> Effect Interface
8977createConsoleInterface compl =
9078 createInterface stdin
9179 $ output := stdout
9280 <> completer := compl
9381
9482-- | A completion function which offers no completions.
95- noCompletion :: forall eff . Completer eff
83+ noCompletion :: Completer
9684noCompletion s = pure { completions: [] , matched: s }
9785
9886-- | Prompt the user for input on the specified `Interface`.
99- foreign import prompt
100- :: forall eff
101- . Interface
102- -> Eff (readline :: READLINE | eff ) Unit
87+ foreign import prompt :: Interface -> Effect Unit
10388
10489-- | Writes a query to the output, waits
10590-- | for user input to be provided on input, then invokes
10691-- | the callback function
10792foreign import question
108- :: forall eff
109- . String
110- -> (String -> Eff (readline :: READLINE | eff ) Unit )
93+ :: String
94+ -> (String -> Effect Unit )
11195 -> Interface
112- -> Eff ( readline :: READLINE | eff ) Unit
96+ -> Effect Unit
11397
11498-- | Set the prompt.
11599foreign import setPrompt
116- :: forall eff
117- . String
100+ :: String
118101 -> Int
119102 -> Interface
120- -> Eff ( readline :: READLINE | eff ) Unit
103+ -> Effect Unit
121104
122105-- | Close the specified `Interface`.
123- foreign import close
124- :: forall eff
125- . Interface
126- -> Eff (readline :: READLINE | eff ) Unit
106+ foreign import close :: Interface -> Effect Unit
127107
128108-- | A function which handles each line of input.
129- type LineHandler eff a = String -> Eff eff a
109+ type LineHandler a = String -> Effect a
130110
131111-- | Set the current line handler function.
132112foreign import setLineHandler
133- :: forall eff a
113+ :: forall a
134114 . Interface
135- -> LineHandler ( readline :: READLINE | eff ) a
136- -> Eff ( readline :: READLINE | eff ) Unit
115+ -> LineHandler a
116+ -> Effect Unit
0 commit comments