Codebase list golang-github-vbauerster-mpb / fa18081
separate Writer struct Vladimir Bauer 3 years ago
3 changed file(s) with 30 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
1515
1616 // ErrNotTTY not a TeleTYpewriter error.
1717 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 }
3118
3219 // New returns a new Writer with defaults.
3320 func New(out io.Writer) *Writer {
22 package cwriter
33
44 import (
5 "bytes"
6 "io"
7
58 "golang.org/x/sys/unix"
69 )
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 }
722
823 // Flush flushes the underlying buffer.
924 // It's caller's responsibility to pass correct number of lines.
22 package cwriter
33
44 import (
5 "bytes"
6 "io"
57 "unsafe"
68
79 "golang.org/x/sys/windows"
1315 procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition")
1416 procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW")
1517 )
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 }
1631
1732 // Flush flushes the underlying buffer.
1833 // It's caller's responsibility to pass correct number of lines.