Codebase list golang-github-vbauerster-mpb / 48e4b0a
allocless ansiCuuAndEd func Vladimir Bauer 3 years ago
1 changed file(s) with 9 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
77 "strconv"
88 )
99
10 // ErrNotTTY not a TeleTYpewriter error.
11 var ErrNotTTY = errors.New("not a terminal")
12
1310 // https://github.com/dylanaraps/pure-sh-bible#cursor-movement
1411 const (
1512 escOpen = "\x1b["
1613 cuuAndEd = "A\x1b[J"
1714 )
15
16 // used by ansiCuuAndEd func
17 var escBuf = make([]byte, 8)
18
19 // ErrNotTTY not a TeleTYpewriter error.
20 var ErrNotTTY = errors.New("not a terminal")
1821
1922 // Writer is a buffered the writer that updates the terminal. The
2023 // contents of writer will be flushed when Flush is called.
5255 return w.termSize(w.fd)
5356 }
5457
58 // if n > 99 it will allocate because of len(escBuf) = 8
5559 func ansiCuuAndEd(out io.Writer, n int) error {
56 buf := make([]byte, 8)
57 buf = strconv.AppendInt(buf[:copy(buf, escOpen)], int64(n), 10)
58 _, err := out.Write(append(buf, cuuAndEd...))
60 escBuf = strconv.AppendInt(escBuf[:copy(escBuf, escOpen)], int64(n), 10)
61 _, err := out.Write(append(escBuf, cuuAndEd...))
5962 return err
6063 }