From 11a373200fb561f71e0e998ef31032a93e98e85f Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 3 May 2020 18:41:33 +1000 Subject: [PATCH] cmd/torrent: Only output progress lines when they change This stops spamming output when seeding. --- cmd/torrent/main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/torrent/main.go b/cmd/torrent/main.go index a346cdfb..02e58997 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -34,6 +34,7 @@ func torrentBar(t *torrent.Torrent, pieceStates bool) { fmt.Printf("getting info for %q\n", t.Name()) <-t.GotInfo() } + var lastLine string for { var completedPieces, partialPieces int psrs := t.PieceStateRuns() @@ -45,7 +46,7 @@ func torrentBar(t *torrent.Torrent, pieceStates bool) { partialPieces += r.Length } } - fmt.Printf( + line := fmt.Sprintf( "downloading %q: %s/%s, %d/%d pieces completed (%d partial)\n", t.Name(), humanize.Bytes(uint64(t.BytesCompleted())), @@ -54,6 +55,10 @@ func torrentBar(t *torrent.Torrent, pieceStates bool) { t.NumPieces(), partialPieces, ) + if line != lastLine { + lastLine = line + os.Stdout.WriteString(line) + } if pieceStates { fmt.Println(psrs) } -- 2.48.1