separate Writer struct
Vladimir Bauer
3 years ago
| 15 | 15 |
|
| 16 | 16 |
// ErrNotTTY not a TeleTYpewriter error.
|
| 17 | 17 |
var ErrNotTTY = errors.New("not a terminal")
|
| 18 | |
|
| 19 | |
// Writer is a buffered terminal writer, which moves cursor N lines up
|
| 20 | |
// on each flush except the first one, where N is a number of lines of
|
| 21 | |
// a previous flush.
|
| 22 | |
type Writer struct {
|
| 23 | |
*bytes.Buffer
|
| 24 | |
out io.Writer
|
| 25 | |
ew escWriter
|
| 26 | |
lines int //nolint:unused
|
| 27 | |
fd int
|
| 28 | |
terminal bool
|
| 29 | |
termSize func(int) (int, int, error)
|
| 30 | |
}
|
| 31 | 18 |
|
| 32 | 19 |
// New returns a new Writer with defaults.
|
| 33 | 20 |
func New(out io.Writer) *Writer {
|
| 2 | 2 |
package cwriter
|
| 3 | 3 |
|
| 4 | 4 |
import (
|
|
5 |
"bytes"
|
|
6 |
"io"
|
|
7 |
|
| 5 | 8 |
"golang.org/x/sys/unix"
|
| 6 | 9 |
)
|
|
10 |
|
|
11 |
// Writer is a buffered terminal writer, which moves cursor N lines up
|
|
12 |
// on each flush except the first one, where N is a number of lines of
|
|
13 |
// a previous flush.
|
|
14 |
type Writer struct {
|
|
15 |
*bytes.Buffer
|
|
16 |
out io.Writer
|
|
17 |
ew escWriter
|
|
18 |
fd int
|
|
19 |
terminal bool
|
|
20 |
termSize func(int) (int, int, error)
|
|
21 |
}
|
| 7 | 22 |
|
| 8 | 23 |
// Flush flushes the underlying buffer.
|
| 9 | 24 |
// It's caller's responsibility to pass correct number of lines.
|
| 2 | 2 |
package cwriter
|
| 3 | 3 |
|
| 4 | 4 |
import (
|
|
5 |
"bytes"
|
|
6 |
"io"
|
| 5 | 7 |
"unsafe"
|
| 6 | 8 |
|
| 7 | 9 |
"golang.org/x/sys/windows"
|
|
| 13 | 15 |
procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition")
|
| 14 | 16 |
procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW")
|
| 15 | 17 |
)
|
|
18 |
|
|
19 |
// Writer is a buffered terminal writer, which moves cursor N lines up
|
|
20 |
// on each flush except the first one, where N is a number of lines of
|
|
21 |
// a previous flush.
|
|
22 |
type Writer struct {
|
|
23 |
*bytes.Buffer
|
|
24 |
out io.Writer
|
|
25 |
ew escWriter
|
|
26 |
lines int
|
|
27 |
fd int
|
|
28 |
terminal bool
|
|
29 |
termSize func(int) (int, int, error)
|
|
30 |
}
|
| 16 | 31 |
|
| 17 | 32 |
// Flush flushes the underlying buffer.
|
| 18 | 33 |
// It's caller's responsibility to pass correct number of lines.
|