Codebase list golang-github-vbauerster-mpb / 4751910
windows support Vladimir Bauer 9 years ago
1 changed file(s) with 20 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
33
44 import (
55 "fmt"
6 "io"
67 "syscall"
78 "unsafe"
89
4243 maximumWindowSize coord
4344 }
4445
46 // FdWriter is a writer with a file descriptor.
47 type FdWriter interface {
48 io.Writer
49 Fd() uintptr
50 }
51
4552 func (w *Writer) clearLines() {
46 f, ok := w.Out.(FdWriter)
53 f, ok := w.out.(FdWriter)
4754 if ok && !isatty.IsTerminal(f.Fd()) {
4855 ok = false
4956 }
5057 if !ok {
5158 for i := 0; i < w.lineCount; i++ {
52 fmt.Fprintf(w.Out, "%c[%dA", ESC, 0) // move the cursor up
53 fmt.Fprintf(w.Out, "%c[2K\r", ESC) // clear the line
59 fmt.Fprintf(w.out, "%c[%dA", ESC, 0) // move the cursor up
60 fmt.Fprintf(w.out, "%c[2K\r", ESC) // clear the line
5461 }
5562 return
5663 }
7279 procFillConsoleOutputCharacter.Call(fd, uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&w)))
7380 }
7481 }
82
83 // TerminalWidth returns width of the terminal.
84 func TerminalWidth() (int, error) {
85 var info consoleScreenBufferInfo
86 _, _, errno := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(syscall.Stdout), uintptr(unsafe.Pointer(&info)), 0)
87 if errno != 0 {
88 return 0, errno
89 }
90 return int(info.size.x) - 1, nil
91 }