From 1e80629770aec2bc5e1f47c33d9dda5ab7aaa942 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 8 Feb 2015 21:59:52 +0000 Subject: [PATCH] make printing of file progress more compact in client_test --- examples/client_test.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 859d027b5..8f2f2394e 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -2069,7 +2069,7 @@ int main(int argc, char* argv[]) std::sort(cs.pieces.begin(), cs.pieces.end(), boost::bind(&cached_piece_info::piece, _1) > boost::bind(&cached_piece_info::piece, _2)); - int p = 0; + int p = 0; // this is horizontal position for (std::vector::iterator i = cs.pieces.begin(); i != cs.pieces.end(); ++i) { @@ -2158,6 +2158,8 @@ int main(int argc, char* argv[]) std::vector file_prio = h.file_priorities(); std::vector::iterator f = file_status.begin(); boost::shared_ptr ti = h.torrent_file(); + + int p = 0; // this is horizontal position for (int i = 0; i < ti->num_files(); ++i) { if (pos + 1 >= terminal_height) break; @@ -2201,12 +2203,29 @@ int main(int argc, char* argv[]) ++f; } - snprintf(str, sizeof(str), "%s %s prio: %d\x1b[K\n", - progress_bar(progress, 70, complete?col_green:col_yellow, '-', '#' + const int file_progress_width = 65; + + // do we need to line-break? + if (p + file_progress_width + 13 > terminal_width) + { + out += "\x1b[K\n"; + pos += 1; + p = 0; + } + + snprintf(str, sizeof(str), "%s %7s p: %d ", + progress_bar(progress, file_progress_width, complete ? col_green : col_yellow, '-', '#' , title.c_str()).c_str() , add_suffix(file_progress[i]).c_str() , file_prio[i]); + + p += file_progress_width + 13; out += str; + } + + if (p != 0) + { + out += "\x1b[K\n"; pos += 1; } }