refactoring: lineCount => lines
Vladimir Bauer
4 years ago
| 31 | 31 |
|
| 32 | 32 |
func BenchmarkWithCopy(b *testing.B) {
|
| 33 | 33 |
w := New(ioutil.Discard)
|
| 34 | |
w.lineCount = 4
|
|
34 |
w.lines = 4
|
| 35 | 35 |
for i := 0; i < b.N; i++ {
|
| 36 | 36 |
w.ansiCuuAndEd()
|
| 37 | 37 |
}
|
| 21 | 21 |
type Writer struct {
|
| 22 | 22 |
out io.Writer
|
| 23 | 23 |
buf bytes.Buffer
|
| 24 | |
lineCount int
|
|
24 |
lines int
|
| 25 | 25 |
fd int
|
| 26 | 26 |
isTerminal bool
|
| 27 | 27 |
}
|
|
| 37 | 37 |
}
|
| 38 | 38 |
|
| 39 | 39 |
// Flush flushes the underlying buffer.
|
| 40 | |
func (w *Writer) Flush(lineCount int) (err error) {
|
|
40 |
func (w *Writer) Flush(lines int) (err error) {
|
| 41 | 41 |
// some terminals interpret 'cursor up 0' as 'cursor up 1'
|
| 42 | |
if w.lineCount > 0 {
|
|
42 |
if w.lines > 0 {
|
| 43 | 43 |
err = w.clearLines()
|
| 44 | 44 |
if err != nil {
|
| 45 | 45 |
return
|
| 46 | 46 |
}
|
| 47 | 47 |
}
|
| 48 | |
w.lineCount = lineCount
|
|
48 |
w.lines = lines
|
| 49 | 49 |
_, err = w.buf.WriteTo(w.out)
|
| 50 | 50 |
return
|
| 51 | 51 |
}
|
|
| 77 | 77 |
|
| 78 | 78 |
func (w *Writer) ansiCuuAndEd() (err error) {
|
| 79 | 79 |
buf := make([]byte, 8)
|
| 80 | |
buf = strconv.AppendInt(buf[:copy(buf, escOpen)], int64(w.lineCount), 10)
|
|
80 |
buf = strconv.AppendInt(buf[:copy(buf, escOpen)], int64(w.lines), 10)
|
| 81 | 81 |
_, err = w.out.Write(append(buf, cuuAndEd...))
|
| 82 | 82 |
return
|
| 83 | 83 |
}
|