cmd/torrent: Only output progress lines when they change

This stops spamming output when seeding.
This commit is contained in:
Matt Joiner 2020-05-03 18:41:33 +10:00
parent 9edd98ad78
commit 11a373200f
1 changed files with 6 additions and 1 deletions

View File

@ -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)
}