File: display_windows.go

package info (click to toggle)
golang-github-k0kubun-go-ansi 0.0~git20180517.3bf9e29-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 100 kB
  • sloc: makefile: 2
file content (28 lines) | stat: -rw-r--r-- 564 bytes parent folder | download
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
package ansi

import (
	"os"
	"syscall"
	"unsafe"
)

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)))
}