improve windows output of client_test

This commit is contained in:
arvidn 2016-02-27 19:40:04 -05:00
parent ac2916c426
commit 296a38efba
2 changed files with 14 additions and 6 deletions

View File

@ -376,9 +376,13 @@ FILE* g_log_file = 0;
std::string const& piece_bar(libtorrent::bitfield const& p, int width) 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; static std::string bar;
bar.clear(); bar.clear();
bar.reserve(width * 6); 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) for (int k = int(piece); k < end; ++k, ++num_pieces)
if (p[k]) ++num_have; if (p[k]) ++num_have;
int color = int(std::ceil(num_have / float((std::max)(num_pieces, 1)) * (table_size - 1))); int color = int(std::ceil(num_have / float((std::max)(num_pieces, 1)) * (table_size - 1)));
char buf[10]; char buf[40];
snprintf(buf, 10, "48;5;%d", 232 + color); #ifdef _WIN32
bar += esc(buf); 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 += " ";
} }
bar += esc("0"); bar += esc("0");

View File

@ -88,7 +88,7 @@ std::string const& progress_bar(int progress, int width, color_code c
bar.clear(); bar.clear();
bar.reserve(size_t(width + 10)); bar.reserve(size_t(width + 10));
int progress_chars = (progress * width + 500) / 1000; int const progress_chars = (progress * width + 500) / 1000;
if (caption.empty()) if (caption.empty())
{ {