Skip to content

Commit cae5b2b

Browse files
committed
Fix #37
uilive does not account for long lines breaking resulting in unwanted scrolling when printing long lines.
1 parent 4204e2f commit cae5b2b

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

cmd/internal/runtest.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -200,29 +200,29 @@ func (f *Formatter) Flush(limit bool) error {
200200
if len(f.buf.Bytes()) == 0 {
201201
return nil
202202
}
203+
defer f.buf.Reset()
203204

204-
out := string(f.buf.Bytes())
205+
termStartOfRow(f.w)
205206
if limit {
207+
out := string(f.buf.Bytes())
206208
width := 0
207209
lines := 0
208-
for i, r := range out {
209-
if r == '\n' {
210-
width = 0
211-
lines++
212-
} else if width++; width > cols {
210+
for _, r := range out {
211+
width++
212+
if r == '\n' || width > cols {
213213
width = 0
214214
lines++
215-
}
216-
if lines == rows {
217-
out = out[0:i]
218-
break
215+
if lines == rows {
216+
break
217+
}
218+
if _, err := f.w.Write([]byte("\n")); err != nil {
219+
return err
220+
}
221+
} else if _, err := f.w.Write([]byte(string(r))); err != nil {
222+
return err
219223
}
220224
}
221-
}
222-
termStartOfRow(f.w)
223-
_, err := f.w.Write([]byte(out))
224-
f.buf.Reset()
225-
if err != nil {
225+
} else if _, err := f.w.Write(f.buf.Bytes()); err != nil {
226226
return err
227227
}
228228
return f.w.Flush()

0 commit comments

Comments
 (0)