forked from k0kubun/go-ansi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay_windows.go
54 lines (44 loc) · 1.12 KB
/
display_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//go:build windows
package ansi
import (
"golang.org/x/term"
"os"
"syscall"
"unsafe"
)
func GetTerminalSize() (int, int) {
width, height, _ := term.GetSize(int(os.Stdout.Fd()))
return width, height
}
func GetScreenSize() (int, int) {
screen := getScreen()
return int(screen.size.x), int(screen.size.y)
}
func getScreen() consoleScreenBufferInfo {
handle := syscall.Handle(os.Stdout.Fd())
var csbi consoleScreenBufferInfo
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
return csbi
}
func EraseInLine(mode int) {
handle := syscall.Handle(os.Stdout.Fd())
var csbi consoleScreenBufferInfo
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
var w uint32
var x Short
cursor := csbi.cursorPosition
switch mode {
case 1:
x = csbi.size.x
case 2:
x = 0
case 3:
cursor.x = 0
x = csbi.size.x
}
procFillConsoleOutputCharacter.Call(uintptr(handle), uintptr(' '), uintptr(x), uintptr(*(*int32)(unsafe.Pointer(&cursor))), uintptr(unsafe.Pointer(&w)))
}
func GetBottomScrollIndex() int {
screen := getScreen()
return int(screen.window.bottom)
}