diff --git a/docs/UnityConfigurationGuide.md b/docs/UnityConfigurationGuide.md index 49202eb..96e5358 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 9783efa..da04be6 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 "; @@ -83,6 +90,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 {