aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/util')
-rw-r--r--src/crepe/util/Log.cpp9
-rw-r--r--src/crepe/util/Log.h17
-rw-r--r--src/crepe/util/Log.hpp3
-rw-r--r--src/crepe/util/LogColor.cpp65
-rw-r--r--src/crepe/util/LogColor.h24
-rw-r--r--src/crepe/util/Proxy.h4
6 files changed, 55 insertions, 67 deletions
diff --git a/src/crepe/util/Log.cpp b/src/crepe/util/Log.cpp
index e583734..84d80a8 100644
--- a/src/crepe/util/Log.cpp
+++ b/src/crepe/util/Log.cpp
@@ -1,9 +1,8 @@
-#include <cstdarg>
-#include <cstdio>
-#include <cstdlib>
+#include <iostream>
#include <string>
#include "../api/Config.h"
+
#include "Log.h"
using namespace crepe;
@@ -33,6 +32,6 @@ void Log::log(const Level & level, const string & msg) {
if (!out.ends_with("\n")) out += "\n";
// TODO: also log to file or smth
- fwrite(out.c_str(), 1, out.size(), stdout);
- fflush(stdout);
+ cout.write(out.data(), out.size());
+ cout.flush();
}
diff --git a/src/crepe/util/Log.h b/src/crepe/util/Log.h
index 01452b2..d55b11e 100644
--- a/src/crepe/util/Log.h
+++ b/src/crepe/util/Log.h
@@ -9,16 +9,14 @@
// utility macros
#define _crepe_logf_here(level, fmt, ...) \
- crepe::Log::logf( \
- level, "{}" fmt, \
- crepe::LogColor().fg_white(false).str(std::format( \
- "{} ({}:{})", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__)), \
- __VA_ARGS__)
+ crepe::Log::logf(level, "{}" fmt, \
+ crepe::LogColor().fg_white(false).str(std::format( \
+ "{} ({}:{})", __PRETTY_FUNCTION__, __FILE_NAME__, __LINE__)), \
+ __VA_ARGS__)
// very illegal global function-style macros
// NOLINTBEGIN
-#define dbg_logf(fmt, ...) \
- _crepe_logf_here(crepe::Log::Level::DEBUG, ": " fmt, __VA_ARGS__)
+#define dbg_logf(fmt, ...) _crepe_logf_here(crepe::Log::Level::DEBUG, ": " fmt, __VA_ARGS__)
#define dbg_log(str) _crepe_logf_here(crepe::Log::Level::DEBUG, ": {}", str)
#define dbg_trace() _crepe_logf_here(crepe::Log::Level::TRACE, "", "")
// NOLINTEND
@@ -59,8 +57,7 @@ public:
* \param args Format arguments
*/
template <class... Args>
- static void logf(const Level & level, std::format_string<Args...> fmt,
- Args &&... args);
+ static void logf(const Level & level, std::format_string<Args...> fmt, Args &&... args);
/**
* \brief Format a message and log it (with default severity \c INFO)
@@ -76,6 +73,8 @@ private:
* \brief Output a message prefix depending on the log level
*
* \param level Message severity
+ *
+ * \return Colored message severity prefix string
*/
static std::string prefix(const Level & level);
};
diff --git a/src/crepe/util/Log.hpp b/src/crepe/util/Log.hpp
index 651f076..c2156cd 100644
--- a/src/crepe/util/Log.hpp
+++ b/src/crepe/util/Log.hpp
@@ -10,8 +10,7 @@ void Log::logf(std::format_string<Args...> fmt, Args &&... args) {
}
template <class... Args>
-void Log::logf(const Level & level, std::format_string<Args...> fmt,
- Args &&... args) {
+void Log::logf(const Level & level, std::format_string<Args...> fmt, Args &&... args) {
Log::log(level, std::format(fmt, std::forward<Args>(args)...));
}
diff --git a/src/crepe/util/LogColor.cpp b/src/crepe/util/LogColor.cpp
index ae44d72..5411898 100644
--- a/src/crepe/util/LogColor.cpp
+++ b/src/crepe/util/LogColor.cpp
@@ -1,6 +1,7 @@
#include <cstdarg>
#include "../api/Config.h"
+
#include "LogColor.h"
using namespace crepe;
@@ -27,51 +28,19 @@ LogColor & LogColor::reset() {
return *this;
}
-LogColor & LogColor::fg_black(bool bright) {
- return this->add_code(bright ? 90 : 30);
-}
-LogColor & LogColor::fg_red(bool bright) {
- return this->add_code(bright ? 91 : 31);
-}
-LogColor & LogColor::fg_green(bool bright) {
- return this->add_code(bright ? 92 : 32);
-}
-LogColor & LogColor::fg_yellow(bool bright) {
- return this->add_code(bright ? 93 : 33);
-}
-LogColor & LogColor::fg_blue(bool bright) {
- return this->add_code(bright ? 94 : 34);
-}
-LogColor & LogColor::fg_magenta(bool bright) {
- return this->add_code(bright ? 95 : 35);
-}
-LogColor & LogColor::fg_cyan(bool bright) {
- return this->add_code(bright ? 96 : 36);
-}
-LogColor & LogColor::fg_white(bool bright) {
- return this->add_code(bright ? 97 : 37);
-}
-LogColor & LogColor::bg_black(bool bright) {
- return this->add_code(bright ? 100 : 40);
-}
-LogColor & LogColor::bg_red(bool bright) {
- return this->add_code(bright ? 101 : 41);
-}
-LogColor & LogColor::bg_green(bool bright) {
- return this->add_code(bright ? 102 : 42);
-}
-LogColor & LogColor::bg_yellow(bool bright) {
- return this->add_code(bright ? 103 : 43);
-}
-LogColor & LogColor::bg_blue(bool bright) {
- return this->add_code(bright ? 104 : 44);
-}
-LogColor & LogColor::bg_magenta(bool bright) {
- return this->add_code(bright ? 105 : 45);
-}
-LogColor & LogColor::bg_cyan(bool bright) {
- return this->add_code(bright ? 106 : 46);
-}
-LogColor & LogColor::bg_white(bool bright) {
- return this->add_code(bright ? 107 : 47);
-}
+LogColor & LogColor::fg_black(bool bright) { return this->add_code(bright ? 90 : 30); }
+LogColor & LogColor::fg_red(bool bright) { return this->add_code(bright ? 91 : 31); }
+LogColor & LogColor::fg_green(bool bright) { return this->add_code(bright ? 92 : 32); }
+LogColor & LogColor::fg_yellow(bool bright) { return this->add_code(bright ? 93 : 33); }
+LogColor & LogColor::fg_blue(bool bright) { return this->add_code(bright ? 94 : 34); }
+LogColor & LogColor::fg_magenta(bool bright) { return this->add_code(bright ? 95 : 35); }
+LogColor & LogColor::fg_cyan(bool bright) { return this->add_code(bright ? 96 : 36); }
+LogColor & LogColor::fg_white(bool bright) { return this->add_code(bright ? 97 : 37); }
+LogColor & LogColor::bg_black(bool bright) { return this->add_code(bright ? 100 : 40); }
+LogColor & LogColor::bg_red(bool bright) { return this->add_code(bright ? 101 : 41); }
+LogColor & LogColor::bg_green(bool bright) { return this->add_code(bright ? 102 : 42); }
+LogColor & LogColor::bg_yellow(bool bright) { return this->add_code(bright ? 103 : 43); }
+LogColor & LogColor::bg_blue(bool bright) { return this->add_code(bright ? 104 : 44); }
+LogColor & LogColor::bg_magenta(bool bright) { return this->add_code(bright ? 105 : 45); }
+LogColor & LogColor::bg_cyan(bool bright) { return this->add_code(bright ? 106 : 46); }
+LogColor & LogColor::bg_white(bool bright) { return this->add_code(bright ? 107 : 47); }
diff --git a/src/crepe/util/LogColor.h b/src/crepe/util/LogColor.h
index 4b65127..132fb94 100644
--- a/src/crepe/util/LogColor.h
+++ b/src/crepe/util/LogColor.h
@@ -12,7 +12,13 @@ namespace crepe {
*/
class LogColor {
public:
- //! Get color code as stl string (or color content string)
+ /**
+ * \brief Get color code as STL string
+ *
+ * \param content If given, color this string and append a color reset escape sequence.
+ *
+ * \returns Color escape sequence
+ */
const std::string str(const std::string & content = "") const;
public:
@@ -20,6 +26,13 @@ public:
LogColor & reset();
public:
+ /**
+ * \name Foreground colors
+ *
+ * These functions set the foreground (text) color. The \c bright parameter
+ * makes the color brighter, or bold on some terminals.
+ * \{
+ */
LogColor & fg_black(bool bright = false);
LogColor & fg_red(bool bright = false);
LogColor & fg_green(bool bright = false);
@@ -28,8 +41,16 @@ public:
LogColor & fg_magenta(bool bright = false);
LogColor & fg_cyan(bool bright = false);
LogColor & fg_white(bool bright = false);
+ /// \}
public:
+ /**
+ * \name Background colors
+ *
+ * These functions set the background color. The \c bright parameter makes
+ * the color brighter.
+ * \{
+ */
LogColor & bg_black(bool bright = false);
LogColor & bg_red(bool bright = false);
LogColor & bg_green(bool bright = false);
@@ -38,6 +59,7 @@ public:
LogColor & bg_magenta(bool bright = false);
LogColor & bg_cyan(bool bright = false);
LogColor & bg_white(bool bright = false);
+ /// \}
private:
/**
diff --git a/src/crepe/util/Proxy.h b/src/crepe/util/Proxy.h
index f84e462..b34f7c6 100644
--- a/src/crepe/util/Proxy.h
+++ b/src/crepe/util/Proxy.h
@@ -7,8 +7,8 @@ namespace crepe {
/**
* \brief Utility wrapper for \c ValueBroker
*
- * This class can be used to to wrap a ValueBroker instance so it behaves like
- * a regular variable.
+ * This class can be used to to wrap a ValueBroker instance so it behaves like a regular
+ * variable.
*
* \tparam T Type of the underlying variable
*/