2
2
3
3
module Node.ReadLine
4
4
( Interface
5
- , READLINE
6
5
, InterfaceOptions
7
6
, Completer
8
7
, LineHandler
@@ -22,11 +21,9 @@ module Node.ReadLine
22
21
23
22
import Prelude
24
23
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 )
28
25
29
- import Data. Foreign (Foreign )
26
+ import Foreign (Foreign )
30
27
import Data.Options (Options , Option , (:=), options , opt )
31
28
32
29
import Node.Process (stdin , stdout )
@@ -37,21 +34,15 @@ import Node.Stream (Readable, Writable)
37
34
-- | A handle can be created with the `createInterface` function.
38
35
foreign import data Interface :: Type
39
36
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
47
38
48
39
-- | Options passed to `readline`'s `createInterface`
49
- data InterfaceOptions
40
+ foreign import data InterfaceOptions :: Type
50
41
51
- output :: forall w eff . Option InterfaceOptions (Writable w eff )
42
+ output :: forall w . Option InterfaceOptions (Writable w )
52
43
output = opt " output"
53
44
54
- completer :: forall eff . Option InterfaceOptions ( Completer eff )
45
+ completer :: Option InterfaceOptions Completer
55
46
completer = opt " completer"
56
47
57
48
terminal :: Option InterfaceOptions Boolean
@@ -64,73 +55,62 @@ historySize = opt "historySize"
64
55
-- |
65
56
-- | This function takes the partial command as input, and returns a collection of
66
57
-- | completions, as well as the matched portion of the input string.
67
- type Completer eff
58
+ type Completer
68
59
= String
69
- -> Eff eff
60
+ -> Effect
70
61
{ completions :: Array String
71
62
, matched :: String
72
63
}
73
64
74
65
-- | Builds an interface with the specified options.
75
66
createInterface
76
- :: forall r eff
77
- . Readable r ( readline :: READLINE | eff )
67
+ :: forall r
68
+ . Readable r
78
69
-> Options InterfaceOptions
79
- -> Eff ( readline :: READLINE | eff ) Interface
70
+ -> Effect Interface
80
71
createInterface input opts = createInterfaceImpl
81
72
$ options $ opts
82
73
<> opt " input" := input
83
74
84
75
-- | 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
89
77
createConsoleInterface compl =
90
78
createInterface stdin
91
79
$ output := stdout
92
80
<> completer := compl
93
81
94
82
-- | A completion function which offers no completions.
95
- noCompletion :: forall eff . Completer eff
83
+ noCompletion :: Completer
96
84
noCompletion s = pure { completions: [] , matched: s }
97
85
98
86
-- | 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
103
88
104
89
-- | Writes a query to the output, waits
105
90
-- | for user input to be provided on input, then invokes
106
91
-- | the callback function
107
92
foreign import question
108
- :: forall eff
109
- . String
110
- -> (String -> Eff (readline :: READLINE | eff ) Unit )
93
+ :: String
94
+ -> (String -> Effect Unit )
111
95
-> Interface
112
- -> Eff ( readline :: READLINE | eff ) Unit
96
+ -> Effect Unit
113
97
114
98
-- | Set the prompt.
115
99
foreign import setPrompt
116
- :: forall eff
117
- . String
100
+ :: String
118
101
-> Int
119
102
-> Interface
120
- -> Eff ( readline :: READLINE | eff ) Unit
103
+ -> Effect Unit
121
104
122
105
-- | 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
127
107
128
108
-- | A function which handles each line of input.
129
- type LineHandler eff a = String -> Eff eff a
109
+ type LineHandler a = String -> Effect a
130
110
131
111
-- | Set the current line handler function.
132
112
foreign import setLineHandler
133
- :: forall eff a
113
+ :: forall a
134
114
. Interface
135
- -> LineHandler ( readline :: READLINE | eff ) a
136
- -> Eff ( readline :: READLINE | eff ) Unit
115
+ -> LineHandler a
116
+ -> Effect Unit
0 commit comments