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

direnv exec has started writing ANSI escape sequences to stderr when stderr isn't a terminal #953

Closed
frou opened this issue Jun 17, 2022 · 2 comments · Fixed by #958
Closed
Labels

Comments

@frou
Copy link

frou commented Jun 17, 2022

Describe the bug

Hi there - It seems like a recent version of direnv has started making a classic mistake that many programs do, and is unconditionally writing ANSI escape sequences :)

To Reproduce

$ direnv exec . true 2>x.txt

Then open x.txt in a text editor and see that it starts with

\x1B[mdirenv: loading

Expected behavior

When writing to either of stdout/stderr, if they aren't a terminal/TTY then ANSI escape sequences shouldn't be written. So the file x.txt in the example should simply start with:

direnv: loading

Environment

  • OS: macOS 12
  • Shell: bash
  • Direnv version: 2.32.0
@frou frou added the Bug label Jun 17, 2022
@tmatilai
Copy link
Contributor

It seems like a recent version of direnv has started making a classic mistake that many programs do, and is unconditionally writing ANSI escape sequences :)

Agreed that it should check the TTY. The error messages have been printed in red for quite some years, but I guess this came visible to you because of #884 adding the reset code for status log messages.

@zimbatm
Copy link
Member

zimbatm commented Jun 23, 2022

Also, I removed the dependency on tput, which might have done the job for us.

zimbatm added a commit that referenced this issue Jun 23, 2022
Test if stderr is a tty before sending escape codes

Fixes #953
zimbatm added a commit that referenced this issue Jun 24, 2022
Test if stderr is a tty before sending escape codes

Fixes #953
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants