|
WinTer 0.1.1
Windows Terminal Emulator
|
Core structures and routines for terminal shell bridging via Windows ConPTY. More...
Classes | |
| struct | pty_state_t |
| Encapsulates the OS-level state of an active Pseudo Console session. More... | |
Typedefs | |
| typedef struct pty_state_t | PTY_State |
| Encapsulates the OS-level state of an active Pseudo Console session. | |
Functions | |
| b32 | pty_init (struct pty_state_t *state, u16 columns, u16 rows) |
| Initializes a Pseudo Console and establishes bidirectional communication pipes. | |
| b32 | pty_spawn (struct pty_state_t *state, LPCWSTR command_line) |
| Spawns a shell process and attaches it to an initialized Pseudo Console. | |
| void | pty_cleanup (struct pty_state_t *state) |
| Terminates the Pseudo Console session and releases all active system handles. | |
| INTERNAL void | safe_close_handle (HANDLE *h) |
| Safely closes a Win32 HANDLE and sets the pointer to NULL. | |
Core structures and routines for terminal shell bridging via Windows ConPTY.
This module encapsulates the full lifecycle of a Windows pseudo-terminal session. It manages anonymous pipe creation, the ConPTY object, and the child shell process that writes output into and reads input from those pipes.
Separating these phases allows the caller to configure the ConPTY (e.g., resize it) before a shell is attached, and makes the code easier to reason about.
| typedef struct pty_state_t PTY_State |
Encapsulates the OS-level state of an active Pseudo Console session.
This struct owns all Win32 handles needed to communicate with the shell process. All handles are initialized to NULL and must only be used after a successful call to pty_init(). The hProcess and hThread handles are populated after a successful call to pty_spawn().
| void pty_cleanup | ( | struct pty_state_t * | state | ) |
Terminates the Pseudo Console session and releases all active system handles.
Closes the ConPTY object, the shell process handle, and the pipe handles owned by our application. All pointers in state are set to NULL after cleanup.
| [in,out] | state | Pointer to the PTY state structure to clean up. Safe to call with NULL or a partially initialized state. |
Definition at line 260 of file pty.c.


| b32 pty_init | ( | struct pty_state_t * | state, |
| u16 | columns, | ||
| u16 | rows ) |
Initializes a Pseudo Console and establishes bidirectional communication pipes.
This function performs the first phase of PTY setup:
After this call, state->hInputWrite and state->hOutputRead are valid and ready for I/O. No shell is attached yet call pty_spawn() for that.
| [out] | state | Pointer to the state structure to populate. Must not be NULL. |
| [in] | columns | Initial terminal grid width in characters (e.g., 80). |
| [in] | rows | Initial terminal grid height in characters (e.g., 24). |
Definition at line 50 of file pty.c.


| b32 pty_spawn | ( | struct pty_state_t * | state, |
| LPCWSTR | command_line ) |
Spawns a shell process and attaches it to an initialized Pseudo Console.
This function performs the second phase of PTY setup. It uses the extended process creation API (STARTUPINFOEXW + PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE) to attach the new process to the ConPTY created by pty_init().
The key steps are:
| [in,out] | state | Pointer to a state structure populated by pty_init(). Must not be NULL. On success, state->hProcess is set. |
| [in] | command_line | The command to execute as a wide string (e.g., L"cmd.exe"). Windows resolves bare names via the system PATH. Must not be NULL. |
Definition at line 116 of file pty.c.

| INTERNAL void safe_close_handle | ( | HANDLE * | h | ) |
Safely closes a Win32 HANDLE and sets the pointer to NULL.
This is an internal guard wrapper around CloseHandle. It is a no-op if *h is already NULL, making it safe to call on partially initialized state.
| [in,out] | h | Pointer to the HANDLE to close. Set to NULL on success. |
Definition at line 41 of file pty.c.
