VirtualTerminal.CommandLine
1.1.0
dotnet add package VirtualTerminal.CommandLine --version 1.1.0
NuGet\Install-Package VirtualTerminal.CommandLine -Version 1.1.0
<PackageReference Include="VirtualTerminal.CommandLine" Version="1.1.0" />
<PackageVersion Include="VirtualTerminal.CommandLine" Version="1.1.0" />
<PackageReference Include="VirtualTerminal.CommandLine" />
paket add VirtualTerminal.CommandLine --version 1.1.0
#r "nuget: VirtualTerminal.CommandLine, 1.1.0"
#:package VirtualTerminal.CommandLine@1.1.0
#addin nuget:?package=VirtualTerminal.CommandLine&version=1.1.0
#tool nuget:?package=VirtualTerminal.CommandLine&version=1.1.0
VirtualTerminal.CommandLine
VirtualTerminal.CommandLine is an addon for the core VirtualTerminal library that provides a CommandLineSession implementation based on Windows ConPTY.
It lets you host a real local command line (e.g. cmd.exe, PowerShell, custom CLI apps) inside the VirtualTerminalView WPF control.
Getting started
Reference the project
- Add a project reference from your WPF app to:
VirtualTerminal.CommandLineVirtualTerminal(core – already referenced by the addon).
- Ensure your app targets
net10.0-windowswith WPF enabled.
Basic usage with VirtualTerminalView
In XAML (same as core README):
<Window x:Class="MyApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vt="clr-namespace:VirtualTerminal;assembly=VirtualTerminal">
<Grid>
<vt:VirtualTerminalView x:Name="Terminal"
AllowDirectInput="True"
ScrollDownVisible="True" />
</Grid>
</Window>
In code-behind:
using System;
using System.Windows;
using VirtualTerminal;
public partial class MainWindow : Window
{
private CommandLineSession? _session;
public MainWindow()
{
InitializeComponent();
// Start default cmd.exe
_session = new CommandLineSession();
Terminal.Session = _session;
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
_session?.Dispose();
}
}
You now have an interactive command prompt embedded directly in your window.
CommandLineSession API
Located in CommandLineSession.cs (namespace VirtualTerminal).
Purpose
- Concrete
TerminalSessionimplementation backed by Windows ConPTY:- Connects a
VirtualTerminalBufferto a pseudoconsole. - Spawns a child process (e.g.
cmd.exe) attached to that pseudoconsole. - Forwards user input into the process, and process output into the buffer.
- Connects a
Constructors
CommandLineSession(string application)- Starts
applicationas the child process. - Uses
Encoding.UTF8asInputEncoding. - Internally calls
PseudoConsoleFactory.Start(Buffer, new ProcessCreationInfo { CommandLine = application }).
- Starts
CommandLineSession()- Convenience overload that starts the default Windows shell:
C:\Windows\System32\cmd.exe
- Convenience overload that starts the default Windows shell:
Properties
override string Title- Returns
"ConPTY".
- Returns
PseudoConsole PseudoConsole- Exposes the underlying
PseudoConsoleinstance (process + pipes).
- Exposes the underlying
Input and output pipeline
Internally, CommandLineSession:
- Starts a long-running background task
ReadOutputLoop():- Reads from
PseudoConsole.Reader. - Converts from
InputEncodingtoVirtualTerminalBuffer.Encoding. - Writes into
Bufferand callsNotifyBufferUpdated()to trigger UI re-rendering.
- Reads from
- Overrides
WriteInput(ReadOnlySpan<byte> data):- Writes input bytes into
PseudoConsole.Writer. - Calls
NotifyBufferUpdated()to ensure UI flush if needed.
- Writes input bytes into
Disposal
protected override void Dispose(bool disposing)- Cancels and disposes the read loop token.
- Disposes
PseudoConsole.
Always dispose CommandLineSession when you are done:
_session?.Dispose();
PseudoConsole and interop
VirtualTerminal.CommandLine.Interop contains the plumbing that connects the Windows pseudoconsole to the VirtualTerminalBuffer:
PseudoConsoleFactory
Located in Interop/PseudoConsoleFactory.cs.
static PseudoConsole Start(VirtualTerminalBuffer buffer, ProcessCreationInfo processInfo)- Creates anonymous pipes for stdin/stdout.
- Calls
CreatePseudoConsolewith buffer dimensions. - Starts a child process via
Win32ProcessFactory.Start(processInfo, handle). - Returns a
PseudoConsolethat wraps:- ConPTY handle
- Child process
Streamwriter (stdin)Streamreader (stdout)
You usually don’t need to use PseudoConsoleFactory directly unless you are building your own custom session around it.
Example: starting a custom CLI app
You can point CommandLineSession at any console application:
// Run PowerShell
var psSession = new CommandLineSession(@"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe");
Terminal.Session = psSession;
// Or Python REPL
var replSession = new CommandLineSession(@"C:\python314\python.exe");
Terminal.Session = replSession;
// Or some custom tool
var toolSession = new CommandLineSession(@"C:\path\to\mytool.exe");
Terminal.Session = toolSession;
All VT-compatible output from the tool will be rendered in the VirtualTerminalView.
Tips & limitations
- Windows-only: ConPTY is available on modern Windows 10+; the library targets
net10.0-windows. - Encoding:
CommandLineSessionuses UTF‑8 for input and converts output into the Unicode buffer encoding. - Resizing: When the WPF control resizes and calls
Resize, the underlyingVirtualTerminalBuffersize is updated. The child process will see the new console dimensions via ConPTY.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0-windows7.0 is compatible. |
-
net10.0-windows7.0
- VirtualTerminal (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.