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

Double key entry #109

Closed
stephenplusplus opened this issue Apr 28, 2014 · 28 comments
Closed

Double key entry #109

stephenplusplus opened this issue Apr 28, 2014 · 28 comments
Labels

Comments

@stephenplusplus
Copy link

I'm not sure if this is an issue here or with the generator, but the ghost issue we had before has reappeared. Here's a gif to help me explain:

yo-uh-oh mov

@SBoudrias
Copy link
Owner

You mean the npm being outputed after you exited? Or the line being duplicated at the beginning?

@stephenplusplus
Copy link
Author

Sorry, that video didn't turn out well. The line duplicated as well as when
I hit "y" to answer a question, it comes up as "yy".

On Monday, April 28, 2014, Simon Boudrias notifications@github.com wrote:

You mean the npm being outputed after you exited? Or the line being
duplicated at the beginning?


Reply to this email directly or view it on GitHubhttps://github.com//issues/109#issuecomment-41610132
.

@SBoudrias
Copy link
Owner

Alright, I wonder if that's related to a new (non backward compat) Node release. The bug appeared without any update to the core of Inquirer.

I'll have to check it out!

@danielchatfield
Copy link
Collaborator

@stephenplusplus Which generator is that with? I can see how that would happen if using the API incorrectly.

@stephenplusplus
Copy link
Author

generator-angular's latest release.

On Monday, April 28, 2014, Daniel Chatfield notifications@github.com
wrote:

@stephenplusplus https://github.com/stephenplusplus Which generator is
that with? I can see how that would happen if using the API incorrectly.


Reply to this email directly or view it on GitHubhttps://github.com//issues/109#issuecomment-41613287
.

@danielchatfield
Copy link
Collaborator

I can't reproduce this, is there anything I'm missing?

@stephenplusplus
Copy link
Author

Hmm.

$ node -v
v0.10.26

$ npm -v
1.4.3

Happens in Terminal and iTerm 2 for me.

@SBoudrias
Copy link
Owner

I tested it on iterm yesterday and I haven't been able to reproduce with node v0.10.26 on iTerm 2

But I had this bug on Windows powershell back at work...

@danielchatfield
Copy link
Collaborator

No luck on my windows machine with power shell either.

I have a feeling this is going to be a tricky one to pin down.

@zewa666
Copy link

zewa666 commented Jun 25, 2014

I'm experiencing the same issue with Node v.0.10.24 and Inquirer v0.5.1 on my Windows 8.1 machine. It just doubles every key stroke, but interestingly the value provided as answer is the proper data.

So e.g. I enter ABC -> display == AABBCC, but the value nevertheless = ABC.
I guess it may be some event emitting called twice.

EDIT:
I found the reason for my scenario at least.
I'm creating a CLI module which of course should operate cross-plattform. So I had to handle CTRL+C on windows where code like this is needed

if (process.platform === "win32"){
    var rl = readLine.createInterface ({
        input: process.stdin,
        output: process.stdout
    });

    rl.on ("SIGINT", function (){
        process.emit ("SIGINT");
    });
}

So the readLine interface is interfering with Inquirer. Hope this helps to find out how to solve the bug.

@SBoudrias SBoudrias added the bug label Sep 1, 2014
@rodriguise
Copy link

Any update on this? I'm seeing this issue on v.0.8 node 10.33.

@SBoudrias
Copy link
Owner

@rodriguise Did you ran on this issue using a yeoman-generator or running this repo examples?

@rodriguise
Copy link

No running my own code

inquirer.prompt([
{
    type: 'input',
    name: 'user',
    message: 'Enter your username',
    validate: promptRequired('username'),
    when: promptWhen(user, false)
},
{
    type: 'password',
    name: 'pass',
    message: 'Enter your password',
    validate: promptRequired('password'),
    when: promptWhen(pass, false)
},
{
    type: 'list',
    name: 'cmd',
    message: 'Select an operation',
    choices: ops,
default: false
}
], function(answers) {

user = answers.user;
pass = answers.pass;
cmd = answers.cmd;

callback();
});

@SBoudrias
Copy link
Owner

@rodriguise which prompt / operating system do you use?

@rodriguise
Copy link

OS X 10.10, Terminal.app

@rodriguise
Copy link

This behavior seems to be linked to the bottom bar.

var ui = new inquirer.ui.BottomBar();

commenting that out it goes away.

@7nights
Copy link

7nights commented Jan 7, 2015

@rodriguise
The same problem. Have you found a solution?

@mason-stewart
Copy link

FWIW, I ran into the same issue when I when requiring (and using) Inquirer in two separate modules, both of which were being required by a third module.

I resolved the issue temporarily by reducing it to a single var inquirer = require('inquirer'); for my entire app, and passing that var around when needed, which obviously isn't ideal. Hope that helps 💃

@knownasilya
Copy link

Might be unrelated, but I ran into this when I instantiated two instances of readline.

@SBoudrias
Copy link
Owner

@knownasilya Yes, that will effectively happen currently if two inquirer or readlines run at the same time.

@ruizb
Copy link

ruizb commented Jul 12, 2015

Got the same problem here with this piece of code:

var inquirer = require('inquirer');

var ui = new inquirer.ui.BottomBar();

var questions = [
  {
    name: 'firstname',
    message: 'First name?',
    validate: function (data) {
      // there are as many character duplicates as there are instanciations of BottomBar
      new inquirer.ui.BottomBar();
      new inquirer.ui.BottomBar();
      return true;
    }
  },
  {
    name: 'lastname',
    message: 'Last name?'
  }
];

inquirer.prompt(questions, function (answers) {
  console.log(answers);
});

It seems like the more there are instances of BottomBar, the more there are duplicates.

Tested on OS X Yosemite v10.10.4, node v0.10.33 and iTerm2 v2.1.1.

Screenshot

@SBoudrias
Copy link
Owner

I cannot reproduce in the latest release. I did some cleanup to events listeners a while ago, so that might just've fixed the issue.

Either way, feel free to reopen if the issue still occurs for you.

@ccostel
Copy link

ccostel commented Jan 29, 2018

I am having the same issue..
Node v8.9.4
NPM 5.6.0
iTerm
OSX 10.12.6 (16G29)

@Poyoman39
Copy link

Hey ! Same for me on windows10 with git bash (aka cygwin) and OSX terminal (using last LTS v8 nodejs and inquirer 5.2.0)

@devzsolt
Copy link

Broken for me now, inquirer 6.0.0, node v10.6.0
Btw. the old prompt package caused the same issue. Any idea guys?

@AlbertEmil
Copy link

AlbertEmil commented Dec 17, 2018

Similar problem of duplicate output here. Working with nodejs v10.14.2 and inquirer 6.2.1 on Windows 7 Pro, x64.

Project dependencies:

 "dependencies": {
    "cli-interact": "^0.1.9",
    "coffeequate": "^1.3.0",
    "inquirer": "^6.2.1"
  }

Sample output:

$ node app.js
? What's the sample volume [mL]?  2270
? What's the sample volume [mL]?  2270
? What's the sample density [g/mL]?  ,987
? What's the sample density [g/mL]?  .987
Add 1384.04 g of pure ethanol.

Tried both using cmd and Git Bash (based on MINGW64) which provide same faulty output.

Inquirer related code is as follows:

const validateFloat = (val) => {
    if ( val && val.match(/^[0-9]*[\.\,]?[0-9]*$/i) ) {
        return true
    }
    else {
        return 'Please enter a valid float'
    }
}

const replaceComma = (val) => {
    return val.replace(',', '.')
}

const questions = [
    {
        type: 'input',
        name: 'volume',
        message: "What's the sample volume [mL]? ",
        filter: (val) => replaceComma(val),
        validate: (val) => validateFloat(val),
    },
    {
        type: 'input',
        name: 'density',
        message: "What's the sample density [g/mL]? ",
        filter: (val) => replaceComma(val),        
        validate: (val) => validateFloat(val),
    },
]

inquirer.prompt(questions).then(answers => {
    for (const answer in answers) {
        answers[answer] = parseFloat(answers[answer])
    }

    const answer = query('Press any key twice to exit.')
})

@Poyoman39
Copy link

Poyoman39 commented Dec 17, 2018

I did a work around for this bug, if you can't wait for a bug fix. Just decorate the original prompt function like this =>

  const inquirer = require('inquirer');

  const pause = duration => (new Promise(resolve => (
    setTimeout(resolve, duration)
  )));

  const decoratedPrompt = async (...args) => {
    const r = await inquirer.prompt.call(inquirer, ...args);
    await pause(200);
    return r;
  }

 module.exports = {
  prompt: decoratedPrompt,
 }

... Hope it may help some of you.

@kristianoye
Copy link

I think the multiple character echo stems from multiple calls to readline.createInterface. If you have more than one module that does this, then you end up with the duplicate. Look for and eliminate any redundant calls to fix your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests