Skip to content

Prompt not waited for when running as pipe target #236

@pke

Description

@pke

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

  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions