Skip to content

Commit 71c9d87

Browse files
aymanbagabasqmuntal
authored andcommitted
windows: add console ConPTY API
Add Windows ConPTY API, specifically CreatePseudoConsole, ClosePseudoConsole, and ResizePseudoConsole. See https://devblogs.microsoft.com/commandline/windows-command-line-introducing-the-windows-pseudo-console-conpty/ See https://learn.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session Updates #62708 Change-Id: I433c4d9d8716dd75fa44291ab0cf6ef3c5f6a913 GitHub-Last-Rev: 21cda7e GitHub-Pull-Request: #175 Reviewed-on: https://go-review.googlesource.com/c/sys/+/528915 Run-TryBot: Quim Muntal <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Quim Muntal <[email protected]> Reviewed-by: Than McIntosh <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent aa9470e commit 71c9d87

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

windows/syscall_windows.go

+17
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,15 @@ func NewCallbackCDecl(fn interface{}) uintptr {
297297
//sys RegNotifyChangeKeyValue(key Handle, watchSubtree bool, notifyFilter uint32, event Handle, asynchronous bool) (regerrno error) = advapi32.RegNotifyChangeKeyValue
298298
//sys GetCurrentProcessId() (pid uint32) = kernel32.GetCurrentProcessId
299299
//sys ProcessIdToSessionId(pid uint32, sessionid *uint32) (err error) = kernel32.ProcessIdToSessionId
300+
//sys ClosePseudoConsole(console Handle) = kernel32.ClosePseudoConsole
301+
//sys createPseudoConsole(size uint32, in Handle, out Handle, flags uint32, pconsole *Handle) (hr error) = kernel32.CreatePseudoConsole
300302
//sys GetConsoleMode(console Handle, mode *uint32) (err error) = kernel32.GetConsoleMode
301303
//sys SetConsoleMode(console Handle, mode uint32) (err error) = kernel32.SetConsoleMode
302304
//sys GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) (err error) = kernel32.GetConsoleScreenBufferInfo
303305
//sys setConsoleCursorPosition(console Handle, position uint32) (err error) = kernel32.SetConsoleCursorPosition
304306
//sys WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) = kernel32.WriteConsoleW
305307
//sys ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) = kernel32.ReadConsoleW
308+
//sys resizePseudoConsole(pconsole Handle, size uint32) (hr error) = kernel32.ResizePseudoConsole
306309
//sys CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) [failretval==InvalidHandle] = kernel32.CreateToolhelp32Snapshot
307310
//sys Module32First(snapshot Handle, moduleEntry *ModuleEntry32) (err error) = kernel32.Module32FirstW
308311
//sys Module32Next(snapshot Handle, moduleEntry *ModuleEntry32) (err error) = kernel32.Module32NextW
@@ -1813,3 +1816,17 @@ type PSAPI_WORKING_SET_EX_INFORMATION struct {
18131816
// A PSAPI_WORKING_SET_EX_BLOCK union that indicates the attributes of the page at VirtualAddress.
18141817
VirtualAttributes PSAPI_WORKING_SET_EX_BLOCK
18151818
}
1819+
1820+
// CreatePseudoConsole creates a windows pseudo console.
1821+
func CreatePseudoConsole(size Coord, in Handle, out Handle, flags uint32, pconsole *Handle) error {
1822+
// We need this wrapper to manually cast Coord to uint32. The autogenerated wrappers only
1823+
// accept arguments that can be casted to uintptr, and Coord can't.
1824+
return createPseudoConsole(*((*uint32)(unsafe.Pointer(&size))), in, out, flags, pconsole)
1825+
}
1826+
1827+
// ResizePseudoConsole resizes the internal buffers of the pseudo console to the width and height specified in `size`.
1828+
func ResizePseudoConsole(pconsole Handle, size Coord) error {
1829+
// We need this wrapper to manually cast Coord to uint32. The autogenerated wrappers only
1830+
// accept arguments that can be casted to uintptr, and Coord can't.
1831+
return resizePseudoConsole(pconsole, *((*uint32)(unsafe.Pointer(&size))))
1832+
}

windows/types_windows.go

+7
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ const (
247247
PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY = 0x00020007
248248
PROC_THREAD_ATTRIBUTE_UMS_THREAD = 0x00030006
249249
PROC_THREAD_ATTRIBUTE_PROTECTION_LEVEL = 0x0002000b
250+
PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE = 0x00020016
250251
)
251252

252253
const (
@@ -2139,6 +2140,12 @@ const (
21392140
ENABLE_LVB_GRID_WORLDWIDE = 0x10
21402141
)
21412142

2143+
// Pseudo console related constants used for the flags parameter to
2144+
// CreatePseudoConsole. See: https://learn.microsoft.com/en-us/windows/console/createpseudoconsole
2145+
const (
2146+
PSEUDOCONSOLE_INHERIT_CURSOR = 0x1
2147+
)
2148+
21422149
type Coord struct {
21432150
X int16
21442151
Y int16

windows/zsyscall_windows.go

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)