]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/progress.go
MTH
[nncp.git] / src / progress.go
index 61ad4654649a975e0f6d21d3cd6d0479c98cf251..0c2f0ee2c99f7cd874edd56fbded6e815bbdf8d2 100644 (file)
@@ -25,7 +25,7 @@ import (
        "time"
 
        "github.com/dustin/go-humanize"
-       "go.cypherpunks.ru/nncp/v5/uilive"
+       "go.cypherpunks.ru/nncp/v7/uilive"
 )
 
 func init() {
@@ -82,7 +82,7 @@ func CopyProgressed(
        dst io.Writer,
        src io.Reader,
        prgrsPrefix string,
-       sds SDS,
+       les LEs,
        showPrgrs bool,
 ) (written int64, err error) {
        buf := make([]byte, EncBlkSize)
@@ -95,8 +95,7 @@ func CopyProgressed(
                        if nw > 0 {
                                written += int64(nw)
                                if showPrgrs {
-                                       sds["size"] = written
-                                       Progress(prgrsPrefix, sds)
+                                       Progress(prgrsPrefix, append(les, LE{"Size", written}))
                                }
                        }
                        if ew != nil {
@@ -118,13 +117,20 @@ func CopyProgressed(
        return
 }
 
-func Progress(prefix string, sds SDS) {
+func Progress(prefix string, les LEs) {
        var size int64
-       if sizeI, exists := sds["size"]; exists {
-               size = sizeI.(int64)
+       var fullsize int64
+       var pkt string
+       for _, le := range les {
+               switch le.K {
+               case "Size":
+                       size = le.V.(int64)
+               case "FullSize":
+                       fullsize = le.V.(int64)
+               case "Pkt":
+                       pkt = le.V.(string)
+               }
        }
-       fullsize := sds["fullsize"].(int64)
-       pkt := sds["pkt"].(string)
        progressBarsLock.RLock()
        pb, exists := progressBars[pkt]
        progressBarsLock.RUnlock()
@@ -135,7 +141,7 @@ func Progress(prefix string, sds SDS) {
                progressBarsLock.Unlock()
        }
        what := pkt
-       if len(what) >= 52 { // Base32 encoded
+       if len(what) >= Base32Encoded32Len { // Base32 encoded
                what = what[:16] + ".." + what[len(what)-16:]
        }
        what = prefix + " " + what
@@ -147,3 +153,13 @@ func Progress(prefix string, sds SDS) {
                progressBarsLock.Unlock()
        }
 }
+
+func ProgressKill(pkt string) {
+       progressBarsLock.Lock()
+       pb, exists := progressBars[pkt]
+       if exists {
+               pb.Kill()
+               delete(progressBars, pkt)
+       }
+       progressBarsLock.Unlock()
+}