### WinGet Install Command Example Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ This is an example of a suggested command that the user can run to install a package that might resolve a 'command not found' error. The actual command will be dynamically generated based on the missing command. ```bash winget install... ``` -------------------------------- ### Hierarchy Example: Conhost and Terminal (Default Application) Source: https://github.com/microsoft/terminal/blob/main/doc/specs/drafts/ Illustrates a scenario where `conhost.exe` is started in response to a process without a host, then connects to a running `wt.exe` instance. ```text - conhost.exe (in PTY mode) - Hosted to A |- pwsh.exe - wt.exe (Terminal Instance A) ``` -------------------------------- ### Setup Build Environment and Get Formatting Tool Source: https://github.com/microsoft/terminal/blob/main/doc/building.md Import the OpenConsole PowerShell module, set up the MSBuild development environment, and download the clang-format executable. This is required for code formatting within Visual Studio. ```powershell Import-Module .\tools\OpenConsole.psm1 Set-MsBuildDevEnvironment Get-Format ``` -------------------------------- ### Global Summon Examples Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ These examples demonstrate various configurations for the globalSummon action, controlling window activation and placement across monitors and desktops. ```json { "keys": "win+1", "command":{ "action":"globalSummon", "monitor":"any", "desktop": "any" } } ``` ```json { "keys": "win+2", "command":{ "action":"globalSummon", "monitor":"toCurrent", "desktop": "toCurrent" } } ``` ```json { "keys": "win+2", "command": "globalSummon" } ``` ```json { "keys": "win+3", "command":{ "action":"globalSummon", "monitor":"any", "desktop": "onCurrent" } } ``` ```json { "keys": "win+4", "command":{ "action":"globalSummon", "monitor": 2, "desktop": "toCurrent" } } ``` ```json { "keys": "win+5", "command":{ "action":"globalSummon", "monitor": 3, "desktop": "onCurrent" } } ``` ```json { "keys": "win+6", "command":{ "action":"globalSummon", "monitor": "onCurrent", "desktop": "toCurrent" } } ``` -------------------------------- ### Example Usage for Updating NuGet Packages Source: https://github.com/microsoft/terminal/blob/main/doc/building.md An example demonstrating how to update the `Microsoft.UI.Xaml` package from version `2.4.0-prerelease.200506002` to `2.5.0-prerelease.200812002` using the `git grep` and `sed` command. ```shell git grep -z -l Microsoft.UI.Xaml | xargs -0 sed -i -e 's/2.4.0-prerelease.200506002/2.5.0-prerelease.200812002/g' ``` -------------------------------- ### Full JSON Configuration Example Source: https://github.com/microsoft/terminal/blob/main/doc/specs/Proto extensions-spec.md An example of a complete JSON file that includes profile updates and a new color scheme definition. This combines multiple configuration elements. ```js { "profiles": [ { "updates": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}", "fontSize": 16, "fontWeight": "thin" }, { "guid": "{a821ae62-9d4a-3e34-b989-0a998ec283e6}", "name": "Cool Profile", "commandline": "powershell.exe", "antialiasingMode": "aliased", "fontWeight": "bold", "scrollbarState": "hidden" } ], "schemes": [ { "name": "Postmodern Tango Light", "cursorColor": "#FFFFFF", "selectionBackground": "#FFFFFF", "background": '#61D6D6', "foreground": '#E74856', "black" : "#0C0C0C", "blue" : "#0037DA", "cyan" : "#3A96DD", "green" : "#13A10E", "purple" : "#881798", "red" : "#C50F1F", "white" : "#CCCCCC", "yellow" : "#C19C00", "brightBlack" : "#767676", "brightBlue" : "#3B78FF", "brightCyan" : "#61D6D6", "brightGreen" : "#16C60C", "brightPurple" : "#B4009E", "brightRed" : "#E74856", "brightWhite" : "#F2F2F2", "brightYellow" : "#F9F1A5" } ] } ``` -------------------------------- ### Combine Profile and Starting Directory Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ Open a specific profile in a new tab and set its starting directory simultaneously using `--profile` and `--startingDirectory` (or their short forms). ```sh wt new-tab --profile "Windows Powershell" --startingDirectory "c:/Users/Foo/dev/MyProject" wt --profile "Windows Powershell" --startingDirectory "c:/Users/Foo/dev/MyProject" wt -p "Windows Powershell" -d "c:/Users/Foo/dev/MyProject" ``` -------------------------------- ### Set Starting Directory Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ Specify the starting directory for a new tab using `--startingDirectory` or `-d`. Both forward and backward slashes are accepted for paths. ```sh wt new-tab --startingDirectory "c:/Users/Foo/dev/MyProject" wt --startingDirectory "c:/Users/Foo/dev/MyProject" wt -d "c:/Users/Foo/dev/MyProject" wt -d "c:\Users\Foo\dev\MyProject" ``` -------------------------------- ### Initial Process Hierarchy Example Source: https://github.com/microsoft/terminal/blob/main/doc/specs/drafts/ Illustrates the process tree before a tab is torn off from Terminal Instance A and merged into Terminal Instance B. ```text - wt.exe (Terminal Instance A) |- conhost.exe (in PTY mode) - Hosted to A | |- cmd.exe |- conhost.exe (in PTY mode) - Hosted to A |- pwsh.exe <-- I will be dragged out - wt.exe (Terminal Instance B) |- conhost.exe (in PTY mode) - Hosted to B |- cmd.exe ``` -------------------------------- ### Full XAML Hosting Test Class Setup Source: https://github.com/microsoft/terminal/blob/main/doc/cascadia/Unittesting-CppWinRT-Xaml.md This snippet shows a complete C++ test class setup for XAML hosting. It includes initializing the WinRT apartment, setting up the WindowsXamlManager, and initializing a DesktopWindowXamlSource, which are necessary for using XAML types within a test. ```c++ class TabTests { BEGIN_TEST_CLASS(TabTests) TEST_CLASS_PROPERTY(L"RunAs", L"UAP") TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TerminalApp.Unit.Tests.AppxManifest.xml") END_TEST_CLASS() TEST_METHOD(TryCreateXamlObjects); TEST_CLASS_SETUP(ClassSetup) { winrt::init_apartment(winrt::apartment_type::single_threaded); // Initialize the Xaml Hosting Manager _manager = winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread(); _source = winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource{}; return true; } private: winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager _manager{ nullptr }; winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource _source{ nullptr }; }; void TabTests::TryCreateXamlObjects(){ ... } ``` -------------------------------- ### Win32 ConPTY C API Example Source: https://context7.com/microsoft/terminal/llms.txt Provides C++ examples for the core Win32 ConPTY functions: `CreatePseudoConsole`, `ResizePseudoConsole`, and `ClosePseudoConsole`. It includes functions for creating pipes and the pseudo console, spawning a child process, resizing the console, and cleanup. ```APIDOC ## CreatePseudoConsole — Win32 ConPTY C API The three Win32 functions `CreatePseudoConsole`, `ResizePseudoConsole`, and `ClosePseudoConsole` in `kernel32.dll` are the lowest-level entry point. Any application that wants full VT terminal emulation for a child process creates a pair of anonymous pipes, connects them to a `HPCON`, then passes the handle via `PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE` in a `STARTUPINFOEX` when spawning the child. ```cpp // EchoCon pattern — complete C++ ConPTY usage (from samples/ConPTY/EchoCon) #include #include HRESULT CreatePseudoConsoleAndPipes(HPCON* phPC, HANDLE* phPipeIn, HANDLE* phPipeOut) { HANDLE hPipePTYIn{INVALID_HANDLE_VALUE}, hPipePTYOut{INVALID_HANDLE_VALUE}; if (!CreatePipe(&hPipePTYIn, phPipeOut, NULL, 0) || !CreatePipe(phPipeIn, &hPipePTYOut, NULL, 0)) return HRESULT_FROM_WIN32(GetLastError()); COORD size{}; CONSOLE_SCREEN_BUFFER_INFO csbi{}; if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) { size.X = csbi.srWindow.Right - csbi.srWindow.Left + 1; size.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; } HRESULT hr = CreatePseudoConsole(size, hPipePTYIn, hPipePTYOut, 0, phPC); CloseHandle(hPipePTYOut); CloseHandle(hPipePTYIn); return hr; } // Launch a child process attached to the ConPTY HRESULT SpawnProcess(HPCON hPC, HANDLE* phProcess) { STARTUPINFOEX si{}; si.StartupInfo.cb = sizeof(STARTUPINFOEX); size_t attrSize{}; InitializeProcThreadAttributeList(NULL, 1, 0, &attrSize); si.lpAttributeList = (LPPROC_THREAD_ATTRIBUTE_LIST)malloc(attrSize); InitializeProcThreadAttributeList(si.lpAttributeList, 1, 0, &attrSize); UpdateProcThreadAttribute(si.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, hPC, sizeof(HPCON), NULL, NULL); wchar_t cmd[] = L"ping localhost"; PROCESS_INFORMATION pi{}; if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, EXTENDED_STARTUPINFO_PRESENT, NULL, NULL, &si.StartupInfo, &pi)) return HRESULT_FROM_WIN32(GetLastError()); *phProcess = pi.hProcess; CloseHandle(pi.hThread); DeleteProcThreadAttributeList(si.lpAttributeList); free(si.lpAttributeList); return S_OK; } // Resize the pseudo console after user resizes the window void HandleResize(HPCON hPC, SHORT newCols, SHORT newRows) { COORD newSize{ newCols, newRows }; ResizePseudoConsole(hPC, newSize); } // Cleanup void Teardown(HPCON hPC, HANDLE hPipeIn, HANDLE hPipeOut) { ClosePseudoConsole(hPC); CloseHandle(hPipeOut); CloseHandle(hPipeIn); } ``` ``` -------------------------------- ### IControlSettings Configuration Example Source: https://context7.com/microsoft/terminal/llms.txt Illustrates the configuration options available through the IControlSettings interface using a JSON snippet for settings.json. ```APIDOC ## IControlSettings — terminal control configuration `IControlSettings` (namespace `Microsoft.Terminal.Control`) extends `ICoreSettings` and `IControlAppearance` and is the single configuration interface consumed by `TermControl`. It covers font, padding, scrollbar style, antialiasing, key behavior, graphics API selection, and path translation for WSL/Cygwin. ```json // settings.json — profile snippet exercising key IControlSettings properties { "profiles": { "defaults": { "font": { "face": "Cascadia Code", "size": 12, "weight": "normal", "features": { "ss01": 1 }, "axes": { "wght": 400 }, "cellWidth": "1.0", "cellHeight": "1.2" }, "padding": "8", "scrollbarState": "visible", "antialiasingMode": "grayscale", "copyOnSelect": false, "focusFollowMouse": false, "graphicsAPI": "automatic", "textMeasurement": "graphemes", "pathTranslationStyle": "wsl", "rightClickContextMenu": true, "repositionCursorWithMouse": true }, "list": [ { "name": "Ubuntu", "guid": "{2c4de342-38b7-51cf-b940-2309a097f518}", "commandline": "wsl.exe -d Ubuntu", "startingDirectory": "~", "colorScheme": "One Half Dark", "font": { "face": "Cascadia Mono", "size": 11 }, "scrollbarState": "always", "antialiasingMode": "cleartype" } ] } } ``` ``` -------------------------------- ### Start Elevated Process using ShellExecute Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ This C++ code snippet demonstrates how to start an elevated process by using the 'runas' verb with ShellExecute. This will trigger a UAC prompt before spawning the target executable. ```c++ ShellExecute(nullptr, L"runas", L"wt.exe", L"-w new new-tab [args...]", nullptr, SW_SHOWNORMAL); ``` -------------------------------- ### Project Cascadia KeyBindings Implementation Example Source: https://github.com/microsoft/terminal/blob/main/doc/specs/Keybindings-spec.md An example implementation of the `IKeyBindings` interface for the Project Cascadia application. It includes a dictionary to map shortcut actions to key chords and defines delegates for various terminal actions. ```csharp enum ShortcutAction { CopyText, PasteText, NewTab, NewWindow, CloseWindow, CloseTab, SwitchToTab, NextTab, PrevTab, IncreaseFontSize, DecreaseFontSize, ... } public delegate bool NewTabEvent(object sender); public delegate bool CloseTabEvent(object sender); public delegate bool NewWindowEvent(object sender); public delegate bool CloseWindowEvent(object sender); public delegate bool CopyEvent(object sender); public delegate bool PasteEvent(object sender); class KeyBindings : IKeyBindings { private Dictionary keyShortcuts; public void SetKeyBinding(ShortcutAction action, KeyChord? chord); public bool TryKeyChord(KeyChord chord); } ``` -------------------------------- ### AllocConsoleWithOptions Example Usage (Conceptual) Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ Illustrates how AllocConsoleWithOptions can be used to manage console window behavior, particularly for Python applications. ```c++ > **EXAMPLE**: If Python updates python.exe to specify an allocation policy of **detached**, graphical python applications > will become double-click runnable from the graphical shell without spawning a console window. _However_, console-based > python applications will no longer spawn a console window when double-clicked from the graphical shell. > > In addition, if python.exe specifies **detached**, Console APIs will fail until a console is allocated. Python could work around this by calling [`AllocConsole`] or [new API `AllocConsoleWithOptions`](#allocconsolewithoptions) if it can be detected that console I/O is required. ``` -------------------------------- ### Add Cygwin Profile Source: https://github.com/microsoft/terminal/blob/main/doc/user-docs/ThirdPartyToolProfiles.md Configure a Cygwin profile, setting the command line to launch bash and specifying the icon and starting directory. ```json { "name": "Cygwin", "commandline": "C:\\Cygwin\\bin\\bash --login -i", "icon": "C:\\Cygwin\\Cygwin.ico", "startingDirectory": "C:\\Cygwin\\bin" } ``` -------------------------------- ### Interrogating JSON with GetValueForKey and optional Source: https://github.com/microsoft/terminal/blob/main/doc/cascadia/Json-Utility-API.md This example demonstrates how to check for the presence of a specific member in a JSON object using GetValueForKey with std::optional. The condition is true only if the 'guid' member exists in the JSON. ```c++ if (const auto guid{ GetValueForKey>(json, "guid") }) // This condition is only true if there was a "guid" member in the provided JSON object. // It can be accessed through *guid. ``` -------------------------------- ### ITerminalConnection Interface Implementation Source: https://context7.com/microsoft/terminal/llms.txt This C# example demonstrates how to implement the `ITerminalConnection` WinRT interface to create a custom terminal backend that wraps a named-pipe server. It covers starting the connection, handling input and output, resizing the terminal, and managing connection state. ```APIDOC ## ITerminalConnection Interface Implementation ### Description This C# WinRT example shows a custom `ITerminalConnection` implementation that wraps a named-pipe server. It details how to handle terminal output, state changes, starting the connection, writing input, resizing, and closing the connection. ### Class `PipeConnection` ### Interface Implemented `Microsoft.Terminal.TerminalConnection.ITerminalConnection` ### Methods - **`Initialize(ValueSet settings)`**: Optional per-connection configuration. - **`Start()`**: Initiates the connection process. Sets state to `Connecting`, then `Connected` upon successful connection. Starts a background read loop. - **`WriteInput(char[] data)`**: Forwards user keystrokes to the backend. - **`Resize(uint rows, uint columns)`**: Notifies the backend of viewport size changes, typically by sending an escape sequence. - **`Close()`**: Initiates the closing process. Sets state to `Closing`, then `Closed`. ### Events - **`TerminalOutput`**: Event handler for receiving terminal output from the backend. - **`StateChanged`**: Event handler for `ConnectionState` transitions (e.g., `NotConnected` -> `Connecting` -> `Connected` -> `Closing` -> `Closed` / `Failed`). ### Properties - **`SessionId`**: A unique identifier for the connection session. - **`State`**: The current state of the connection (`ConnectionState`). ### Example Usage (Conceptual) ```csharp // C# WinRT – custom ITerminalConnection that wraps a named-pipe server using Microsoft.Terminal.TerminalConnection; using Windows.Foundation.Collections; public sealed class PipeConnection : ITerminalConnection { private readonly NamedPipeClientStream _pipe; public event TerminalOutputHandler TerminalOutput; public event TypedEventHandler StateChanged; public Guid SessionId { get; } = Guid.NewGuid(); public ConnectionState State { get; private set; } = ConnectionState.NotConnected; public PipeConnection(string pipeName) => _pipe = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.Asynchronous); public void Initialize(ValueSet settings) { /* optional per-connection config */ } public async void Start() { State = ConnectionState.Connecting; StateChanged?.Invoke(this, null); await _pipe.ConnectAsync(3000); // 3 s timeout State = ConnectionState.Connected; StateChanged?.Invoke(this, null); _ = ReadLoopAsync(); } public void WriteInput(char[] data) => _pipe.Write(System.Text.Encoding.UTF8.GetBytes(data)); public void Resize(uint rows, uint columns) { // send resize escape or protocol message to server var msg = $"\x1b[8;{rows};{columns}t"; WriteInput(msg.ToCharArray()); } public void Close() { State = ConnectionState.Closing; StateChanged?.Invoke(this, null); _pipe.Close(); State = ConnectionState.Closed; StateChanged?.Invoke(this, null); } private async Task ReadLoopAsync() { var buf = new byte[4096]; while (_pipe.IsConnected) { int n = await _pipe.ReadAsync(buf, 0, buf.Length); if (n == 0) break; TerminalOutput?.Invoke(System.Text.Encoding.UTF8.GetChars(buf, 0, n)); } State = ConnectionState.Closed; StateChanged?.Invoke(this, null); } } ``` ``` -------------------------------- ### Install Windows Terminal via Scoop Source: https://github.com/microsoft/terminal/blob/main/README.md To install Windows Terminal using Scoop, first add the 'extras' bucket, then install the 'windows-terminal' package. Refer to the Scoop Extras repository issues page for any installation problems. ```powershell scoop bucket add extras ``` ```powershell scoop install windows-terminal ``` -------------------------------- ### Install Windows Terminal via Chocolatey Source: https://github.com/microsoft/terminal/blob/main/README.md Use this command to install the latest Windows Terminal release using Chocolatey. Ensure Chocolatey is installed and configured. ```powershell choco install microsoft-windows-terminal ``` -------------------------------- ### Expose Namespace and GUID Generation Functions Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ Functions exposed to dynamic profile generators for retrieving their namespace GUID and generating UUIDv5 GUIDs within that namespace. ```c++ GUID GetNamespaceGuid(IDynamicProfileGenerator& generator); GUID GetGuidForName(IDynamicProfileGenerator& generator, std::wstring& name); ``` -------------------------------- ### Nested Actions Example Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ Shows an example of nested actions, which currently do not support top-level IDs for keybinding purposes. ```json { // Select color scheme... "name": { "key": "SetColorSchemeParentCommandName" }, "commands": [ { "iterateOn": "schemes", "name": "${scheme.name}", "command": { "action": "setColorScheme", "colorScheme": "${scheme.name}" } } ] } ``` -------------------------------- ### Existing Profile Stub Example Source: https://github.com/microsoft/terminal/blob/main/doc/specs/Proto extensions-spec.md This is an example of an existing Azure Cloud Shell profile in the user's settings file, which can be targeted for modification. ```json { "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}", "hidden": false, "name": "Azure Cloud Shell", "source": "Windows.Terminal.Azure" } ``` -------------------------------- ### New Tab Menu Configuration Example Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ Demonstrates the structure for configuring the new tab menu using 'matchProfile' and 'remainingProfiles' entries. This configuration allows for dynamic menu generation based on available profiles. ```jsonc { "newTabMenu": [ { "type": "matchProfile", "source": "Microsoft.Terminal.Wsl" } { "type": "folder", "name": "WSLs", "entries": [ { "type": "matchProfile", "source": "Microsoft.Terminal.Wsl" } ] }, { "type": "remainingProfiles" } ] } ``` -------------------------------- ### Unified Keybindings and Commands Example Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ This JSON demonstrates how to define a single action that functions as both a keybinding and a command palette entry. It replaces the older, more verbose method of defining them separately. ```json { "keybindings": [ { "keys": [ "ctrl+alt+t" ], "command": { "action": "splitPane", "split":"auto", "splitMode": "duplicate" } }, ], "commands": [ { "name": "Duplicate Pane", "action": { "action": "splitPane", "split":"auto", "splitMode": "duplicate" }, "icon": null }, ] } ``` -------------------------------- ### Prepopulate Suggestions UI with Commandline Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ Use this action to invoke the Suggestions UI, filtering results based on the user's current commandline input. Requires shell integration to be enabled. ```json { "command": { "action":"suggestions", "source": "commandHistory", "useCommandline": true } } ``` -------------------------------- ### ConptyConnection C# Example Source: https://context7.com/microsoft/terminal/llms.txt Demonstrates launching PowerShell 7 within a ConptyConnection using the C# WinRT projection. It covers creating settings, initializing the connection, handling output and state changes, sending input, resizing, and graceful shutdown. ```APIDOC ## ConptyConnection — Win32 Pseudo Console connection `ConptyConnection` (namespace `Microsoft.Terminal.TerminalConnection`) is the built-in `ITerminalConnection` that wraps the Windows Pseudo Console (`CreatePseudoConsole`). The static `CreateSettings()` factory builds the `ValueSet` configuration bag; `StartInboundListener()` / `NewConnection` allow a process to accept inbound ConPTY connections from child processes. `RootProcessHandle()` returns the HANDLE of the spawned process for external wait logic. ```csharp // Launch PowerShell 7 in a ConptyConnection (C# WinRT projection) using Microsoft.Terminal.TerminalConnection; using Windows.Foundation.Collections; // Build the settings ValueSet ValueSet settings = ConptyConnection.CreateSettings( cmdline: @"pwsh.exe", startingDirectory: @"C:\Users\dev", startingTitle: "PowerShell 7", reloadEnvironmentVariables: true, initialEnvironment: null, environmentOverrides: new Dictionary { ["MY_VAR"] = "hello" } .ToImmutableDictionary(), rows: 30, columns: 120, guid: Guid.NewGuid(), // session id profileGuid: Guid.NewGuid()); // associated profile var conn = new ConptyConnection(); conn.Initialize(settings); // Wire up output conn.TerminalOutput += (chars) => Console.Write(new string(chars)); conn.StateChanged += (sender, _) => Console.Error.WriteLine($"State: {((ITerminalConnection)sender).State}"); conn.Start(); // Resize after the user resizes the window conn.Resize(rows: 40, columns: 160); // Send a command conn.WriteInput("\r".ToCharArray()); // enter key // Graceful shutdown conn.Close(); ulong rootPid = conn.RootProcessHandle(); ``` ``` -------------------------------- ### Start Debug ETL Trace with WPR Source: https://github.com/microsoft/terminal/wiki/Troubleshooting-Tips Use this command to start capturing a general profile and a verbose debug trace for Terminal. Ensure the Terminal.wprp file is in the specified path. ```cmd wpr -start GeneralProfile -start C:\path\to\Terminal.wprp!DefTerm.Verbose ``` -------------------------------- ### Global Summon Keybinding Example Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ Demonstrates how to configure a global summon action within the actions array of the settings. This allows multiple keybindings to trigger specific summon commands. ```json { "keys": "ctrl+c", "command": { "action": "globalSummon", "monitor": 1 } } ``` -------------------------------- ### Initialize XAML Islands in Test Setup Source: https://github.com/microsoft/terminal/blob/main/doc/cascadia/Unittesting-CppWinRT-Xaml.md Initialize the XAML Islands environment and create a DesktopWindowXamlSource within your test class setup method. This ensures a single instance is reused across tests. ```cpp class TabTests { TEST_CLASS_SETUP(ClassSetup) { winrt::init_apartment(winrt::apartment_type::single_threaded); // Initialize the Xaml Hosting Manager _manager = winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread(); _source = winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource{}; return true; } private: winrt::Windows::UI::Xaml::Hosting::WindowsXamlManager _manager{ nullptr }; winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource _source{ nullptr }; }; ``` -------------------------------- ### wt.exe Process Hierarchy Example Source: https://github.com/microsoft/terminal/blob/main/doc/specs/drafts/ Illustrates the proposed process tree structure for Microsoft Terminal with tab tearoff enabled, showing different modes of wt.exe and their relationship with conhost.exe and client applications. ```text wt.exe - Manager Mode |- wt.exe - Frame Host Mode | |- wt.exe - Tab Host Mode | | |- conhost.exe - ConPTY mode | | |- pwsh.exe - Client application | |- wt.exe - Tab Host Mode | |- conhost.exe - ConPTY mode | |- cmd.exe - Client application |- wt.exe - Frame Host Mode |- wt.exe - Tab Host Mode |- conhost.exe - ConPTY mode |- pwsh.exe - Client application ``` -------------------------------- ### Install Windows Terminal via GitHub Release Source: https://github.com/microsoft/terminal/blob/main/README.md Use this PowerShell command to install the Windows Terminal from a downloaded .msixbundle file. Ensure you are using PowerShell 7+ and import the Appx module if necessary. ```powershell # NOTE: If you are using PowerShell 7+, please run # Import-Module Appx -UseWindowsPowerShell # before using Add-AppxPackage. Add-AppxPackage Microsoft.WindowsTerminal_.msixbundle ``` -------------------------------- ### Quake Mode Action Example Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ This JSON configuration demonstrates the 'quakeMode' action, which is a specialized version of 'globalSummon' to invoke the quake window in the current location with specific settings for monitor, desktop, window, visibility toggle, and dropdown duration. ```json { "monitor": "toCurrent", "desktop": "toCurrent", "window": "_quake", "toggleVisibility": true, "dropdownDuration": 0.5 } ``` -------------------------------- ### Install Windows Terminal via winget Source: https://github.com/microsoft/terminal/blob/main/README.md Install the latest stable release of Windows Terminal using the Windows Package Manager CLI (winget). Ensure your winget client is version 1.6.2631 or later for dependency support. ```powershell winget install --id Microsoft.WindowsTerminal -e ``` -------------------------------- ### Set up TAEF Development Environment Source: https://github.com/microsoft/terminal/blob/main/doc/TAEF.md Before running TAEF tests, set up the development environment using this command. This makes the te.exe runner available via the %TAEF% alias. ```shell .\tools\razzle.cmd ``` -------------------------------- ### Open Settings UI with Minimal Target Argument Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ Use the `target` argument to specify opening the general Settings UI. ```json "command": { "action": "openSettings", "target": "settingsUI" } ``` -------------------------------- ### Example of 'exit' command in cmd.exe with non-zero exit code Source: https://github.com/microsoft/terminal/wiki/Frequently-Asked-Questions-(FAQ) This example demonstrates how typing 'exit' in cmd.exe after a command failure (like 'foo' not being recognized) will display the exit code of the previously failed command, which is then caught and displayed by Windows Terminal. ```cmd > foo 'foo' is not recognized as an internal or external command, operable program or batch file. > exit [process exited with code 9009] ``` -------------------------------- ### Recommended build and test workflow Source: https://github.com/microsoft/terminal/blob/main/tools/README.md This sequence of commands ensures code is built, tests are run, and formatting is applied before creating a pull request. It involves building the project, launching the console, running tests, and finally formatting the code. ```bash bcz dbg && runut /name:** ``` ```bash bcz dbg && runut ``` ```bash bcz opencon testcon runformat ``` -------------------------------- ### Console State Retrieval and Modification Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ APIs for getting the current console state and applying changes. ```APIDOC ## GetInfo ### Description Retrieves a snapshot of the terminal and buffer state. The returned pointer must remain valid until the next `GetInfo()` or `Unlock()` call, or until the active buffer is released. The returned structure does not need to be constantly updated but can be. ### Method const CONSRV_INFO* GetInfo(); ## SetInfo ### Description Applies non-null members of a `CONSRV_INFO_CHANGE` struct to the active buffer. This can include changes to cursor position, buffer size, and other console attributes. ### Method HRESULT SetInfo([in] const CONSRV_INFO_CHANGE* info); ``` -------------------------------- ### Display Help Text Source: https://github.com/microsoft/terminal/blob/main/doc/specs/ Access the help documentation using various flags like `--help`, `-h`, `-?`, or `/`. ```sh wt help wt --help wt -h wt -? wt /? ``` -------------------------------- ### Binplace Manifest and Dependencies Source: https://github.com/microsoft/terminal/blob/main/doc/cascadia/Unittesting-CppWinRT-Xaml.md Use a PostBuildEvent to copy the manifest and necessary DLL dependencies to the output directory. This ensures TAEF can locate them at runtime. ```xml (xcopy /Y "$(OpenConsoleDir)src\cascadia\ut_app\TerminalApp.Unit.Tests.manifest" "$(OutDir)\TerminalApp.Unit.Tests.manifest*" ) ``` ```xml echo OutDir=$(OutDir) (xcopy /Y "$(SolutionDir)src\cascadia\ut_app\TerminalApp.Unit.Tests.manifest" "$(OutDir)\TerminalApp.Unit.Tests.manifest*" ) (xcopy /Y "$(OpenConsoleCommonOutDir)\TerminalConnection\TerminalConnection.dll" "$(OutDir)\TerminalConnection.dll*" ) (xcopy /Y "$(OpenConsoleCommonOutDir)\TerminalSettings\TerminalSettings.dll" "$(OutDir)\TerminalSettings.dll*" ) (xcopy /Y "$(OpenConsoleCommonOutDir)\TerminalControl\TerminalControl.dll" "$(OutDir)\TerminalControl.dll*" ) ```