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

Allow cli with file name argument to be used from scripts #6

Merged
merged 2 commits into from
Jan 16, 2015

Conversation

rmg
Copy link
Contributor

@rmg rmg commented Jan 16, 2015

When invoked via exec()/system()/whatever from a parent script, stdin is generally not a TTY. In the current version of strip-ansi, this prevents any arguments from being used as the filename even if provided.

The first commit adds this scenario as a test case (initially failing). The second commit allows the filename argument, if provided, to be used when scripting.

I found this when I tried to use strip-ansi in my CI pipeline to strip colourized diffs from my TAP result files but was perplexed by the result being an empty file. I am using the cat file | strip-ansi > stripped.txt form as a workaround for now.

This test is currently failing because the file name argument is only
used if stdin is a TTY, which is not the case when being invoked from
a script.
When invoked from a parent shell script the file name was previously
ignored because stdin was closed or otherwise not detected as a TTY.
@sindresorhus
Copy link
Member

You can use spawn('strip-ansi', {stdio: 'inherit'}), but yeah, better this way.

sindresorhus added a commit that referenced this pull request Jan 16, 2015
Allow cli with file name argument to be used from scripts
@sindresorhus sindresorhus merged commit 481faa9 into chalk:master Jan 16, 2015
@rmg rmg deleted the not-a-tty branch January 17, 2015 00:54
@rmg
Copy link
Contributor Author

rmg commented Jan 17, 2015

Or system('strip-ansi', in: STDIN) since I'm calling it from Ruby.

All assuming that the parent process's stdin is a TTY and not deeply nested in some headless environment, of course ;-)

Thanks for the merge & release :-)

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 this pull request may close these issues.

2 participants