Files
bl/common/serialize/log/term/sizes_windows.go
昔念 ffc39f5462 refactor(common): 重构 bitset 和 log 包
- 移除了 github.com/scylladb/termtables 依赖
- 修改了 bitset 包,移除了未使用的代码和测试
- 修改了 log 包,移除了未使用的代码和测试
- 更新了 go.work 文件,添加了 bitset 和 log 包
2025-07-02 22:31:54 +08:00

58 lines
1.2 KiB
Go

// Copyright 2013 Apcera Inc. All rights reserved.
// +build windows
package term
// Used when we have no other source for getting platform-specific information
// about the terminal sizes available.
import (
"os"
"syscall"
"unsafe"
)
// Based on source from from golang.org/x/crypto/ssh/terminal/util_windows.go
var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo")
)
type (
short int16
word uint16
coord struct {
x short
y short
}
smallRect struct {
left short
top short
right short
bottom short
}
consoleScreenBufferInfo struct {
size coord
cursorPosition coord
attributes word
window smallRect
maximumWindowSize coord
}
)
// GetTerminalWindowSize returns the width and height of a terminal in Windows.
func GetTerminalWindowSize(file *os.File) (*Size, error) {
var info consoleScreenBufferInfo
_, _, e := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, file.Fd(), uintptr(unsafe.Pointer(&info)), 0)
if e != 0 {
return nil, error(e)
}
return &Size{
Lines: int(info.size.y),
Columns: int(info.size.x),
}, nil
}