tests don't depend on cwriter
Vladimir Bauer
7 years ago
| 81 | 81 |
|
| 82 | 82 |
got := string(getLastLine(buf.Bytes()))
|
| 83 | 83 |
|
| 84 | |
if got != wantBar {
|
|
84 |
if !strings.Contains(got, wantBar) {
|
| 85 | 85 |
t.Errorf("Want bar: %q, got bar: %q\n", wantBar, got)
|
| 86 | 86 |
}
|
| 87 | 87 |
}
|
|
| 108 | 108 |
)
|
| 109 | 109 |
got := string(getLastLine(buf.Bytes()))
|
| 110 | 110 |
|
| 111 | |
if got != wantBar {
|
|
111 |
if !strings.Contains(got, wantBar) {
|
| 112 | 112 |
t.Errorf("Want bar: %q:%d, got bar: %q:%d\n", wantBar, utf8.RuneCountInString(wantBar), got, utf8.RuneCountInString(got))
|
| 113 | 113 |
}
|
| 114 | 114 |
}
|
| 2 | 2 |
import (
|
| 3 | 3 |
"bytes"
|
| 4 | 4 |
"context"
|
| 5 | |
"fmt"
|
| 6 | 5 |
"io/ioutil"
|
| 7 | 6 |
"math/rand"
|
| 8 | 7 |
"sync"
|
|
| 10 | 9 |
"time"
|
| 11 | 10 |
|
| 12 | 11 |
"github.com/vbauerster/mpb/v4"
|
| 13 | |
"github.com/vbauerster/mpb/v4/cwriter"
|
| 14 | |
)
|
| 15 | |
|
| 16 | |
var (
|
| 17 | |
cursorUp = fmt.Sprintf("%c[%dA", cwriter.ESC, 1)
|
| 18 | |
clearLine = fmt.Sprintf("%c[2K\r", cwriter.ESC)
|
| 19 | |
clearCursorAndLine = cursorUp + clearLine
|
| 20 | 12 |
)
|
| 21 | 13 |
|
| 22 | 14 |
func init() {
|
|
| 117 | 109 |
|
| 118 | 110 |
func getLastLine(bb []byte) []byte {
|
| 119 | 111 |
split := bytes.Split(bb, []byte("\n"))
|
| 120 | |
lastLine := split[len(split)-2]
|
| 121 | |
return lastLine[len(clearCursorAndLine):]
|
|
112 |
return split[len(split)-2]
|
| 122 | 113 |
}
|
| 123 | 114 |
|
| 124 | 115 |
func randomDuration(max time.Duration) time.Duration {
|