From 0ab8dba84b559b49b8081964ce63713fcdf16509 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 17 Jan 2010 21:10:28 +0000 Subject: [PATCH] improve client_test rendering for checking and queued for checking torrents --- examples/client_test.cpp | 102 ++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 45 deletions(-) diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 26960391a..bb3e4666f 100644 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -311,8 +311,8 @@ std::string const& progress_bar(int progress, int width, char const* code = "33" int progress_chars = (progress * width + 500) / 1000; bar = esc(code); std::fill_n(std::back_inserter(bar), progress_chars, '#'); - bar += esc("0"); std::fill_n(std::back_inserter(bar), width - progress_chars, '-'); + bar += esc("0"); return bar; } @@ -1299,63 +1299,75 @@ int main(int argc, char* argv[]) if (s.num_incomplete >= 0) downloaders = s.num_incomplete; else downloaders = s.list_peers - s.list_seeds; - snprintf(str, sizeof(str), "%-13s down: (%s%s%s) up: %s%s%s (%s%s%s) swarm: %4d:%4d" - " bw queue: (%d|%d) all-time (Rx: %s%s%s Tx: %s%s%s) seed rank: %x%s\n" - , (paused && !auto_managed)?"paused":(paused && auto_managed)?"queued":state_str[s.state] - , esc("32"), add_suffix(s.total_download).c_str(), term - , esc("31"), add_suffix(s.upload_rate, "/s").c_str(), term - , esc("31"), add_suffix(s.total_upload).c_str(), term - , downloaders, seeds - , s.up_bandwidth_queue, s.down_bandwidth_queue - , esc("32"), add_suffix(s.all_time_download).c_str(), term - , esc("31"), add_suffix(s.all_time_upload).c_str(), term - , s.seed_rank, esc("0")); - out += str; + if (s.state != torrent_status::queued_for_checking && s.state != torrent_status::checking_files) + { + snprintf(str, sizeof(str), "%-13s down: (%s%s%s) up: %s%s%s (%s%s%s) swarm: %4d:%4d" + " bw queue: (%d|%d) all-time (Rx: %s%s%s Tx: %s%s%s) seed rank: %x%s\n" + , (paused && !auto_managed)?"paused":(paused && auto_managed)?"queued":state_str[s.state] + , esc("32"), add_suffix(s.total_download).c_str(), term + , esc("31"), add_suffix(s.upload_rate, "/s").c_str(), term + , esc("31"), add_suffix(s.total_upload).c_str(), term + , downloaders, seeds + , s.up_bandwidth_queue, s.down_bandwidth_queue + , esc("32"), add_suffix(s.all_time_download).c_str(), term + , esc("31"), add_suffix(s.all_time_upload).c_str(), term + , s.seed_rank, esc("0")); + out += str; - if (torrent_index != active_torrent && s.state == torrent_status::seeding) continue; - char const* progress_bar_color = "33"; // yellow - if (s.state == torrent_status::checking_files - || s.state == torrent_status::downloading_metadata) - { - progress_bar_color = "35"; // magenta + if (torrent_index != active_torrent && s.state == torrent_status::seeding) continue; + char const* progress_bar_color = "33"; // yellow + if (s.state == torrent_status::downloading_metadata) + { + progress_bar_color = "35"; // magenta + } + else if (s.current_tracker.empty()) + { + progress_bar_color = "31"; // red + } + else if (sess_stat.has_incoming_connections) + { + progress_bar_color = "32"; // green + } + + snprintf(str, sizeof(str), " %-10s: %s%-10"PRId64"%s Bytes %6.2f%% %s\n" + , sequential_download?"sequential":"progress" + , esc("32"), s.total_done, esc("0") + , s.progress_ppm / 10000.f + , progress_bar(s.progress_ppm / 1000, terminal_width - 42, progress_bar_color).c_str()); + out += str; } - else if (s.current_tracker.empty()) + else { - progress_bar_color = "31"; // red - } - else if (sess_stat.has_incoming_connections) - { - progress_bar_color = "32"; // green + snprintf(str, sizeof(str), "%-13s %s\n" + , state_str[s.state] + , progress_bar(s.progress_ppm / 1000, terminal_width - 42 - 20, "35").c_str()); + out += str; } - snprintf(str, sizeof(str), " %-10s: %s%-10"PRId64"%s Bytes %6.2f%% %s\n" - , sequential_download?"sequential":"progress" - , esc("32"), s.total_done, esc("0") - , s.progress_ppm / 10000.f - , progress_bar(s.progress_ppm / 1000, terminal_width - 42, progress_bar_color).c_str()); - out += str; - - if (print_piece_bar && s.progress_ppm < 1000000) + if (print_piece_bar && s.progress_ppm < 1000000 && s.progress > 0) { out += " "; out += piece_bar(s.pieces, terminal_width - 7); out += "\n"; } - boost::posix_time::time_duration t = s.next_announce; - snprintf(str, sizeof(str) - , " peers: %s%d%s (%s%d%s) seeds: %s%d%s distributed copies: %s%4.2f%s " + if (s.state != torrent_status::queued_for_checking && s.state != torrent_status::checking_files) + { + boost::posix_time::time_duration t = s.next_announce; + snprintf(str, sizeof(str) + , " peers: %s%d%s (%s%d%s) seeds: %s%d%s distributed copies: %s%4.2f%s " "sparse regions: %d download: %s%s%s next announce: %s%02d:%02d:%02d%s " "tracker: %s%s%s\n" - , esc("37"), s.num_peers, esc("0") - , esc("37"), s.connect_candidates, esc("0") - , esc("37"), s.num_seeds, esc("0") - , esc("37"), s.distributed_copies, esc("0") - , s.sparse_regions - , esc("32"), add_suffix(s.download_rate, "/s").c_str(), esc("0") - , esc("37"), t.hours(), t.minutes(), t.seconds(), esc("0") - , esc("36"), s.current_tracker.c_str(), esc("0")); - out += str; + , esc("37"), s.num_peers, esc("0") + , esc("37"), s.connect_candidates, esc("0") + , esc("37"), s.num_seeds, esc("0") + , esc("37"), s.distributed_copies, esc("0") + , s.sparse_regions + , esc("32"), add_suffix(s.download_rate, "/s").c_str(), esc("0") + , esc("37"), t.hours(), t.minutes(), t.seconds(), esc("0") + , esc("36"), s.current_tracker.c_str(), esc("0")); + out += str; + } if (torrent_index != active_torrent) continue; active_handle = h;