From 296a38efbaecadfe2c51b594c8e12eea2102ac83 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 27 Feb 2016 19:40:04 -0500 Subject: [PATCH] improve windows output of client_test --- examples/client_test.cpp | 18 +++++++++++++----- examples/print.cpp | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index c376b7e4f..87fcb83cf 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -376,9 +376,13 @@ FILE* g_log_file = 0; std::string const& piece_bar(libtorrent::bitfield const& p, int width) { - const int table_size = 18; +#ifdef _WIN32 + int const table_size = 2; +#else + int const table_size = 18; +#endif - double piece_per_char = p.size() / double(width); + double const piece_per_char = p.size() / double(width); static std::string bar; bar.clear(); bar.reserve(width * 6); @@ -400,9 +404,13 @@ std::string const& piece_bar(libtorrent::bitfield const& p, int width) for (int k = int(piece); k < end; ++k, ++num_pieces) if (p[k]) ++num_have; int color = int(std::ceil(num_have / float((std::max)(num_pieces, 1)) * (table_size - 1))); - char buf[10]; - snprintf(buf, 10, "48;5;%d", 232 + color); - bar += esc(buf); + char buf[40]; +#ifdef _WIN32 + snprintf(buf, sizeof(buf), "\x1b[4%dm", color ? 7 : 0); +#else + snprintf(buf, sizeof(buf), "\x1b[48;5;%dm", 232 + color); +#endif + bar += buf; bar += " "; } bar += esc("0"); diff --git a/examples/print.cpp b/examples/print.cpp index 44639cf05..83f888c77 100644 --- a/examples/print.cpp +++ b/examples/print.cpp @@ -88,7 +88,7 @@ std::string const& progress_bar(int progress, int width, color_code c bar.clear(); bar.reserve(size_t(width + 10)); - int progress_chars = (progress * width + 500) / 1000; + int const progress_chars = (progress * width + 500) / 1000; if (caption.empty()) {