Skip to content

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.

csharp
public sealed class Hex1bTerminalChildProcess : IHex1bTerminalWorkloadAdapter, IAsyncDisposable

Inheritance

ObjectHex1bTerminalChildProcess

Implements

Constructors

Hex1bTerminalChildProcess(string, params string[])

Creates a new child process configuration.

Parameters:

  • fileName (String): The executable to run.
  • arguments (String[]): Command-line arguments.
csharp
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.
csharp
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>

csharp
public IReadOnlyList<string> Arguments { get; }

ExitCode

Gets the exit code of the process. Only valid after is true.

Returns: Int32

csharp
public int ExitCode { get; }

FileName

Gets the file name (executable path) of the process.

Returns: String

csharp
public string FileName { get; }

HasExited

Gets whether the process has exited.

Returns: Boolean

csharp
public bool HasExited { get; }

HasStarted

Gets whether the process has been started.

Returns: Boolean

csharp
public bool HasStarted { get; }

Height

Gets the current terminal height.

Returns: Int32

csharp
public int Height { get; }

ProcessId

Gets the process ID of the child process. Returns -1 if not started.

Returns: Int32

csharp
public int ProcessId { get; }

Width

Gets the current terminal width.

Returns: Int32

csharp
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.

csharp
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).
csharp
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:

Returns: ValueTask<Byte>>

csharp
public ValueTask<ReadOnlyMemory<byte>> ReadOutputAsync(CancellationToken ct = default)

ResizeAsync(int, int, CancellationToken)

Notify workload of terminal resize.

Parameters:

Returns: ValueTask

csharp
public ValueTask ResizeAsync(int width, int height, CancellationToken ct = default)

StartAsync(CancellationToken)

Starts the child process with an attached PTY.

Parameters:

Returns: Task

csharp
public Task StartAsync(CancellationToken ct = default)

WaitForExitAsync(CancellationToken)

Waits for the process to exit.

Parameters:

Returns: Task<Int32>

The exit code of the process.

csharp
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:

Returns: ValueTask

csharp
public ValueTask WriteInputAsync(ReadOnlyMemory<byte> data, CancellationToken ct = default)

Events

Disconnected

Raised when workload has disconnected/exited.

Returns: Action

csharp
public event Action? Disconnected

Remarks

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

csharp
// 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();

Released under the MIT License.