Codebase list golang-github-vbauerster-mpb / b769685
copy escOpen once Vladimir Bauer 3 years ago
1 changed file(s) with 4 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
2020 // contents of writer will be flushed when Flush is called.
2121 type Writer struct {
2222 *bytes.Buffer
23 out io.Writer
2324 ew escWriter
24 out io.Writer
2525 lines int // used by writer_windows only
2626 fd int
2727 terminal bool
3232 func New(out io.Writer) *Writer {
3333 w := &Writer{
3434 Buffer: new(bytes.Buffer),
35 ew: escWriter(make([]byte, 8, 16)),
3635 out: out,
3736 termSize: func(_ int) (int, int, error) {
3837 return -1, -1, ErrNotTTY
4746 }
4847 }
4948 }
49 bb := make([]byte, 8, 16)
50 w.ew = escWriter(bb[:copy(bb, []byte(escOpen))])
5051 return w
5152 }
5253
5859 type escWriter []byte
5960
6061 func (b escWriter) ansiCuuAndEd(out io.Writer, n int) error {
61 b = strconv.AppendInt(b[:copy(b, escOpen)], int64(n), 10)
62 b = strconv.AppendInt(b, int64(n), 10)
6263 _, err := out.Write(append(b, cuuAndEd...))
6364 return err
6465 }