Skip to content

Commit 577d3b8

Browse files
committed
misc: don't use fmt/color.h instead just \x1b
I don't know why but it's so damn slow when printing to stdout and then to stderr, in my other program it was mixing up text input. I don't know if it's a bug fixed the latest {fmt} git version so I won't report it right away
1 parent 924ca91 commit 577d3b8

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

cufetchpm/src/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ const std::unordered_map<std::string_view, OPs> map{
6363
{ "list", LIST },
6464
{ "help", HELP },
6565
{ "enable", ENABLE },
66-
{ "disable", UNINSTALL },
66+
{ "disable", DISABLE },
67+
{ "uninstall", UNINSTALL },
6768
{ "gen-manifest", GEN_MANIFEST },
6869
};
6970

include/libcufetch/common.hh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
#include <cstdlib>
2929

30-
#include "fmt/color.h"
3130
#include "fmt/core.h"
3231

3332
constexpr const char NOCOLOR[] = "\033[0m";
@@ -47,8 +46,6 @@ constexpr const char MAGIC_LINE[] = "(cut this line NOW!! RAHHH)";
4746
#define PLUGIN_INIT void start
4847
#define PLUGIN_FINISH void finish
4948

50-
#define BOLD_COLOR(x) (fmt::emphasis::bold | fmt::fg(fmt::rgb(x)))
51-
5249
#if DEBUG
5350
inline bool debug_print = true;
5451
#else
@@ -58,14 +55,14 @@ inline bool debug_print = false;
5855
template <typename... Args>
5956
void error(const std::string_view fmt, Args&&... args) noexcept
6057
{
61-
fmt::print(stderr, BOLD_COLOR(fmt::color::red), "ERROR: {}\033[0m\n",
58+
fmt::print(stderr, "\033[1;31mERROR: {}\033[0m\n",
6259
fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
6360
}
6461

6562
template <typename... Args>
6663
void die(const std::string_view fmt, Args&&... args) noexcept
6764
{
68-
fmt::print(stderr, BOLD_COLOR(fmt::color::red), "FATAL: {}\033[0m\n",
65+
fmt::print(stderr, "\033[1;31mFATAL: {}\033[0m\n",
6966
fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
7067
std::exit(1);
7168
}
@@ -74,22 +71,20 @@ template <typename... Args>
7471
void debug(const std::string_view fmt, Args&&... args) noexcept
7572
{
7673
if (debug_print)
77-
fmt::print(BOLD_COLOR((fmt::color::hot_pink)), "[DEBUG]:\033[0m {}\n",
74+
fmt::print("\033[1;38;2;255;105;180m[DEBUG]:\033[0m {}\n",
7875
fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
7976
}
8077

8178
template <typename... Args>
8279
void warn(const std::string_view fmt, Args&&... args) noexcept
8380
{
84-
fmt::print(BOLD_COLOR((fmt::color::yellow)), "WARNING: {}\033[0m\n",
81+
fmt::print("\033[1;33mWARNING: {}\033[0m\n",
8582
fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
8683
}
8784

8885
template <typename... Args>
8986
void info(const std::string_view fmt, Args&&... args) noexcept
9087
{
91-
fmt::print(BOLD_COLOR((fmt::color::cyan)), "INFO: {}\033[0m\n",
88+
fmt::print("\033[1;36mINFO: {}\033[0m\n",
9289
fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
9390
}
94-
95-
#undef BOLD_COLOR

libcufetch/parse.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include "libcufetch/common.hh"
4242
#include "libcufetch/config.hh"
4343
#include "libcufetch/cufetch.hh"
44-
#include "fmt/color.h"
4544
#include "fmt/format.h"
4645
#include "switch_fnv1a.hpp"
4746
#include "util.hpp"

src/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ std::string shorten_vendor_name(std::string vendor)
262262
fmt::rgb hexStringToColor(const std::string_view hexstr)
263263
{
264264
std::stringstream ss;
265-
ss << std::hex << hexstr.substr(1).data();
265+
ss << std::hex << ((hexstr[0] == '#') ? hexstr.substr(1).data() : hexstr.data());
266266

267267
uint value;
268268
ss >> value;

0 commit comments

Comments
 (0)