Correction of 418 (#420)

This commit is contained in:
alabuzhev 2016-11-11 19:27:39 +02:00 committed by Jonathan Müller
parent 1d2049b53e
commit 25f8ad13dd
4 changed files with 22 additions and 26 deletions

View File

@ -105,6 +105,8 @@ inline int fmt_snprintf(char *buffer, size_t size, const char *format, ...) {
# define FMT_SWPRINTF swprintf
#endif // defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT)
const char RESET_COLOR[] = "\x1b[0m";
typedef void (*FormatFunc)(Writer &, int, StringRef);
// Portable thread-safe version of strerror.
@ -483,6 +485,24 @@ FMT_FUNC void report_windows_error(
}
#endif
FMT_FUNC void print(std::FILE *f, CStringRef format_str, ArgList args) {
MemoryWriter w;
w.write(format_str, args);
std::fwrite(w.data(), 1, w.size(), f);
}
FMT_FUNC void print(CStringRef format_str, ArgList args) {
print(stdout, format_str, args);
}
FMT_FUNC void print_colored(Color c, CStringRef format, ArgList args) {
char escape[] = "\x1b[30m";
escape[3] = static_cast<char>('0' + c);
std::fputs(escape, stdout);
print(format, args);
std::fputs(RESET_COLOR, stdout);
}
#ifndef FMT_HEADER_ONLY
template struct internal::BasicData<void>;

View File

@ -12,30 +12,6 @@
namespace fmt {
namespace {
const char RESET_COLOR[] = "\x1b[0m";
} // namespace
FMT_FUNC void print(std::FILE *f, CStringRef format_str, ArgList args) {
MemoryWriter w;
w.write(format_str, args);
std::fwrite(w.data(), 1, w.size(), f);
}
FMT_FUNC void print(CStringRef format_str, ArgList args) {
print(stdout, format_str, args);
}
FMT_FUNC void print_colored(Color c, CStringRef format, ArgList args) {
char escape[] = "\x1b[30m";
escape[3] = static_cast<char>('0' + c);
std::fputs(escape, stdout);
print(format, args);
std::fputs(RESET_COLOR, stdout);
}
template <typename Char>
void printf(BasicWriter<Char> &w, BasicCStringRef<Char> format, ArgList args);

View File

@ -1,4 +1,4 @@
#include "fmt/printf.h"
#include "fmt/format.h"
int main(int argc, char** argv) {
for(int i = 0; i < argc; ++i)

View File

@ -1,4 +1,4 @@
#include "fmt/printf.h"
#include "fmt/format.h"
int main(int argc, char** argv) {
for(int i = 0; i < argc; ++i)