progress: render a single download with the same table as several

block() no longer special-cases one download with a [bracketed] one-liner;
it always draws the summary line, the column header, and one row per
download. The non-TTY path emits the same summary for one or many. This
drops lineOne and the dual rendering path it created, so a column or state
change is made in one place, not two that could drift.
This commit is contained in:
2026-06-22 08:42:30 +09:00
parent cf9082ff72
commit 7545b046af
2 changed files with 18 additions and 88 deletions

View File

@@ -78,42 +78,6 @@ func TestRatesKeyedByID(t *testing.T) {
}
}
// TestLineOneSeeding: while seeding, render SEED(ratio), drop DL:, keep UL:.
func TestLineOneSeeding(t *testing.T) {
r := newReporter(true)
s := download.Stat{
ID: "h", Name: "f", IsBT: true, Status: download.Seeding,
Total: 1000, Completed: 1000, Uploaded: 1500, Conns: 3, Seeders: 2,
}
line := r.lineOne(s)
if !strings.Contains(line, "SEED(1.5)") {
t.Errorf("missing SEED(1.5): %q", line)
}
if strings.Contains(line, "DL:") {
t.Errorf("DL: should be dropped while seeding: %q", line)
}
if !strings.Contains(line, "UL:") {
t.Errorf("UL: should be kept while seeding: %q", line)
}
}
// TestLineOneCNSD: CN always shown; SD shown for torrents (even with 0 seeders),
// absent for HTTP.
func TestLineOneCNSD(t *testing.T) {
r := newReporter(true)
bt := r.lineOne(download.Stat{ID: "h", Name: "f", IsBT: true, Total: 10, Completed: 1, Conns: 4, Seeders: 0})
if !strings.Contains(bt, "CN:4") || !strings.Contains(bt, "SD:0") {
t.Errorf("torrent line missing CN/SD: %q", bt)
}
http := r.lineOne(download.Stat{ID: "h2", Name: "f", IsBT: false, Total: 10, Completed: 1, Conns: 1})
if !strings.Contains(http, "CN:1") {
t.Errorf("http line missing CN: %q", http)
}
if strings.Contains(http, "SD:") {
t.Errorf("http line should not show SD: %q", http)
}
}
func TestPctField(t *testing.T) {
if got := pctField(download.Stat{Status: download.Active, Total: 100, Completed: 50}); got != " 50%" {
t.Errorf("active 50%% = %q, want ' 50%%'", got)
@@ -183,6 +147,10 @@ func TestBlockTableAndFallback(t *testing.T) {
if got := r.block(stats); len(got) != 4 { // summary + header + 2 rows
t.Errorf("table block = %d lines, want 4:\n%v", len(got), got)
}
// A single download renders the same way as several: summary + header + 1 row.
if got := r.block(stats[:1]); len(got) != 3 {
t.Errorf("single-download block = %d lines, want 3 (summary+header+row):\n%v", len(got), got)
}
r.height = 5 // 4 lines fit with the bottom row left free
if got := r.block(stats); len(got) != 4 {
t.Errorf("just-fits block = %d lines, want 4:\n%v", len(got), got)