### Cross-Compile Native Library with Cross-Compiler Source: https://github.com/tomlm/porta.pty/blob/main/src/Porta.Pty.Native/README.md Example of cross-compiling the native library for Linux ARM64 using a cross-compiler. This requires additional toolchain setup. ```bash # Linux ARM64 (using cross-compiler) # Requires additional setup with arm64 toolchain ``` -------------------------------- ### Add Porta.Pty NuGet Package Source: https://github.com/tomlm/porta.pty/blob/main/README.md Install the Porta.Pty library using the .NET CLI. ```bash dotnet add package Porta.Pty ``` -------------------------------- ### Install Porta.Pty via Package Manager Console Source: https://github.com/tomlm/porta.pty/blob/main/README.md Install the Porta.Pty library using the Package Manager Console in Visual Studio. ```powershell Install-Package Porta.Pty ``` -------------------------------- ### Build Native Library Source: https://github.com/tomlm/porta.pty/blob/main/src/Porta.Pty.Native/README.md Execute the build script to compile the native PTY shim library. Ensure you have CMake and a C compiler installed. ```bash chmod +x build.sh ./build.sh ``` -------------------------------- ### PtyProvider.SpawnAsync Source: https://github.com/tomlm/porta.pty/blob/main/README.md Spawns a new terminal process with the specified options. This is the primary method for starting a new PTY session. ```APIDOC ## PtyProvider.SpawnAsync ### Description Spawns a new terminal process with the specified options. This is the primary method for starting a new PTY session. ### Method `async Task SpawnAsync(PtyOptions options, CancellationToken cancellationToken)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp 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 { { "MY_VAR", "value" } } }; using IPtyConnection terminal = await PtyProvider.SpawnAsync(options, CancellationToken.None); ``` ### Response #### Success Response (IPtyConnection) - **IPtyConnection**: An interface representing the active terminal connection, providing access to streams and control methods. #### Response Example ```csharp // The returned object is of type IPtyConnection ``` ### 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` | Environment variables (empty value removes the variable) ``` -------------------------------- ### Basic Pseudoterminal Usage Source: https://github.com/tomlm/porta.pty/blob/main/README.md Demonstrates spawning a terminal process, writing commands, reading output, and resizing the terminal. Ensure the correct executable path for 'App' based on the operating system. ```csharp 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 { { "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); ``` -------------------------------- ### Cross-Compile Native Library with Docker Source: https://github.com/tomlm/porta.pty/blob/main/src/Porta.Pty.Native/README.md Use Docker to cross-compile the native library for Linux x64. This is useful for CI/CD environments. ```bash # Linux x64 (on any Linux with Docker) docker run --rm -v $(pwd):/src -w /src gcc:latest ./build.sh ``` -------------------------------- ### IPtyConnection Interface Members Source: https://github.com/tomlm/porta.pty/blob/main/README.md Details on the members available through the IPtyConnection interface for managing the terminal. ```APIDOC ## IPtyConnection Interface ### Description Provides methods and properties to interact with a spawned terminal process. ### Members #### 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 ### Usage Example ```csharp // Writing to the terminal byte[] command = Encoding.UTF8.GetBytes("echo Hello World\r"); await terminal.WriterStream.WriteAsync(command, 0, command.Length); await terminal.WriterStream.FlushAsync(); // Reading 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); // Resizing the terminal terminal.Resize(80, 24); // Terminating the process terminal.Kill(); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.