Codebase list golang-github-vbauerster-mpb / f6adf1e
tests don't depend on cwriter Vladimir Bauer 7 years ago
2 changed file(s) with 3 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
8181
8282 got := string(getLastLine(buf.Bytes()))
8383
84 if got != wantBar {
84 if !strings.Contains(got, wantBar) {
8585 t.Errorf("Want bar: %q, got bar: %q\n", wantBar, got)
8686 }
8787 }
108108 )
109109 got := string(getLastLine(buf.Bytes()))
110110
111 if got != wantBar {
111 if !strings.Contains(got, wantBar) {
112112 t.Errorf("Want bar: %q:%d, got bar: %q:%d\n", wantBar, utf8.RuneCountInString(wantBar), got, utf8.RuneCountInString(got))
113113 }
114114 }
22 import (
33 "bytes"
44 "context"
5 "fmt"
65 "io/ioutil"
76 "math/rand"
87 "sync"
109 "time"
1110
1211 "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
2012 )
2113
2214 func init() {
117109
118110 func getLastLine(bb []byte) []byte {
119111 split := bytes.Split(bb, []byte("\n"))
120 lastLine := split[len(split)-2]
121 return lastLine[len(clearCursorAndLine):]
112 return split[len(split)-2]
122113 }
123114
124115 func randomDuration(max time.Duration) time.Duration {