Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1774

How to get command line input?

$
0
0

I know this was over a year ago but in trying to find a solution for ReScript Bun this question is the only thing in the forum so thought I’d post a solution I cobbled together after a lot of googling. I’m using rescript-bun but I guess a similar solution should work for rescript-nodejs.

let {close, question} = module(Readline.Interface)
let rl = Readline.make({
  input: %raw(`process.stdin`),
  output: %raw(`process.stdout`),
})

let answer = await Promise.make((resolve, _reject) => {
  rl->question("? ", resolve)
})

answer->Console.log
rl->close

I was struggling to find what was a RescriptBun.Stream.Readable.subtype<RescriptBun.Buffer.t, 'rtype> for the input and output fields, so I found a similar solution in an old ReasonML forum that used the %raw solution to provide process.stdin/stdout.

I found out via stackoverflow how to get the command line input value out by wrapping the question call in a promise.


Viewing all articles
Browse latest Browse all 1774

Trending Articles