Porta.Pty 1.0.7

dotnet add package Porta.Pty --version 1.0.7
                    
NuGet\Install-Package Porta.Pty -Version 1.0.7
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Porta.Pty" Version="1.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Porta.Pty" Version="1.0.7" />
                    
Directory.Packages.props
<PackageReference Include="Porta.Pty" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Porta.Pty --version 1.0.7
                    
#r "nuget: Porta.Pty, 1.0.7"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Porta.Pty@1.0.7
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Porta.Pty&version=1.0.7
                    
Install as a Cake Addin
#tool nuget:?package=Porta.Pty&version=1.0.7
                    
Install as a Cake Tool

Porta.Pty

A cross-platform pseudoterminal (PTY) library for .NET that enables spawning and interacting with terminal processes on Windows, Linux, and macOS.

Windows Linux macOS NuGet Version License: MIT

Features

  • Cross-Platform Support: Works on Windows (using ConPTY), Linux, and macOS
  • Simple API: Easy-to-use async API for spawning terminal processes
  • Full PTY Control: Read/write streams, resize terminal, handle process exit events
  • Unicode Support: Full UTF-8 support including complex characters
  • .NET Standard 2.0: Compatible with .NET Core 2.0+, .NET 5+, and .NET Framework 4.6.1+

Installation

Install via NuGet Package Manager:

dotnet add package Porta.Pty

Or via the Package Manager Console in Visual Studio:

Install-Package Porta.Pty

Usage

Basic Example

using Porta.Pty;
using System.Text;

// Configure the terminal options
var options = new PtyOptions
{
    Name = "MyTerminal",
    Cols = 120,
    Rows = 30,
    Cwd = Environment.CurrentDirectory,
    App = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) 
        ? Path.Combine(Environment.SystemDirectory, "cmd.exe") 
        : "/bin/bash",
    Environment = new Dictionary<string, string>
    {
        { "MY_VAR", "value" }
    }
};

// Spawn the terminal process
using IPtyConnection terminal = await PtyProvider.SpawnAsync(options, CancellationToken.None);

// Handle process exit
terminal.ProcessExited += (sender, e) => 
{
    Console.WriteLine($"Terminal exited with code: {e.ExitCode}");
};

// Write to the terminal
byte[] command = Encoding.UTF8.GetBytes("echo Hello World\r");
await terminal.WriterStream.WriteAsync(command, 0, command.Length);
await terminal.WriterStream.FlushAsync();

// Read from the terminal
byte[] buffer = new byte[4096];
int bytesRead = await terminal.ReaderStream.ReadAsync(buffer, 0, buffer.Length);
string output = Encoding.UTF8.GetString(buffer, 0, bytesRead);
Console.WriteLine(output);

// Resize the terminal
terminal.Resize(80, 24);

PtyOptions Properties

Property Type Description
Name string? Optional terminal name
Cols int Initial number of columns
Rows int Initial number of rows
Cwd string Working directory for the process
App string Path to the executable to spawn
CommandLine string[] Command line arguments
VerbatimCommandLine bool If true, arguments are not quoted
Environment IDictionary<string, string> Environment variables (empty value removes the variable)

IPtyConnection Interface

Member Description
ReaderStream Stream for reading output from the terminal
WriterStream Stream for writing input to the terminal
Pid Process ID of the terminal process
ExitCode Exit code (available after process exits)
ProcessExited Event fired when the process exits
Resize(cols, rows) Resize the terminal dimensions
Kill() Immediately terminate the process
WaitForExit(ms) Wait for process exit with timeout

Architecture

flowchart TB
    subgraph Entry["Entry Point"]
        PtyProvider["PtyProvider<br/>(Static class)"]
    end

    subgraph Platform["PlatformServices"]
        direction LR
        WinProvider["Windows<br/>Provider"]
        LinuxProvider["Linux<br/>Provider"]
        MacProvider["macOS<br/>Provider"]
    end

    subgraph Connections["Platform Connections"]
        direction LR
        PseudoConsole["PseudoConsole<br/>Connection<br/>(ConPTY API)"]
        LinuxPty["Unix PTY<br/>Connection<br/>(forkpty)"]
        MacPty["Unix PTY<br/>Connection<br/>(forkpty)"]
    end

    PtyProvider -->|"SpawnAsync(PtyOptions)"| Platform
    WinProvider --> PseudoConsole
    LinuxProvider --> LinuxPty
    MacProvider --> MacPty

    PseudoConsole -->|"implements"| IPtyConnection["IPtyConnection"]
    LinuxPty -->|"implements"| IPtyConnection
    MacPty -->|"implements"| IPtyConnection

Platform Implementations

Windows
  • Uses the Windows ConPTY (Pseudo Console) API introduced in Windows 10 1809
  • Leverages CreatePseudoConsole, ResizePseudoConsole, and ClosePseudoConsole native functions
  • Process isolation via Windows Job Objects for clean process termination
  • Implements proper cleanup order per Microsoft documentation
Linux & macOS
  • Uses POSIX PTY functions (forkpty, openpty)
  • Sets appropriate terminal environment variables (TERM=xterm-256color)
  • Clears conflicting environment variables (TMUX, screen sessions)

Key Components

Component Description
PtyProvider Static class providing the SpawnAsync entry point
PtyOptions Configuration class for terminal spawning
IPtyConnection Interface representing an active terminal connection
IPtyProvider Internal interface implemented by platform-specific providers
PlatformServices Platform detection and provider selection logic

Dependencies

  • Vanara.PInvoke.Kernel32: Windows API P/Invoke bindings
  • Mono.Posix.NETStandard: POSIX API bindings for Unix platforms

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Porta.Pty:

Package Downloads
Iciclecreek.Avalonia.Terminal

Avalonia terminal controls (TerminalControl/TerminalWindow) that provide an XTerm console for hosting console applications in Avalonia.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 197 1/22/2026
1.0.6 324 12/29/2025
1.0.5 179 12/26/2025
1.0.4 183 12/25/2025
1.0.3 179 12/23/2025
1.0.2 173 12/23/2025
1.0.0 176 12/23/2025