15#include <fmt/format.h>
37 static bool enabled =
true;
57 HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
60 if (hOut != INVALID_HANDLE_VALUE && GetConsoleMode(hOut, &dwMode)) {
61 SetConsoleMode(hOut, dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
78 inline std::string
styled(std::string
const& s, fmt::terminal_color c) {
83 return fmt::format(
"\033[{}m{}\033[39m",
static_cast<uint8_t
>(c), s);
89 inline std::string
error(std::string
const& s) {
90 return styled(s, fmt::terminal_color::red);
96 inline std::string
success(std::string
const& s) {
97 return styled(s, fmt::terminal_color::green);
106 inline std::string
emphasis(std::string
const& s) {
111 return fmt::format(
"\033[1m{}\033[22m", s);
117 inline std::string
muted(std::string
const& s) {
118 return styled(s, fmt::terminal_color::bright_black);
124 inline std::string
info(std::string
const& s) {
125 return styled(s, fmt::terminal_color::cyan);
131 inline std::string
warning(std::string
const& s) {
132 return styled(s, fmt::terminal_color::yellow);
144 inline std::string
link(std::string
const& url, std::string
const&
text) {
150 return fmt::format(
"\x1b]8;;{}\x07{}\x1b]8;;\x07", url,
text);
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:89
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:124
std::string link(std::string const &url, std::string const &text)
Wrap text in an OSC 8 hyperlink targeting url.
Definition Color.hpp:144
std::string emphasis(std::string const &s)
Format text in bold (for emphasis / labels).
Definition Color.hpp:106
std::string warning(std::string const &s)
Format text in yellow (for warnings).
Definition Color.hpp:131
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:78
std::string success(std::string const &s)
Format text in green (for success messages).
Definition Color.hpp:96
std::string muted(std::string const &s)
Format text in dim gray (for hints and secondary info).
Definition Color.hpp:117