Skip to content

Commit

Permalink
Removed print_colored.
Browse files Browse the repository at this point in the history
Renamed enum colors back to color.
  • Loading branch information
Remotion committed Jun 9, 2018
1 parent ef2f510 commit 2e0053a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 44 deletions.
26 changes: 21 additions & 5 deletions include/fmt/colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

FMT_BEGIN_NAMESPACE

enum class colors : uint32_t;
enum class color : uint32_t;

// rgb is a struct for red, green and blue colors.
// We use rgb as name because some editors will show it as color direct in the
Expand Down Expand Up @@ -74,24 +74,40 @@ inline void vprint_rgb(rgb fd, rgb bg, string_view format, format_args args) {
std::fputs(RESET_COLOR, stdout);
}

/**
Formats a string and prints it to stdout using ANSI escape sequences to
specify foreground color 'fd'.
Example:
fmt::print_rgb(fmt::color::red, "Elapsed time: {0:.2f} seconds", 1.23);
*/
template <typename... Args>
inline void print_rgb(rgb fd, string_view format_str, const Args & ... args) {
vprint_rgb(fd, format_str, make_format_args(args...));
}

// rgb foreground color
/**
Formats a string and prints it to stdout using ANSI escape sequences to
specify foreground color 'fd'.
Example:
fmt::print(fmt::color::red, "Elapsed time: {0:.2f} seconds", 1.23);
*/
template <typename... Args>
inline void print(rgb fd, string_view format_str, const Args & ... args) {
vprint_rgb(fd, format_str, make_format_args(args...));
}

// rgb foreground color and background color
/**
Formats a string and prints it to stdout using ANSI escape sequences to
specify foreground color 'fd' and background color 'bg'.
Example:
fmt::print(fmt::color::red, fmt::color::black, "Elapsed time: {0:.2f} seconds", 1.23);
*/
template <typename... Args>
inline void print(rgb fd, rgb bg, string_view format_str, const Args & ... args) {
vprint_rgb(fd, bg, format_str, make_format_args(args...));
}

enum class colors : uint32_t {
enum class color : uint32_t {
alice_blue = 0xF0F8FF, // rgb(240,248,255)
antique_white = 0xFAEBD7, // rgb(250,235,215)
aqua = 0x00FFFF, // rgb(0,255,255)
Expand Down Expand Up @@ -233,7 +249,7 @@ enum class colors : uint32_t {
white_smoke = 0xF5F5F5, // rgb(245,245,245)
yellow = 0xFFFF00, // rgb(255,255,0)
yellow_green = 0x9ACD32, // rgb(154,205,50)
}; // enum class colors
}; // enum class color

FMT_END_NAMESPACE

Expand Down
23 changes: 0 additions & 23 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1181,29 +1181,6 @@ inline internal::named_arg<T, wchar_t> arg(wstring_view name, const T &arg) {
template <typename S, typename T, typename Char>
void arg(S, internal::named_arg<T, Char>) FMT_DELETED;

enum color { black, red, green, yellow, blue, magenta, cyan, white };

FMT_API void vprint_colored(color c, string_view format, format_args args);
FMT_API void vprint_colored(color c, wstring_view format, wformat_args args);

/**
Formats a string and prints it to stdout using ANSI escape sequences to
specify color (experimental).
Example:
fmt::print_colored(fmt::RED, "Elapsed time: {0:.2f} seconds", 1.23);
*/
template <typename... Args>
inline void print_colored(color c, string_view format_str,
const Args & ... args) {
vprint_colored(c, format_str, make_format_args(args...));
}

template <typename... Args>
inline void print_colored(color c, wstring_view format_str,
const Args & ... args) {
vprint_colored(c, format_str, make_format_args<wformat_context>(args...));
}

format_context::iterator vformat_to(
internal::buffer &buf, string_view format_str, format_args args);
wformat_context::iterator vformat_to(
Expand Down
16 changes: 0 additions & 16 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,22 +499,6 @@ FMT_FUNC void vprint(wstring_view format_str, wformat_args args) {
vprint(stdout, format_str, args);
}

FMT_FUNC void vprint_colored(color c, string_view format, format_args args) {
char escape[] = "\x1b[30m";
escape[3] = static_cast<char>('0' + c);
std::fputs(escape, stdout);
vprint(format, args);
std::fputs(RESET_COLOR, stdout);
}

FMT_FUNC void vprint_colored(color c, wstring_view format, wformat_args args) {
wchar_t escape[] = L"\x1b[30m";
escape[3] = static_cast<wchar_t>('0' + c);
std::fputws(escape, stdout);
vprint(format, args);
std::fputws(WRESET_COLOR, stdout);
}

FMT_FUNC locale locale_provider::locale() { return fmt::locale(); }

FMT_END_NAMESPACE
Expand Down

0 comments on commit 2e0053a

Please sign in to comment.