diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-15 20:26:26 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-15 20:26:26 +0100 |
commit | 5bee4515c1089ce3499bc3b74780db94f0c02306 (patch) | |
tree | 3e18158665e45851b92c61095664fc16060c8fd2 /src/crepe/util | |
parent | 8600b8a29351aae26ec7b22f84aeeef92d8cb421 (diff) |
process feedback on #26
Diffstat (limited to 'src/crepe/util')
-rw-r--r-- | src/crepe/util/Log.cpp | 9 | ||||
-rw-r--r-- | src/crepe/util/Log.h | 2 | ||||
-rw-r--r-- | src/crepe/util/LogColor.cpp | 1 | ||||
-rw-r--r-- | src/crepe/util/LogColor.h | 24 |
4 files changed, 30 insertions, 6 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..e0844ca 100644 --- a/src/crepe/util/Log.h +++ b/src/crepe/util/Log.h @@ -76,6 +76,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/LogColor.cpp b/src/crepe/util/LogColor.cpp index ae44d72..170ddcf 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; 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: /** |