forked from Angey40/BaiduPCS-Go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,56 @@ | ||
package pcsliner | ||
|
||
import ( | ||
"github.com/peterh/liner" | ||
_ "unsafe" // for go:linkname | ||
"syscall" | ||
"unsafe" | ||
) | ||
|
||
//go:linkname eraseScreen github.com/iikira/BaiduPCS-Go/vendor/github.com/peterh/liner.(*State).eraseScreen | ||
func eraseScreen(s *liner.State) | ||
const ( | ||
std_output_handle = uint32(-11 & 0xFFFFFFFF) | ||
) | ||
|
||
var ( | ||
kernel32 = syscall.NewLazyDLL("kernel32.dll") | ||
|
||
procGetStdHandle = kernel32.NewProc("GetStdHandle") | ||
procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition") | ||
procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo") | ||
procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW") | ||
) | ||
|
||
type ( | ||
coord struct { | ||
x, y int16 | ||
} | ||
smallRect struct { | ||
left, top, right, bottom int16 | ||
} | ||
consoleScreenBufferInfo struct { | ||
dwSize coord | ||
dwCursorPosition coord | ||
wAttributes int16 | ||
srWindow smallRect | ||
dwMaximumWindowSize coord | ||
} | ||
) | ||
|
||
// ClearScreen 清空屏幕 | ||
func (pl *PCSLiner) ClearScreen() { | ||
eraseScreen(pl.State) | ||
ClearScreen() | ||
} | ||
|
||
// ClearScreen 清空屏幕 | ||
func ClearScreen() { | ||
liner := NewLiner() | ||
liner.ClearScreen() | ||
liner.Close() | ||
out, _, _ := procGetStdHandle.Call(uintptr(std_output_handle)) | ||
hOut := syscall.Handle(out) | ||
|
||
var sbi consoleScreenBufferInfo | ||
procGetConsoleScreenBufferInfo.Call(uintptr(hOut), uintptr(unsafe.Pointer(&sbi))) | ||
|
||
var numWritten uint32 | ||
procFillConsoleOutputCharacter.Call(uintptr(hOut), uintptr(' '), | ||
uintptr(sbi.dwSize.x)*uintptr(sbi.dwSize.y), | ||
0, | ||
uintptr(unsafe.Pointer(&numWritten))) | ||
procSetConsoleCursorPosition.Call(uintptr(hOut), 0) | ||
} |