Skip to content

Commit

Permalink
Fix callback invocation for readline.question (#38)
Browse files Browse the repository at this point in the history
* call mkEffectFn1 on cb to question

* typo

* update changelog
  • Loading branch information
youngnh authored Jun 30, 2024
1 parent 0e5f4a8 commit 3d94029
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Breaking changes:
New features:

Bugfixes:
- Ensure that callbacks passed to `question` and `question'` are invoked
- Fixed typo in options passed to `readline.createInterface`

Other improvements:

Expand Down
2 changes: 1 addition & 1 deletion src/Node/ReadLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const createInterfaceImpl = (options) => readline.createInterface({
historySize: options.historySize,
removeHistoryDuplicates: options.removeHistoryDuplicates,
prompt: options.prompt,
crlDelay: options.crlDelay,
crlfDelay: options.crlfDelay,
escapeCodeTimeout: options.escapeCodeTimeout,
tabSize: options.tabSize,
signal: options.signal
Expand Down
8 changes: 4 additions & 4 deletions src/Node/ReadLine.purs
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ foreign import promptOptsImpl :: EffectFn2 (Boolean) (Interface) (Unit)
-- |
-- | The callback function passed to `rl.question()` does not follow the typical pattern of accepting an Error object or null as the first argument. The callback is called with the provided answer as the only argument.
question :: String -> (String -> Effect Unit) -> Interface -> Effect Unit
question text cb iface = runEffectFn3 questionImpl iface text cb
question text cb iface = runEffectFn3 questionImpl iface text $ mkEffectFn1 cb

foreign import questionImpl :: EffectFn3 (Interface) (String) ((String -> Effect Unit)) Unit
foreign import questionImpl :: EffectFn3 (Interface) (String) (EffectFn1 String Unit) Unit

-- | Writes a query to the output, waits
-- | for user input to be provided on input, then invokes
Expand All @@ -338,9 +338,9 @@ foreign import questionImpl :: EffectFn3 (Interface) (String) ((String -> Effect
-- |
-- | The callback function passed to `rl.question()` does not follow the typical pattern of accepting an Error object or null as the first argument. The callback is called with the provided answer as the only argument.
question' :: String -> { signal :: AbortSignal } -> (String -> Effect Unit) -> Interface -> Effect Unit
question' text opts cb iface = runEffectFn4 questionOptsCbImpl iface text opts cb
question' text opts cb iface = runEffectFn4 questionOptsCbImpl iface text opts $ mkEffectFn1 cb

foreign import questionOptsCbImpl :: EffectFn4 (Interface) (String) { signal :: AbortSignal } ((String -> Effect Unit)) Unit
foreign import questionOptsCbImpl :: EffectFn4 (Interface) (String) { signal :: AbortSignal } (EffectFn1 String Unit) Unit

-- | The rl.resume() method resumes the input stream if it has been paused.
resume :: Interface -> Effect Unit
Expand Down

0 comments on commit 3d94029

Please sign in to comment.