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

Redirect Output #519

Closed
brianantonelli opened this issue Mar 27, 2017 · 15 comments
Closed

Redirect Output #519

brianantonelli opened this issue Mar 27, 2017 · 15 comments

Comments

@brianantonelli
Copy link

Would love to see a configuration option to redirect output to stderr instead of stdout. That way programs could support functionality like:

eval $(myapp dosomething)

Then we could then display the prompt through stderr so that only the response will be evaluated.

@remyrylan
Copy link

@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 */)

@SBoudrias
Copy link
Owner

@jrylan thanks for following up with the proper way to handle it <3

@brianantonelli
Copy link
Author

Thx!

@brianantonelli
Copy link
Author

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

@remyrylan
Copy link

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

@brianantonelli
Copy link
Author

brianantonelli commented Jun 27, 2017

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.

@SBoudrias
Copy link
Owner

@brianantonelli weird, but that doesn't seem relate to Inquirer. As you might guess, we're not snooping in on your AWS creds.

@brianantonelli
Copy link
Author

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.

@SBoudrias
Copy link
Owner

@brianantonelli I'm not super familiar with that, but any chance some ANSI control chars can't be use on stderr?

@brianantonelli
Copy link
Author

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');
  • Running node test.js > out.txt && vi out.txt shows no control characters:
test
  • Running node test.js inq > out.txt && vi out.txt shows control characters:
^[[?25ltest
^[[?25h^[[?25h

@brianantonelli
Copy link
Author

Any ideas?

@popey456963
Copy link

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

@brianantonelli
Copy link
Author

Can't those be disabled?

@popey456963
Copy link

popey456963 commented Jul 17, 2017

@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 jlord/sheetsee.js#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.

@SBoudrias
Copy link
Owner

Simpler yet, I believe chalk doesn't print colors when --no-color is in the process argv.

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

No branches or pull requests

4 participants