diff --git a/docs/UnityConfigurationGuide.md b/docs/UnityConfigurationGuide.md index 49202eb22d852d2f3bfeb1392668759978bcc30d..96e5358d41ac93c4e07fbe5e8658d612aeeb3de1 100644 --- a/docs/UnityConfigurationGuide.md +++ b/docs/UnityConfigurationGuide.md @@ -337,6 +337,13 @@ things anyway, though... so this option exists for those situations. _Example:_ #define UNITY_EXCLUDE_SETJMP +##### `UNITY_OUTPUT_COLOR` + +If you want to add color using ANSI escape codes you can use this define. +t +_Example:_ + #define UNITY_OUTPUT_COLOR + ## Getting Into The Guts diff --git a/src/unity.c b/src/unity.c index 216e005d7f423a0bcdcb5788f5a91bfb1dc5323c..dbf87258717a040bb9132271089d63f78eb613a3 100644 --- a/src/unity.c +++ b/src/unity.c @@ -19,10 +19,17 @@ void UNITY_OUTPUT_CHAR(int); struct UNITY_STORAGE_T Unity; +#ifdef UNITY_OUTPUT_COLOR +static const char UnityStrOk[] = "\033[42mOK\033[00m"; +static const char UnityStrPass[] = "\033[42mPASS\033[00m"; +static const char UnityStrFail[] = "\033[41mFAIL\033[00m"; +static const char UnityStrIgnore[] = "\033[43mIGNORE\033[00m"; +#else static const char UnityStrOk[] = "OK"; static const char UnityStrPass[] = "PASS"; static const char UnityStrFail[] = "FAIL"; static const char UnityStrIgnore[] = "IGNORE"; +#endif static const char UnityStrNull[] = "NULL"; static const char UnityStrSpacer[] = ". "; static const char UnityStrExpected[] = " Expected "; @@ -84,6 +91,18 @@ void UnityPrint(const char* string) UNITY_OUTPUT_CHAR('\\'); UNITY_OUTPUT_CHAR('n'); } +#ifdef UNITY_OUTPUT_COLOR + /* print ANSI escape code */ + else if (*pch == 27 && *(pch + 1) == '[') + { + while (*pch && *pch != 'm') + { + UNITY_OUTPUT_CHAR(*pch); + pch++; + } + UNITY_OUTPUT_CHAR('m'); + } +#endif /* unprintable characters are shown as codes */ else {