summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@beefcake.parabola.nu>2018-05-19 10:56:50 -0400
committerLuke Shumaker <lukeshu@beefcake.parabola.nu>2018-05-19 10:56:50 -0400
commit9899b4cad260e5574b1df611777dbf11aa26d902 (patch)
tree0c7150dd7c7305a99a29bbd5076e4c5ee5426d40
parent8c249c0243f660bf5c5c6fb9d403c008534d2bf3 (diff)
cow-dedupe: fixup statusline
-rw-r--r--go/src/cow-dedupe/dedupe.go10
-rw-r--r--go/src/lib/statusline/async.go26
2 files changed, 23 insertions, 13 deletions
diff --git a/go/src/cow-dedupe/dedupe.go b/go/src/cow-dedupe/dedupe.go
index ba7701c..b67d677 100644
--- a/go/src/cow-dedupe/dedupe.go
+++ b/go/src/cow-dedupe/dedupe.go
@@ -71,9 +71,8 @@ func getFiemaps(paths []string) map[string][]string {
}
errhandle(cmd.Wait())
- sl.Put(fmt.Sprintf("Mapping extents... done; mapped %d files", cnt))
sl.End()
- io.WriteString(os.Stderr, "\n")
+ fmt.Fprintf(os.Stderr, "Mapping extents... done; mapped %d files\n", cnt)
return ret
}
@@ -82,7 +81,7 @@ func getChecksums(paths []string) map[string][]string {
sl := statusline.NewAsyncStatusLine(os.Stderr, time.Second/2)
cnt := 0
- sl.Put(fmt.Sprintf("Generating checksums for files... %d/%d\n", cnt, len(paths)))
+ sl.Put(fmt.Sprintf("Generating checksums for files... %d/%d", cnt, len(paths)))
for len(paths) > 0 {
_paths := paths
@@ -117,14 +116,13 @@ func getChecksums(paths []string) map[string][]string {
ret[checksum] = append(ret[checksum], filename)
cnt++
- sl.Put(fmt.Sprintf("Generating checksums for files... %d/%d\n", cnt, len(paths)))
+ sl.Put(fmt.Sprintf("Generating checksums for files... %d/%d", cnt, len(paths)))
}
errhandle(cmd.Wait())
}
- sl.Put(fmt.Sprintf("Generating checksums for files... done; summed %d files\n", cnt))
sl.End()
- io.WriteString(os.Stderr, "\n")
+ fmt.Fprintf(os.Stderr, "Generating checksums for files... done; summed %d files\n", cnt)
return ret
}
diff --git a/go/src/lib/statusline/async.go b/go/src/lib/statusline/async.go
index 32c9a2b..5b509ac 100644
--- a/go/src/lib/statusline/async.go
+++ b/go/src/lib/statusline/async.go
@@ -7,27 +7,38 @@ import (
type AsyncStatusLine struct {
lines chan string
- end chan struct{}
+ end1 chan struct{}
+ end2 chan struct{}
}
func NewAsyncStatusLine(out io.Writer, d time.Duration) *AsyncStatusLine {
ret := &AsyncStatusLine{
lines: make(chan string),
- end: make(chan struct{}),
+ end1: make(chan struct{}),
+ end2: make(chan struct{}),
}
go func() {
sl := NewStatusLine(out)
ticker := time.NewTicker(d)
- var line string
+ var oldLine string
+ var newLine string
+ dirty := false
for {
select {
case <-ticker.C:
- sl.Put(line)
+ if dirty && newLine != oldLine {
+ sl.Put(newLine)
+ dirty = false
+ }
case l := <-ret.lines:
- line = l
- case <-ret.end:
+ newLine = l
+ dirty = true
+ case <-ret.end1:
sl.End()
ticker.Stop()
+ end2 <- struct{}{}
+ close(end2)
+ return
}
}
}()
@@ -39,7 +50,8 @@ func (sl *AsyncStatusLine) Put(line string) {
}
func (sl *AsyncStatusLine) End() {
- sl.end <- struct{}{}
+ sl.end1 <- struct{}{}
close(sl.lines)
close(sl.end)
+ <-sl.end2
}