diff --git a/cwriter/writer.go b/cwriter/writer.go index 4a7a34a..63cffdf 100644 --- a/cwriter/writer.go +++ b/cwriter/writer.go @@ -21,8 +21,8 @@ // contents of writer will be flushed when Flush is called. type Writer struct { *bytes.Buffer + out io.Writer ew escWriter - out io.Writer lines int // used by writer_windows only fd int terminal bool @@ -33,7 +33,6 @@ func New(out io.Writer) *Writer { w := &Writer{ Buffer: new(bytes.Buffer), - ew: escWriter(make([]byte, 8, 16)), out: out, termSize: func(_ int) (int, int, error) { return -1, -1, ErrNotTTY @@ -48,6 +47,8 @@ } } } + bb := make([]byte, 8, 16) + w.ew = escWriter(bb[:copy(bb, []byte(escOpen))]) return w } @@ -59,7 +60,7 @@ type escWriter []byte func (b escWriter) ansiCuuAndEd(out io.Writer, n int) error { - b = strconv.AppendInt(b[:copy(b, escOpen)], int64(n), 10) + b = strconv.AppendInt(b, int64(n), 10) _, err := out.Write(append(b, cuuAndEd...)) return err }