console.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //go:build windows
  2. package winapi
  3. import (
  4. "unsafe"
  5. "golang.org/x/sys/windows"
  6. )
  7. const PSEUDOCONSOLE_INHERIT_CURSOR = 0x1
  8. // CreatePseudoConsole creates a windows pseudo console.
  9. func CreatePseudoConsole(size windows.Coord, hInput windows.Handle, hOutput windows.Handle, dwFlags uint32, hpcon *windows.Handle) error {
  10. // We need this wrapper as the function takes a COORD struct and not a pointer to one, so we need to cast to something beforehand.
  11. return createPseudoConsole(*((*uint32)(unsafe.Pointer(&size))), hInput, hOutput, 0, hpcon)
  12. }
  13. // ResizePseudoConsole resizes the internal buffers of the pseudo console to the width and height specified in `size`.
  14. func ResizePseudoConsole(hpcon windows.Handle, size windows.Coord) error {
  15. // We need this wrapper as the function takes a COORD struct and not a pointer to one, so we need to cast to something beforehand.
  16. return resizePseudoConsole(hpcon, *((*uint32)(unsafe.Pointer(&size))))
  17. }
  18. // HRESULT WINAPI CreatePseudoConsole(
  19. // _In_ COORD size,
  20. // _In_ HANDLE hInput,
  21. // _In_ HANDLE hOutput,
  22. // _In_ DWORD dwFlags,
  23. // _Out_ HPCON* phPC
  24. // );
  25. //
  26. //sys createPseudoConsole(size uint32, hInput windows.Handle, hOutput windows.Handle, dwFlags uint32, hpcon *windows.Handle) (hr error) = kernel32.CreatePseudoConsole
  27. // void WINAPI ClosePseudoConsole(
  28. // _In_ HPCON hPC
  29. // );
  30. //
  31. //sys ClosePseudoConsole(hpc windows.Handle) = kernel32.ClosePseudoConsole
  32. // HRESULT WINAPI ResizePseudoConsole(
  33. // _In_ HPCON hPC ,
  34. // _In_ COORD size
  35. // );
  36. //
  37. //sys resizePseudoConsole(hPc windows.Handle, size uint32) (hr error) = kernel32.ResizePseudoConsole