]> Sergey Matveev's repositories - btrtrc.git/commitdiff
cmd/torrent: Only output progress lines when they change
authorMatt Joiner <anacrolix@gmail.com>
Sun, 3 May 2020 08:41:33 +0000 (18:41 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 3 May 2020 08:41:33 +0000 (18:41 +1000)
This stops spamming output when seeding.

cmd/torrent/main.go

index a346cdfbc8ffe91bdaa8580a0e1f7bba0e248479..02e5899725c7615f5a1fdcdb9c55642f958fabdf 100644 (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)
                        }