cwriter change: GetTermSize to TermSize
Vladimir Bauer
8 years ago
| 1 | 1 |
|
| 2 | 2 |
import (
|
| 3 | 3 |
"bytes"
|
|
4 |
"fmt"
|
| 4 | 5 |
"io"
|
| 5 | |
"fmt"
|
| 6 | 6 |
)
|
| 7 | 7 |
|
| 8 | 8 |
// ESC is the ASCII code for escape character
|
|
| 47 | 47 |
func (w *Writer) Write(b []byte) (n int, err error) {
|
| 48 | 48 |
return w.buf.Write(b)
|
| 49 | 49 |
}
|
|
50 |
|
|
51 |
func (w *Writer) WriteString(s string) (n int, err error) {
|
|
52 |
return w.buf.WriteString(s)
|
|
53 |
}
|
| 3 | 3 |
|
| 4 | 4 |
import (
|
| 5 | 5 |
"fmt"
|
|
6 |
"strings"
|
| 6 | 7 |
"syscall"
|
| 7 | 8 |
"unsafe"
|
| 8 | |
"strings"
|
| 9 | 9 |
)
|
| 10 | 10 |
|
| 11 | 11 |
func (w *Writer) clearLines() {
|
| 12 | 12 |
fmt.Fprint(w.out, strings.Repeat(clearCursorAndLine, w.lineCount))
|
| 13 | 13 |
}
|
| 14 | 14 |
|
| 15 | |
// GetTermSize returns the dimensions of the given terminal.
|
|
15 |
// TermSize returns the dimensions of the given terminal.
|
| 16 | 16 |
// the code is stolen from "golang.org/x/crypto/ssh/terminal"
|
| 17 | |
func GetTermSize() (width, height int, err error) {
|
|
17 |
func TermSize() (width, height int, err error) {
|
| 18 | 18 |
var dimensions [4]uint16
|
| 19 | 19 |
|
| 20 | 20 |
if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(syscall.Stdout), uintptr(syscall.TIOCGWINSZ), uintptr(unsafe.Pointer(&dimensions)), 0, 0, 0); err != 0 {
|