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

Skipping second prompt? #132

Open
mikeRead opened this issue Oct 17, 2015 · 15 comments
Open

Skipping second prompt? #132

mikeRead opened this issue Oct 17, 2015 · 15 comments

Comments

@mikeRead
Copy link

I have a very simple script (shown below) but it is printing out the first input and then skipping the second prompt is this a known issue? and/or anyone know how I can fix this?

var prompt = require('prompt');
var input_schema = {
    properties: {
        promptOne:{
            description:"prompt 1",
            default:"prompt 1"
         },
         promptTwo:{
            description:"prompt 2 (skips this)",
            default:"prompt 2 (skips this)"
         },
         promptThree:{
            description:"prompt 3",
            default:"prompt 3"
         },
    }
};  
prompt.start();
prompt.get(input_schema, function (err, result) {
    console.log(result)    
});

here is what happens when i try to enter each prompt

S:\github\example>node example-code-above.js
prompt: prompt 1:  (prompt 1) I'm entering the first prompt
I'm entering the first prompt
prompt: prompt 2 (skips this):  (prompt 2 (skips this))
prompt: prompt 3:  (prompt 3) I'm entering the second prompt
{ promptOne: 'I\'m entering the first prompt',
  promptTwo: 'prompt 2 (skips this)',
  promptThree: 'I\'m entering the second prompt ' }
@cameronk
Copy link

I'm having the same issue. First input gets output to the console, second is skipped and returns undefined.

@mikeRead
Copy link
Author

@cameronk we are talking about it on issue number #131 . it seems to be a windows 10 bug (or possibly just a windows bug)

@nickdbush
Copy link

So many modules use prompt that it would be great to have a fix!

@gangstead
Copy link
Member

I'm also thinking a windows bug, when I tried locally (on a mac):
image

Anybody with a windows machine able to take a look?

@gangstead
Copy link
Member

@cameronk @mikeRead over in #131 they are reporting their similar-sounding issue being resolved on node v5. Can you see if that fixes it for you?

@adnaan1703
Copy link

I am using node v5.7.0 and still facing this problem and I am on windows8.1.

@gangstead
Copy link
Member

Thanks for checking. I'll keep investigating.

@janunezc
Copy link

same happening in my case. GIT Bash and Windows 8.1 Command Prompt

@objelke
Copy link

objelke commented May 2, 2016

it's highly timing dependent it seems, entering random logging makes it irregular.

for some reason, the read library:

rl.on('line', onLine)
is issuing an event instantly.

patching the read library
https://github.com/npm/read

// wrap the line event listener in a timeout
setTimeout(function () {
// original code
        rl.on('line', onLine)

        function onLine(line) {
            if (called) return
            if (silent && terminal) {
                output.unmute()
                output.write('\r\n')
            }
            done('on_line')
            // truncate the \n at the end.
            line = line.replace(/\r?\n$/, '')
            var isDefault = !!(editDef && line === def)
            if (def && !line) {
                isDefault = true
                line = def
            }
            cb(null, line, isDefault)
        }
// wrap in timeout, end code
    }, 100);

will cover it up. Not a solution, just a hack - spent to many hours already on this.
flushing process.stdIn is unfortunately not an option.

@nikhiljha
Copy link

Broken on Node 6, Windows 10 as well (bash/no bash)
Broken on Node 5, Windows 10 (bash/no bash)

@simonmarklar
Copy link

Also happening to me, windows 10, node 5

I found a fix, but its ugly.

in lib/prompt.js, the read command is setup. if the options object includes terminal: false and stdout.isTTY is set to false before the read() call, then no errors occur and everything works as expected on windows (i dont have a mac to test this)

This just feels like a bad idea overwritingstdout.isTTY. But if its not done there, you'd need to patch the read module and it looks like its been abandoned (or at least there has been no activity for more than 6 months)

I'm also not sure if there are any "bad effects" of setting stdout.isTTY to false, or if patching read so that it only checks opts.terminal and ignores the output stream's .isTTY property will break things due to Ansi//VT100 escape codes not being written to "it"

@simonmarklar
Copy link

and the above "fix" fails the 3rd "interactive test", but perhaps I entered in the required prompt wrong, the wording of the test confused me. no matter what I entered it asked me again then on the second time failed the test. I assume this is why terminal is true.

@realjck
Copy link

realjck commented Jun 29, 2016

TY for the fix @simonmarklar

@simonmarklar
Copy link

@jckleinbourg I believe this is actually a bug in libuv that was fixed in a recent node release. See nodejs/node#5384 for the info

The "fix" I posted above is pretty hacky and I wouldn't use it unless I had no other choice

@realjck
Copy link

realjck commented Jun 30, 2016

@simonmarklar I use node v4.4.7 LTS. In my case it is just for a personal tool, I'm conscious that it would not be suitable for a production version.

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

No branches or pull requests

10 participants