Simplify ui.StdioWrapper.Write

Instead of looping to find line breaks, make it look for the last one.
This commit is contained in:
greatroar
2020-10-17 20:23:36 +02:00
parent 863a590a81
commit 35419de232
2 changed files with 18 additions and 39 deletions

View File

@@ -55,22 +55,12 @@ func (w *lineWriter) Write(data []byte) (n int, err error) {
// look for line breaks
buf := w.buf.Bytes()
skip := 0
for i := 0; i < len(buf); {
if buf[i] == '\n' {
// found line
w.print(string(buf[:i+1]))
buf = buf[i+1:]
skip += i + 1
i = 0
continue
}
i++
i := bytes.LastIndexByte(buf, '\n')
if i != -1 {
w.print(string(buf[:i+1]))
w.buf.Next(i + 1)
}
_ = w.buf.Next(skip)
return n, err
}