printProgress prints the progress with an optional log
(logMessage string)
| 77 | |
| 78 | // printProgress prints the progress with an optional log |
| 79 | func printProgress(logMessage string) { |
| 80 | operations.StdoutMutex.Lock() |
| 81 | defer operations.StdoutMutex.Unlock() |
| 82 | |
| 83 | var buf bytes.Buffer |
| 84 | w, _ := terminal.GetSize() |
| 85 | stats := strings.TrimSpace(accounting.GlobalStats().String()) |
| 86 | logMessage = strings.TrimSpace(logMessage) |
| 87 | |
| 88 | out := func(s string) { |
| 89 | buf.WriteString(s) |
| 90 | } |
| 91 | |
| 92 | if logMessage != "" { |
| 93 | out("\n") |
| 94 | out(terminal.MoveUp) |
| 95 | } |
| 96 | // Move to the start of the block we wrote erasing all the previous lines |
| 97 | for range nlines - 1 { |
| 98 | out(terminal.EraseLine) |
| 99 | out(terminal.MoveUp) |
| 100 | } |
| 101 | out(terminal.EraseLine) |
| 102 | out(terminal.MoveToStartOfLine) |
| 103 | if logMessage != "" { |
| 104 | out(terminal.EraseLine) |
| 105 | out(logMessage + "\n") |
| 106 | } |
| 107 | fixedLines := strings.Split(stats, "\n") |
| 108 | nlines = len(fixedLines) |
| 109 | for i, line := range fixedLines { |
| 110 | if len(line) > w { |
| 111 | line = line[:w] |
| 112 | } |
| 113 | out(line) |
| 114 | if i != nlines-1 { |
| 115 | out("\n") |
| 116 | } |
| 117 | } |
| 118 | terminal.Write(buf.Bytes()) |
| 119 | } |
no test coverage detected
searching dependent graphs…