From 9110ae474a8ac9fd70b6e15aa3cfda368c5d1cb4 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 19 May 2018 12:25:39 -0400 Subject: statusline fanciness --- go/src/cow-dedupe/dedupe.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'go/src/cow-dedupe/dedupe.go') diff --git a/go/src/cow-dedupe/dedupe.go b/go/src/cow-dedupe/dedupe.go index ea60604..a47e31f 100644 --- a/go/src/cow-dedupe/dedupe.go +++ b/go/src/cow-dedupe/dedupe.go @@ -26,6 +26,10 @@ func errhandle(err error) { } } +func myStatusLine() statusline.StatusLine { + return statusline.StopWatch(statusline.RateLimit(statusline.New(os.Stderr), time.Second/2), time.Second) +} + func getFiemaps(paths []string) map[string][]string { var err error for i := range paths { @@ -35,7 +39,7 @@ func getFiemaps(paths []string) map[string][]string { ret := map[string][]string{} - sl := statusline.NewAsyncStatusLine(os.Stderr, time.Second/2) + sl := myStatusLine() cnt := 0 sl.Put("Mapping extents...") @@ -71,15 +75,15 @@ func getFiemaps(paths []string) map[string][]string { } errhandle(cmd.Wait()) - sl.End() - fmt.Fprintf(os.Stderr, "Mapping extents... done; mapped %d files\n", cnt) + sl.Put(fmt.Sprintf("Mapping extents... done; mapped %d files", cnt)) + sl.End(true) return ret } func getChecksums(paths []string) map[string][]string { ret := map[string][]string{} - sl := statusline.NewAsyncStatusLine(os.Stderr, time.Second/2) + sl := myStatusLine() cnt := 0 sl.Put(fmt.Sprintf("Generating checksums for files... %d/%d", cnt, len(paths))) @@ -121,8 +125,8 @@ func getChecksums(paths []string) map[string][]string { errhandle(cmd.Wait()) } - sl.End() - fmt.Fprintf(os.Stderr, "Generating checksums for files... done; summed %d files\n", cnt) + sl.Put(fmt.Sprintf("Generating checksums for files... done; summed %d files", cnt)) + sl.End(true) return ret } @@ -133,7 +137,8 @@ func main() { fiemap2filenames := getFiemaps(os.Args[1:]) - fmt.Fprintf(os.Stderr, "Building list of spanning files...") + sl := statusline.StopWatch(statusline.New(os.Stderr), time.Second) + sl.Put( "Building list of spanning files...") filename2fiemap := map[string]string{} for fiemap, filenames := range fiemap2filenames { @@ -152,7 +157,8 @@ func main() { i++ } - fmt.Fprintf(os.Stderr, " done (%d files)\n", len(spanningFiles)) + sl.Put(fmt.Sprintf("Building list of spanning files... done; %d files", len(spanningFiles))) + sl.End(true) checksum2filenames := getChecksums(spanningFiles) @@ -168,7 +174,7 @@ func main() { } } - sl := statusline.NewAsyncStatusLine(os.Stderr, time.Second/2) + sl = myStatusLine() cnt := 0 sl.Put(fmt.Sprintf("Deduplicating sets of files... %d/%d", cnt, len(checksum2fiemaps))) for checksum, fiemaps := range checksum2fiemaps { @@ -211,6 +217,6 @@ func main() { cnt++ sl.Put(fmt.Sprintf("Deduplicating sets of files... %d/%d", cnt, len(checksum2fiemaps))) } - sl.End() - fmt.Fprintf(os.Stderr, "Deduplicating sets of files... done; deduplicated %d sets", cnt) + sl.Put(fmt.Sprintf("Deduplicating sets of files... done; deduplicated %d sets", cnt)) + sl.End(true) } -- cgit v1.2.3