Codebase list golang-github-vbauerster-mpb / 41495fc
better windows clearLines Vladimir Bauer 7 years ago
1 changed file(s) with 19 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
1616 procFillConsoleOutputAttribute = kernel32.NewProc("FillConsoleOutputAttribute")
1717 )
1818
19 type short int16
20 type dword uint32
21 type word uint16
22
2319 type coord struct {
24 x short
25 y short
20 x int16
21 y int16
2622 }
2723
2824 type smallRect struct {
29 left short
30 top short
31 right short
32 bottom short
25 left int16
26 top int16
27 right int16
28 bottom int16
3329 }
3430
3531 type consoleScreenBufferInfo struct {
3632 size coord
3733 cursorPosition coord
38 attributes word
34 attributes uint16
3935 window smallRect
4036 maximumWindowSize coord
4137 }
4743 var info consoleScreenBufferInfo
4844 procGetConsoleScreenBufferInfo.Call(w.fd, uintptr(unsafe.Pointer(&info)))
4945
50 for i := 0; i < w.lineCount; i++ {
51 // move the cursor up
52 info.cursorPosition.y--
53 procSetConsoleCursorPosition.Call(w.fd, uintptr(*(*int32)(unsafe.Pointer(&info.cursorPosition))))
54 // clear the line
55 cursor := coord{
56 x: info.window.left,
57 y: info.window.top + info.cursorPosition.y,
58 }
59 var count, dw dword
60 count = dword(info.size.x)
61 procFillConsoleOutputCharacter.Call(w.fd, uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&dw)))
46 info.cursorPosition.y -= int16(w.lineCount)
47 if info.cursorPosition.y < 0 {
48 info.cursorPosition.y = 0
6249 }
50 procSetConsoleCursorPosition.Call(w.fd, uintptr(uint32(uint16(info.cursorPosition.y))<<16|uint32(uint16(info.cursorPosition.x))))
51
52 // clear the lines
53 cursor := coord{
54 x: info.window.left,
55 y: info.cursorPosition.y,
56 }
57 count := uint32(info.size.x) * uint32(w.lineCount)
58 procFillConsoleOutputCharacter.Call(w.fd, uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(new(uint32))))
6359 }