Kaynağa Gözat

Two changes to stat output:

1. Show the number of torrents with tracker errors on the total status line.
2. Show the torrent status character on the status line instead of the name
   line. This only has effect when the '-i' flag is given.
master
Richard Nyberg 19 yıl önce
ebeveyn
işleme
a1f2f9faae
1 değiştirilmiş dosya ile 14 ekleme ve 17 silme
  1. +14
    -17
      cli/btcli.c

+ 14
- 17
cli/btcli.c Dosyayı Görüntüle

@@ -44,31 +44,26 @@ handle_ipc_res(enum ipc_code code, const char *target)
return code; return code;
} }


void
print_state_name(struct tpstat *ts)
char
state_char(struct tpstat *ts)
{ {
char c;
switch (ts->state) { switch (ts->state) {
case T_STARTING: case T_STARTING:
c = '+';
break;
return '+';
case T_ACTIVE: case T_ACTIVE:
c = ts->pieces_got == ts->torrent_pieces ? 'S' : 'L';
break;
return ts->pieces_got == ts->torrent_pieces ? 'S' : 'L';
case T_STOPPING: case T_STOPPING:
c = '-';
break;
return '-';
default: default:
c = 'U';
break;
return ' ';
} }
printf("%c. %s", c, ts->name);
} }


void void
print_stat(struct tpstat *ts) print_stat(struct tpstat *ts)
{ {
printf("%5.1f%% %6.1fM %7.2fkB/s %6.1fM %7.2fkB/s %4u %5.1f%%",
printf("%c %5.1f%% %6.1fM %7.2fkB/s %6.1fM %7.2fkB/s %4u %5.1f%%",
state_char(ts),
100.0 * ts->content_got / ts->content_size, 100.0 * ts->content_got / ts->content_size,
(double)ts->downloaded / (1 << 20), (double)ts->downloaded / (1 << 20),
(double)ts->rate_down / (20 << 10), (double)ts->rate_down / (20 << 10),
@@ -281,8 +276,8 @@ cmd_list(int argc, char **argv)
if (handle_ipc_res(btpd_stat(ipc, &st), "list") != IPC_OK) if (handle_ipc_res(btpd_stat(ipc, &st), "list") != IPC_OK)
exit(1); exit(1);
for (int i = 0; i < st->ntorrents; i++) { for (int i = 0; i < st->ntorrents; i++) {
print_state_name(&st->torrents[i]);
putchar('\n');
struct tpstat *ts = &st->torrents[i];
printf("%c. %s\n", state_char(ts), ts->name);
} }
printf("%u torrent%s.\n", st->ntorrents, printf("%u torrent%s.\n", st->ntorrents,
st->ntorrents == 1 ? "" : "s"); st->ntorrents == 1 ? "" : "s");
@@ -320,6 +315,7 @@ do_stat(int individual, int seconds, int hash_count, uint8_t (*hashes)[20])
struct tpstat tot; struct tpstat tot;
again: again:
bzero(&tot, sizeof(tot)); bzero(&tot, sizeof(tot));
tot.state = -1;
if (handle_ipc_res(btpd_stat(ipc, &st), "stat") != IPC_OK) if (handle_ipc_res(btpd_stat(ipc, &st), "stat") != IPC_OK)
exit(1); exit(1);
for (int i = 0; i < st->ntorrents; i++) { for (int i = 0; i < st->ntorrents; i++) {
@@ -341,9 +337,10 @@ again:
tot.torrent_pieces += cur->torrent_pieces; tot.torrent_pieces += cur->torrent_pieces;
tot.content_got += cur->content_got; tot.content_got += cur->content_got;
tot.content_size += cur->content_size; tot.content_size += cur->content_size;
if (cur->tr_errors > 0)
tot.tr_errors++;
if (individual) { if (individual) {
print_state_name(cur);
printf(":\n");
printf("%s:\n", cur->name);
print_stat(cur); print_stat(cur);
} }
} }


Yükleniyor…
İptal
Kaydet