Hex1bTerminalChildProcess
Namespace: Hex1b
Assembly: Hex1b.dll
Represents a child process attached to a pseudo-terminal (PTY). The process's stdin/stdout/stderr are connected to the PTY, making it believe it's running in an interactive terminal.
public sealed class Hex1bTerminalChildProcess : IHex1bTerminalWorkloadAdapter, IAsyncDisposableInheritance
Object → Hex1bTerminalChildProcess
Implements
Constructors
Hex1bTerminalChildProcess(string, params string[])
Creates a new child process configuration.
Parameters:
public Hex1bTerminalChildProcess(string fileName, params string[] arguments)Hex1bTerminalChildProcess(string, string[], string?, Dictionary<string, string>?, bool, int, int)
Creates a new child process configuration with full options.
Parameters:
fileName(String): The executable to run.arguments(String[]): Command-line arguments.workingDirectory(String): Working directory for the process. Null uses current directory.environment(Dictionary<String, String>): Additional environment variables. Null uses none.inheritEnvironment(Boolean): Whether to inherit the parent's environment variables.initialWidth(Int32): Initial terminal width in columns.initialHeight(Int32): Initial terminal height in rows.
public Hex1bTerminalChildProcess(string fileName, string[] arguments, string? workingDirectory = null, Dictionary<string, string>? environment = null, bool inheritEnvironment = true, int initialWidth = 80, int initialHeight = 24)Properties
Arguments
Gets the arguments passed to the process.
Returns: IReadOnlyList<String>
public IReadOnlyList<string> Arguments { get; }ExitCode
Gets the exit code of the process. Only valid after is true.
Returns: Int32
public int ExitCode { get; }FileName
Gets the file name (executable path) of the process.
Returns: String
public string FileName { get; }HasExited
Gets whether the process has exited.
Returns: Boolean
public bool HasExited { get; }HasStarted
Gets whether the process has been started.
Returns: Boolean
public bool HasStarted { get; }Height
Gets the current terminal height.
Returns: Int32
public int Height { get; }ProcessId
Gets the process ID of the child process. Returns -1 if not started.
Returns: Int32
public int ProcessId { get; }Width
Gets the current terminal width.
Returns: Int32
public int Width { get; }Methods
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
Returns: ValueTask
A task that represents the asynchronous dispose operation.
public ValueTask DisposeAsync()Kill(int)
Sends a signal to the process (Unix) or terminates it (Windows).
Parameters:
signal(Int32): The signal number (Unix only). Default is SIGTERM (15).
public void Kill(int signal = 15)ReadOutputAsync(CancellationToken)
Read output FROM the workload (ANSI sequences to display). The terminal calls this to get data to parse and send to presentation. Returns empty when workload has no more output (should be called in a loop).
Parameters:
ct(CancellationToken):
Returns: ValueTask<Byte>>
public ValueTask<ReadOnlyMemory<byte>> ReadOutputAsync(CancellationToken ct = default)ResizeAsync(int, int, CancellationToken)
Notify workload of terminal resize.
Parameters:
width(Int32):height(Int32):ct(CancellationToken):
Returns: ValueTask
public ValueTask ResizeAsync(int width, int height, CancellationToken ct = default)StartAsync(CancellationToken)
Starts the child process with an attached PTY.
Parameters:
ct(CancellationToken): Cancellation token.
Returns: Task
public Task StartAsync(CancellationToken ct = default)WaitForExitAsync(CancellationToken)
Waits for the process to exit.
Parameters:
ct(CancellationToken): Cancellation token.
Returns: Task<Int32>
The exit code of the process.
public Task<int> WaitForExitAsync(CancellationToken ct = default)WriteInputAsync(ReadOnlyMemory<byte>, CancellationToken)
Write input TO the workload (raw bytes from keyboard/mouse). The terminal calls this when it receives input from the presentation layer.
Parameters:
data(ReadOnlyMemory<Byte>):ct(CancellationToken):
Returns: ValueTask
public ValueTask WriteInputAsync(ReadOnlyMemory<byte> data, CancellationToken ct = default)Events
Disconnected
Raised when workload has disconnected/exited.
Returns: Action
public event Action? DisconnectedRemarks
This class implements , allowing it to be used directly with as the workload source.
Platform support: Linux/macOS: Uses POSIX PTY APIs (posix_openpt, forkpty, etc.)Windows: Uses ConPTY APIs (CreatePseudoConsole, etc.)
Examples
// Launch bash with a PTY attached
await using var process = new Hex1bTerminalChildProcess("/bin/bash", "-l");
await process.StartAsync();
// Connect to Hex1bTerminal
using var terminal = new Hex1bTerminal(process, 80, 24);
// Wait for process to exit
var exitCode = await process.WaitForExitAsync();