perf fix alpine x86
This commit is contained in:
+21
-2
@@ -20,6 +20,7 @@
|
||||
#define BANTAM_HPP
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
@@ -171,8 +172,26 @@ std::string_view utf8_truncate(std::string_view s, size_t max_bytes);
|
||||
|
||||
std::string filter_text(std::string_view s);
|
||||
int color_enabled(const Cfg &cfg);
|
||||
std::string cstr(std::string_view text, std::span<const int> codes);
|
||||
void cprint(std::string_view text, std::span<const int> codes);
|
||||
template<class R>
|
||||
inline std::string cstr(std::string_view text, const R& codes) {
|
||||
if (!g_col || codes.empty() || text.empty()) return std::string(text);
|
||||
std::string s;
|
||||
s.reserve(text.size() + 16);
|
||||
s += "\033[";
|
||||
for (size_t i = 0; i < codes.size(); i++) {
|
||||
if (i) s += ';';
|
||||
s += sfmt("%d", (int)codes[i]);
|
||||
}
|
||||
s += "m";
|
||||
s += text;
|
||||
s += "\033[0m";
|
||||
return s;
|
||||
}
|
||||
template<class R>
|
||||
inline void cprint(std::string_view text, const R& codes) {
|
||||
std::string w = cstr(text, codes);
|
||||
std::fputs(w.c_str(), stdout);
|
||||
}
|
||||
int visible_len(std::string_view s);
|
||||
int rune_width(int cp);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user