Parent: #77
Summary
Implement WindowsConsole using Windows Console API via P/Invoke for proper VT100 support and event-driven input.
Files to Create
src/Termina/Platform/WindowsConsole.cs
P/Invoke Requirements
Console Mode Flags
const uint ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;
const uint ENABLE_WINDOW_INPUT = 0x0008;
const uint ENABLE_MOUSE_INPUT = 0x0010; // Optional
Required APIs
GetStdHandle(STD_INPUT_HANDLE, STD_OUTPUT_HANDLE)
GetConsoleMode() / SetConsoleMode()
ReadConsoleInputW() - Read INPUT_RECORD structs
WaitForSingleObjectEx() - Cancellable wait on input handle
GetConsoleScreenBufferInfo() - Terminal dimensions
Input Records
[StructLayout(LayoutKind.Explicit)]
struct INPUT_RECORD
{
[FieldOffset(0)] public ushort EventType;
[FieldOffset(4)] public KEY_EVENT_RECORD KeyEvent;
[FieldOffset(4)] public WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent;
}
Key Behaviors
- Initialize(): Enable VT100 processing + window input events
- ReadInputAsync(): Use
WaitForSingleObjectEx with timeout for cancellation, then ReadConsoleInputW
- Restore(): Reset console mode to original state
- Resized: Emit when
WINDOW_BUFFER_SIZE_EVENT received
Acceptance Criteria
Parent: #77
Summary
Implement
WindowsConsoleusing Windows Console API via P/Invoke for proper VT100 support and event-driven input.Files to Create
src/Termina/Platform/WindowsConsole.csP/Invoke Requirements
Console Mode Flags
Required APIs
GetStdHandle(STD_INPUT_HANDLE, STD_OUTPUT_HANDLE)GetConsoleMode()/SetConsoleMode()ReadConsoleInputW()- Read INPUT_RECORD structsWaitForSingleObjectEx()- Cancellable wait on input handleGetConsoleScreenBufferInfo()- Terminal dimensionsInput Records
Key Behaviors
WaitForSingleObjectExwith timeout for cancellation, thenReadConsoleInputWWINDOW_BUFFER_SIZE_EVENTreceivedAcceptance Criteria