WinTer 0.1.1
Windows Terminal Emulator
Loading...
Searching...
No Matches
pty.h File Reference

Pseudo Console (PTY) lifecycle, stream management, and shell process spawning. More...

#include "base/base_macros.h"
#include "base/base_types.h"
#include <windows.h>
Include dependency graph for pty.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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.

Detailed Description

Pseudo Console (PTY) lifecycle, stream management, and shell process spawning.

Abstracts the three-phase setup required to host a shell inside a custom Windows application:

  1. Pipe creation two anonymous pipes (input and output) form the byte-level communication channels between our application and ConPTY.
  2. ConPTY initialization a Windows Pseudo Console session is created and bound to the pipe ends it owns.
  3. Shell spawning a child process (cmd.exe or similar) is created with a STARTUPINFOEXW attribute list that attaches it to the ConPTY, so all its I/O flows through our pipes.
Typical Usage
PTY_State pty = {0};
if (!pty_init(&pty, 80, 24)) {
// handle error
}
if (!pty_spawn(&pty, L"cmd.exe")) {
// handle error
}
// Read shell output via pty.hOutputRead
// Write keystrokes via pty.hInputWrite
static Logger L
The single global logger instance state.
Definition base_log.c:32
struct pty_state_t PTY_State
Encapsulates the OS-level state of an active Pseudo Console session.
b32 pty_init(struct pty_state_t *state, u16 columns, u16 rows)
Initializes a Pseudo Console and establishes bidirectional communication pipes.
Definition pty.c:50
void pty_cleanup(struct pty_state_t *state)
Terminates the Pseudo Console session and releases all active system handles.
Definition pty.c:260
b32 pty_spawn(struct pty_state_t *state, LPCWSTR command_line)
Spawns a shell process and attaches it to an initialized Pseudo Console.
Definition pty.c:116
Data Flow
App --[hInputWrite]--> [Input Pipe] --[hInputRead]--> ConPTY --> Shell
App <--[hOutputRead]-- [Output Pipe] <--[hOutputWrite]-- ConPTY <-- Shell
Note
This module is Windows-only. All types and APIs used are from the Win32 and ConPTY APIs introduced in Windows 10 version 1809.

Definition in file pty.h.