diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-18 15:34:22 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-18 15:34:22 +0100 |
commit | b92da3c729c8fc7c002cb3acbb75c56cb63bd89e (patch) | |
tree | 454b64d31b7e0c9151da88a0d49ee782565f49e9 /src/crepe/util/LogColor.h | |
parent | 8b449e764b5c91cd3cb0c4fa404a290ab295a7ef (diff) | |
parent | 121b64b1cb6cfead5814070c8b0185d3d7308095 (diff) |
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/events
Diffstat (limited to 'src/crepe/util/LogColor.h')
-rw-r--r-- | src/crepe/util/LogColor.h | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/src/crepe/util/LogColor.h b/src/crepe/util/LogColor.h index c1170cb..132fb94 100644 --- a/src/crepe/util/LogColor.h +++ b/src/crepe/util/LogColor.h @@ -4,23 +4,35 @@ namespace crepe { +/** + * \brief Utility class for coloring text using ANSI escape codes + * + * \note Most methods in this class return a reference to \c this, which may be + * used to chain multiple display attributes. + */ class LogColor { public: - LogColor() = default; + /** + * \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: - //! get color code as c-style string (or color content string) - const char * c_str(const char * content = NULL); - //! color printf-style format string - const char * fmt(const char * fmt, ...); - //! get color code as stl string (or color content string) - const std::string str(const std::string & content = ""); - -public: - //! reset color to default foreground and background color + //! Reset color to default foreground and background color 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); @@ -29,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); @@ -39,13 +59,22 @@ public: LogColor & bg_magenta(bool bright = false); LogColor & bg_cyan(bool bright = false); LogColor & bg_white(bool bright = false); + /// \} private: + /** + * \brief Append SGR escape sequence to \c this->code + * + * \param code SGR attribute number + * + * See <https://en.wikipedia.org/wiki/ANSI_escape_code> for magic number + * reference. + */ LogColor & add_code(unsigned int code); private: + //! Color escape sequence std::string code = ""; - std::string final = ""; }; } // namespace crepe |