Watch 6 Star 6 Fork 2

ShirDon-廖显东 / uiprogressGoMIT

Join us
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
uiprogress是用于实时更新终端输出的go库 spread retract

https://gitee.com/shirdonl/uiprogress.git

Clone or download
writer_windows.go 1.67 KB
Copy Edit Web IDE Raw Blame History
ShirDon-廖显东 authored 2019-12-01 20:40 . git commit
// +build windows
package uiprogress
import (
"fmt"
"gitee.com/shirdonl/goTerminal"
"strings"
"syscall"
"unsafe"
)
var kernel32 = syscall.NewLazyDLL("kernel32.dll")
var (
procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo")
procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition")
procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW")
)
// clear the line and move the cursor up
var clear = fmt.Sprintf("%c[%dA%c[2K\r", ESC, 0, ESC)
type short int16
type dword uint32
type word uint16
type coord struct {
x short
y short
}
type smallRect struct {
left short
top short
right short
bottom short
}
type consoleScreenBufferInfo struct {
size coord
cursorPosition coord
attributes word
window smallRect
maximumWindowSize coord
}
func (w *Writer) clearLines() {
f, ok := w.Out.(FdWriter)
if ok && !isatty.IsTerminal(f.Fd()) {
ok = false
}
if !ok {
_, _ = fmt.Fprint(w.Out, strings.Repeat(clear, w.lineCount))
return
}
fd := f.Fd()
var csbi consoleScreenBufferInfo
_, _, _ = procGetConsoleScreenBufferInfo.Call(fd, uintptr(unsafe.Pointer(&csbi)))
for i := 0; i < w.lineCount; i++ {
// move the cursor up
csbi.cursorPosition.y--
_, _, _ = procSetConsoleCursorPosition.Call(fd, uintptr(*(*int32)(unsafe.Pointer(&csbi.cursorPosition))))
// clear the line
cursor := coord{
x: csbi.window.left,
y: csbi.window.top + csbi.cursorPosition.y,
}
var count, w dword
count = dword(csbi.size.x)
_, _, _ = procFillConsoleOutputCharacter.Call(fd, uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&w)))
}
}
Go
1
https://gitee.com/shirdonl/uiprogress.git
git@gitee.com:shirdonl/uiprogress.git
shirdonl
uiprogress
uiprogress
master

Help Search