-
-
Notifications
You must be signed in to change notification settings - Fork 310
Open
Description
Describe the bug
Prompt is not waited for when in non TTY mode but as a pipe target.
I'd like to pipe some curl data to a prompt, let the user select an entry and output this choice for the next member in the pipe chain as input.
curl mysite.com/prompt | myscript.js | someotherscript.ja
To Reproduce
- Create a file with the README sample code
#!/usr/bin/env node
// eslint-disable-next-line node/shebang
const prompts = require("prompts");
(async () => {
if (!process.stdin.isTTY) {
//process.stdin.resume()
process.stdin.setEncoding("utf8")
const json = await new Promise((resolve, reject) => {
var data = ""
process.stdin.on("data", function(chunk) {
data += chunk
})
process.stdin.on("end", () => {
resolve(JSON.parse(data))
})
process.stdin.on("error", reject)
})
}
const response = await prompts({
type: "number",
name: "value",
message: "How old are you?",
validate: value => value < 18 ? "Nightclub is 18+ only" : true
})
console.log(response) // => { value: 24 }
})()
Pipe some input to it: curl google.com | myscript.js
Expected behavior
Expected the prompt to be shown (it does show) and waited for user input.
ivkos and farkmarnum
Metadata
Metadata
Assignees
Labels
No labels