Skip to content

Commit

Permalink
Respect the NO_COLOR environment variable
Browse files Browse the repository at this point in the history
Update the implementation of the coloring logic in this project to
respect the NO_COLOR environment variable name to allow users to use the
tool without colored output. This can be useful when, e.g., saving the
result to a file.
  • Loading branch information
ericcornelissen committed Sep 8, 2024
1 parent b2f400f commit 4a4fe64
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/utils/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ const COLORS = <const>{
* @return {String} Message
*/
export function color(message: string, fgColor?: Color, bgColor?: Color): string {
if ('NO_COLOR' in process.env) {
return message;
}

return [
<ColorCode>get(COLORS, `${fgColor}.fg`, ''),
<ColorCode>get(COLORS, `${bgColor}.bg`, ''),
Expand Down

0 comments on commit 4a4fe64

Please sign in to comment.