1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

add CMake option to disable colored log output

Signed-off-by: Steffen Vogel <steffen.vogel@opal-rt.com>
This commit is contained in:
Steffen Vogel 2023-04-03 09:42:32 +00:00 committed by Steffen Vogel
parent 655bc5f9d6
commit 60dbd2c545
4 changed files with 26 additions and 7 deletions

View file

@ -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

View file

@ -8,12 +8,19 @@
#pragma once
#include <villas/config.hpp>
// 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

View file

@ -46,3 +46,5 @@
/** Width of log output in characters */
#define LOG_WIDTH 80
#define LOG_HEIGHT 25
#cmakedefine LOG_COLOR_DISABLE

View file

@ -8,6 +8,7 @@
#include <cstdlib>
#include <cstring>
#include <villas/config.hpp>
#include <villas/utils.hpp>
#include <villas/table.hpp>
#include <villas/colors.hpp>
@ -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);