GetWidth godoc
Vladimir Bauer
7 years ago
| 21 | 21 | clearCursorAndLine = cursorUp + clearLine |
| 22 | 22 | ) |
| 23 | 23 | |
| 24 | // Writer is a buffered the writer that updates the terminal. | |
| 25 | // The contents of writer will be flushed when Flush is called. | |
| 24 | // Writer is a buffered the writer that updates the terminal. The | |
| 25 | // contents of writer will be flushed when Flush is called. | |
| 26 | 26 | type Writer struct { |
| 27 | 27 | out io.Writer |
| 28 | 28 | buf bytes.Buffer |
| 63 | 63 | return w.buf.WriteString(s) |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | // ReadFrom reads from the provided io.Reader and writes to the underlying buffer. | |
| 66 | // ReadFrom reads from the provided io.Reader and writes to the | |
| 67 | // underlying buffer. | |
| 67 | 68 | func (w *Writer) ReadFrom(r io.Reader) (n int64, err error) { |
| 68 | 69 | return w.buf.ReadFrom(r) |
| 69 | 70 | } |
| 70 | 71 | |
| 72 | // GetWidth returns width of underlying terminal. | |
| 71 | 73 | func (w *Writer) GetWidth() (int, error) { |
| 72 | 74 | if w.isTerminal { |
| 73 | 75 | tw, _, err := terminal.GetSize(w.fd) |