diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 0c6ec266c..a1d46efcf 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -58,6 +58,9 @@ if(CRITERION_FOUND AND TOPLEVEL_PROJECT) add_subdirectory(tests) endif() +# Disable any colored log output +option(LOG_COLOR_DISABLE "Disable any colored log output" OFF) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/include/villas/config.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/villas/config.hpp diff --git a/common/include/villas/colors.hpp b/common/include/villas/colors.hpp index cf805467a..75315faec 100644 --- a/common/include/villas/colors.hpp +++ b/common/include/villas/colors.hpp @@ -8,12 +8,19 @@ #pragma once +#include + // CPP stringification #define XSTR(x) STR(x) #define STR(x) #x // Some color escape codes for pretty log messages -#define CLR(clr, str) "\e[" XSTR(clr) "m" str "\e[0m" +#ifdef LOG_COLOR_DISABLE + #define CLR(clr, str) str +#else + #define CLR(clr, str) "\e[" XSTR(clr) "m" str "\e[0m" +#endif + #define CLR_GRY(str) CLR(30, str) // Print str in gray #define CLR_RED(str) CLR(31, str) // Print str in red #define CLR_GRN(str) CLR(32, str) // Print str in green diff --git a/common/include/villas/config.hpp.in b/common/include/villas/config.hpp.in index 49a502d0e..1e12bb1fd 100644 --- a/common/include/villas/config.hpp.in +++ b/common/include/villas/config.hpp.in @@ -46,3 +46,5 @@ /** Width of log output in characters */ #define LOG_WIDTH 80 #define LOG_HEIGHT 25 + +#cmakedefine LOG_COLOR_DISABLE diff --git a/common/lib/table.cpp b/common/lib/table.cpp index 53d6d5f5b..26ad0b755 100644 --- a/common/lib/table.cpp +++ b/common/lib/table.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -17,6 +18,12 @@ using namespace villas; using namespace villas::utils; +#if !defined(LOG_COLOR_DISABLE) + #define ANSI_RESET "\e[0m" +#else + #define ANSI_RESET +#endif + int Table::resize(int w) { int norm, flex, fixed, total; @@ -70,12 +77,12 @@ void Table::header() u = columns[i]._width + strlen(unit) - strlenp(unit); if (columns[i].align == TableColumn::Alignment::LEFT) { - strcatf(&line1, " %-*.*s\e[0m", w, w, col); - strcatf(&line2, " %-*.*s\e[0m", u, u, unit); + strcatf(&line1, " %-*.*s" ANSI_RESET, w, w, col); + strcatf(&line2, " %-*.*s" ANSI_RESET, u, u, unit); } else { - strcatf(&line1, " %*.*s\e[0m", w, w, col); - strcatf(&line2, " %*.*s\e[0m", u, u, unit); + strcatf(&line1, " %*.*s" ANSI_RESET, w, w, col); + strcatf(&line2, " %*.*s" ANSI_RESET, u, u, unit); } for (int j = 0; j < columns[i]._width + 2; j++) { @@ -121,9 +128,9 @@ void Table::row(int count, ...) int w = columns[i]._width + r - l; if (columns[i].align == TableColumn::Alignment::LEFT) - strcatf(&line, " %-*.*s\e[0m ", w, w, col); + strcatf(&line, " %-*.*s " ANSI_RESET, w, w, col); else - strcatf(&line, " %*.*s\e[0m ", w, w, col); + strcatf(&line, " %*.*s " ANSI_RESET, w, w, col); if (i != columns.size() - 1) strcatf(&line, BOX_UD);