improve client_test rendering for checking and queued for checking torrents

This commit is contained in:
Arvid Norberg 2010-01-17 21:10:28 +00:00
parent 018da0e29f
commit 0ab8dba84b
1 changed files with 57 additions and 45 deletions

View File

@ -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;