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

Only produce color error message when outputting to terminal #129

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

laurenthuberdeau
Copy link
Collaborator

Context

In #121, we added color to some of the error messages produced by pnut (when NICE_ERR_MSG is on). Howver, we forgot to take into account that the output of pnut is often redirected to a file, where we don't want to see color codes.

Fortunately, the test POSIX shell utility can be used to check what a file descriptor is a terminal, which allows pnut to only output color codes when stdout is a terminal.

-t file_descriptor
True if file descriptor number file_descriptor is open and is associated with a terminal. False if file_descriptor is not a valid file descriptor number, or if file descriptor number file_descriptor is not open, or if it is open but is not associated with a terminal.

isatty - test whether a file descriptor refers to a terminal

This function will be used in the next commit to determine whether to
produce colored error messages depending on whether the output is a
terminal or not.
Pnut's output is often redirected to a file, and in that case we don't
want to emit color codes.
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.

1 participant