Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select and multiselect spams terminal when redirecting stdout #274

Closed
AumyF opened this issue Oct 4, 2020 · 0 comments · Fixed by #275
Closed

Select and multiselect spams terminal when redirecting stdout #274

AumyF opened this issue Oct 4, 2020 · 0 comments · Fixed by #275

Comments

@AumyF
Copy link
Contributor

AumyF commented Oct 4, 2020

Describe the bug

Some prompts spam terminal when redirecting stdout.
As far as I found out, some prompts include "select", "multiselect", "number", "autosuggest", and "autosuggestMultiselect".

To Reproduce

  1. Create a file and call prompt with { type: "select", stdout: process.stderr }.
const { prompt } = require("prompts");

(async () => {
  const r = await prompt({
    name: "spam",
    type: "select",
    message: "Pick one!",
    stdout: process.stderr,
    choices: [
      { value: "Charmander" },
      { value: "Bulbasaur" },
      { value: "Squirtle" },
      { value: "Pikachu" },
      { value: "Eevee" },
    ],
  });
})();
  1. Run the script and redirect stdout to something (such as /dev/null).
    image

    Type "number" will not output duplicately until some errors occurs.
    image

  2. When removing redirection it runs correctly.
    image

Expected behavior

Should run properly even if stdout is redirected.

System

  • OS: Ubuntu 20.04 on WSL on Windows 10 2004
  • Terminal: Windows Terminal (used in the screenshots), VSCode integrated, and WSL console
  • Node version: both v8.17.0 and v14.11.0

Additional context

This issue seems to be caused by clear function. It uses process.stdout.columns even if it should use process.stderr.columns. When stdout is redirected to something, process.stdout.columns will be undefined, so "clear" clears nothing.

similar issues: #89 #153 #175

AumyF added a commit to AumyF/prompts that referenced this issue Oct 4, 2020
terkelg pushed a commit that referenced this issue Oct 6, 2020
* Fix(select, multiselect) duplicate output when stdout is redirected (fixes #274)

* Remove process.stdout from util functions internals
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant