15#include <fmt/format.h>
37 static bool enabled =
true;
56 HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
59 if (hOut != INVALID_HANDLE_VALUE && GetConsoleMode(hOut, &dwMode)) {
60 SetConsoleMode(hOut, dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
76 inline std::string
styled(std::string
const& s, fmt::terminal_color c) {
80 return fmt::format(
"\033[{}m{}\033[39m",
static_cast<uint8_t
>(c), s);
86 inline std::string
error(std::string
const& s) {
87 return styled(s, fmt::terminal_color::red);
93 inline std::string
success(std::string
const& s) {
94 return styled(s, fmt::terminal_color::green);
103 inline std::string
emphasis(std::string
const& s) {
107 return fmt::format(
"\033[1m{}\033[22m", s);
113 inline std::string
muted(std::string
const& s) {
114 return styled(s, fmt::terminal_color::bright_black);
120 inline std::string
info(std::string
const& s) {
121 return styled(s, fmt::terminal_color::cyan);
127 inline std::string
warning(std::string
const& s) {
128 return styled(s, fmt::terminal_color::yellow);
TTY-aware ANSI colored output utilities.
Definition Color.hpp:31
std::string error(std::string const &s)
Format text in red (for error messages).
Definition Color.hpp:86
void init_color(bool no_color)
Initialize color support based on TTY detection and user preference.
Definition Color.hpp:49
bool & color_enabled()
Global toggle for colored output.
Definition Color.hpp:36
std::string info(std::string const &s)
Format text in cyan (for informational highlights like progress bars).
Definition Color.hpp:120
std::string emphasis(std::string const &s)
Format text in bold (for emphasis / labels).
Definition Color.hpp:103
std::string warning(std::string const &s)
Format text in yellow (for warnings).
Definition Color.hpp:127
std::string styled(std::string const &s, fmt::terminal_color c)
Apply a foreground color with a specific reset (\033[39m) instead of fmt's full reset,...
Definition Color.hpp:76
std::string success(std::string const &s)
Format text in green (for success messages).
Definition Color.hpp:93
std::string muted(std::string const &s)
Format text in dim gray (for hints and secondary info).
Definition Color.hpp:113