Closed brianantonelli closed 7 years ago
@brianantonelli I needed this too and just discovered it's already available.
const inquirer = require('inquirer')
const prompt = inquirer.createPromptModule({ output: process.stderr })
prompt(/* question array/object here */)
@jrylan thanks for following up with the proper way to handle it <3
Thx!
So I'm still seeing some issues with this. I followed @jrylan 's instructions and my prompts are now directed to stderr
which is perfect. However, I'm still seeing some rogue control characters being sent to stdout
.. Thoughts?
^[[?25l^[[?25hexport AWS_ACCESS_KEY_ID=aaa && export AWS_SECRET_ACCESS_KEY=bbb && export AWS_SESSION_TOKEN=ccc
^[[?25h
@brianantonelli That's strange, is that on AWS? I'm using iTerm2 as my terminal on macOS and all the output is identical when using process.stderr
-- everything works perfectly fine.
No, running this on OSX in Terminal. As soon as I make the call to inquirer I get those control chars. The one at the end really throws me because its printing that many function calls later. I only see these characters in VIM. I caught this because it breaks wrapping the output in a eval $(foo)
call.
@brianantonelli weird, but that doesn't seem relate to Inquirer. As you might guess, we're not snooping in on your AWS creds.
That's just an example output from an application that leverages this library. In my application if I pipe all data to stderr using the above solution and only do a single output to stdout (the AWS keys export command in this case) I see these control characters. If I remove the call to inquirer the control chars disappear.
@brianantonelli I'm not super familiar with that, but any chance some ANSI control chars can't be use on stderr?
This only occurs if you use the list prompt. If I do a standard input prompt the characters aren't there. Here's a snippet to reproduce this:
var inquirer = require('inquirer'),
prompt = inquirer.createPromptModule({ output: process.stderr });
console.error('start');
if(process.argv[2] === 'inq'){
prompt([ { type: 'list', name: 'test', message: 'Test', choices: ['a', 'b', 'c'] }]).then(function(answers){
console.error(answers);
});
}
console.log('test');
console.error('stop');
node test.js > out.txt && vi out.txt
shows no control characters:
test
node test.js inq > out.txt && vi out.txt
shows control characters:
^[[?25ltest
^[[?25h^[[?25h
Any ideas?
@brianantonelli Those control codes are for colours. This is something inquirer uses. Vi doesn't support those control code colours, so displays the base codes. Hence you're running into an issue.
Can't those be disabled?
@brianantonelli You can use something like strip-ansi to remove ansi from a string, I've opened an issue to be able to use it with streams https://github.com/jlord/sheetsee.js/issues/26. However, it would probably be pretty simple to allow it to support streams yourself.
It's been a while since I've manipulated such streams, but with a stream.Transform it should work.
Simpler yet, I believe chalk doesn't print colors when --no-color
is in the process argv.
Would love to see a configuration option to redirect output to
stderr
instead ofstdout
. That way programs could support functionality like:Then we could then display the prompt through
stderr
so that only the response will be evaluated.