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

Disable styles if nargo output is redirected to a pipe/file #5074

Closed
gnull opened this issue May 22, 2024 · 0 comments · Fixed by #5346
Closed

Disable styles if nargo output is redirected to a pipe/file #5074

gnull opened this issue May 22, 2024 · 0 comments · Fixed by #5346
Labels
enhancement New feature or request

Comments

@gnull
Copy link

gnull commented May 22, 2024

Problem

It's a common practice for unix tools to disable color and styles output when the output is not a terminal. Or have an option to disable color output manually. See --color option for ls, for example.

nargo seems to always produce colorful output. This breaks some use cases when you may be running it from Vim/Emacs and seeing its output in a buffer that doesn't support terminal escape sequences. Or if you're grepping it.

Happy Case

I expect nargo compile to produce colorful output in my terminal, but nargo compile | cat to have no colors. Alternatively, add an option so that nargo --color=never disables colors and nargo --color=always force-enables them.

Project Impact

Nice-to-have

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@gnull gnull added the enhancement New feature or request label May 22, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir May 22, 2024
github-merge-queue bot pushed a commit that referenced this issue Jun 27, 2024
This will also honor `TERM=dumb` and the `NO_COLOR` env vars.

# Description

## Problem

Resolves #5074

## Summary

`nargo` errors are written to stderr. These were always using colors. In
this PR we check if stderr is a terminal and just then use colors,
otherwise we don't. Actually, if is a terminal we don't always output
colors: we use
`[ColorChoice::Auto](https://docs.rs/termcolor/latest/termcolor/enum.ColorChoice.html#variant.Auto)`
which will honor some standard env vars like `TERM=dumb` or `NO_COLOR`.

This change will also improve error messages outputted in `cargo test`
inside `nargo_cli` when something is supposed to compile but doesn't.

Note that this does just one alternative proposed in #5074. Another
thing is adding a `--color` option. I think that could be done in a
separate PR (if really wanted/needed).

## Additional Context

None.

## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant