[PR #18697] Allow users to specify a base settings path, enabling multiple local state and multi-instance scenarios. #31592

Open
opened 2026-01-31 09:48:16 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/18697

State: closed
Merged: No


Description of the new feature

Multi local state and settings and multi instance with --localstate command-line argument

Summary

Introduce a new command-line option -L or --localstate to allow users to specify a custom local state directory for Windows Terminal, enabling multiple local states, settings and multi-instance scenarios.

Enhancements:

  • Modify command-line argument parsing to support the new local state option
  • Update environment variable handling to use the new local state path

Proposed technical implementation details

Reviewer Guide

Introducing the ability to run multiple instances of Windows Terminal with separate settings and state by using the --localstate command-line argument. Modify parsing to support the new local state option. The changes modify the settings path retrieval logic and window class name generation to incorporate the environment variable, allowing for isolated settings for each instance.

This pull request adds support for a new command-line argument -L or --localstate to allow users to specify a custom local state directory for Windows Terminal. The implementation involves modifying command-line argument parsing, updating environment variable handling, and updating file utilities to use the new local state path.

Sequence diagram for handling the new localstate argument

sequenceDiagram
    participant User
    participant Command Line
    participant AppCommandlineArgs
    participant WindowEmperor
    participant FileUtils

    User->>Command Line: wt --localstate <path>
    Command Line->>AppCommandlineArgs: Parse arguments
    AppCommandlineArgs->>AppCommandlineArgs: Store local state path
    AppCommandlineArgs->>WindowEmperor: Launch Terminal
    WindowEmperor->>WindowEmperor: Handle Commandline Args
    WindowEmperor->>AppCommandlineArgs: Get Local State
    WindowEmperor->>FileUtils: Set ENV_WT_BASE_SETTINGS_PATH to local state path
    FileUtils->>FileUtils: Create directories at local state path

Updated class diagram for AppCommandlineArgs

classDiagram
  class AppCommandlineArgs {
    -std::wregex _commandDelimiterRegex
    -std::vector<std::wstring> _args
    -bool _hasParseError
    -bool _shouldExitEarly
    -bool _isHandoffListener
    -int _loadPersistedLayoutIdx
    -std::string _windowTarget
    -std::string _localState
    +FullResetState()
    +GetTargetWindow() string_view
    +GetLocalState() string_view
    -_getNewTerminalArgs(NewTerminalSubcommand& subcommand) NewTerminalArgs
  }

File-Level Changes

Change Details Files
Introduced a new command-line argument -L or --localstate to allow users to specify a custom local state directory for Windows Terminal.
  • Added _localState field to AppCommandlineArgs class to store the local state path.
  • Added -L,--localstate option to the command-line argument parser.
  • Implemented GetLocalState() method in AppCommandlineArgs to retrieve the local state path.
  • Added LocalState() property to the CommandlineArgs class in Remoting.idl and implemented it in Remoting.cpp.
  • Modified WindowEmperor::HandleCommandlineArgs to retrieve the settings path from the command line arguments.
  • Updated FileUtils::GetBaseSettingsPath to retrieve the settings path from the environment variables.
src/cascadia/WindowsTerminal/WindowEmperor.cpp
src/cascadia/TerminalSettingsModel/FileUtils.cpp
src/cascadia/TerminalApp/AppCommandlineArgs.cpp
src/cascadia/TerminalApp/Remoting.cpp
src/cascadia/TerminalApp/AppCommandlineArgs.h
src/cascadia/TerminalApp/Remoting.h
src/cascadia/CascadiaPackage/Package-Dev.appxmanifest
src/cascadia/TerminalApp/Remoting.idl
src/cascadia/TerminalApp/Resources/en-US/Resources.resw

PR Checklist

Motivation

I created Windows Terminal Layout Manager application. Which is an advanced yet user-friendly application designed to simplify and streamline the management of your Windows Terminal sessions. Effortlessly save, restore, and dynamically manage multiple terminal layouts and settings, ensuring a smooth and consistent workflow.
WTLayoutManager

Image

Image

**Original Pull Request:** https://github.com/microsoft/terminal/pull/18697 **State:** closed **Merged:** No --- ### Description of the new feature Multi local state and settings and multi instance with `--localstate` command-line argument ## Summary Introduce a new command-line option `-L` or `--localstate` to allow users to specify a custom local state directory for Windows Terminal, enabling multiple local states, settings and multi-instance scenarios. Enhancements: - Modify command-line argument parsing to support the new local state option - Update environment variable handling to use the new local state path ### Proposed technical implementation details ## Reviewer Guide Introducing the ability to run multiple instances of Windows Terminal with separate settings and state by using the `--localstate` command-line argument. Modify parsing to support the new local state option. The changes modify the settings path retrieval logic and window class name generation to incorporate the environment variable, allowing for isolated settings for each instance. This pull request adds support for a new command-line argument `-L` or `--localstate` to allow users to specify a custom local state directory for Windows Terminal. The implementation involves modifying command-line argument parsing, updating environment variable handling, and updating file utilities to use the new local state path. #### Sequence diagram for handling the new localstate argument ```mermaid sequenceDiagram participant User participant Command Line participant AppCommandlineArgs participant WindowEmperor participant FileUtils User->>Command Line: wt --localstate <path> Command Line->>AppCommandlineArgs: Parse arguments AppCommandlineArgs->>AppCommandlineArgs: Store local state path AppCommandlineArgs->>WindowEmperor: Launch Terminal WindowEmperor->>WindowEmperor: Handle Commandline Args WindowEmperor->>AppCommandlineArgs: Get Local State WindowEmperor->>FileUtils: Set ENV_WT_BASE_SETTINGS_PATH to local state path FileUtils->>FileUtils: Create directories at local state path ``` #### Updated class diagram for AppCommandlineArgs ```mermaid classDiagram class AppCommandlineArgs { -std::wregex _commandDelimiterRegex -std::vector<std::wstring> _args -bool _hasParseError -bool _shouldExitEarly -bool _isHandoffListener -int _loadPersistedLayoutIdx -std::string _windowTarget -std::string _localState +FullResetState() +GetTargetWindow() string_view +GetLocalState() string_view -_getNewTerminalArgs(NewTerminalSubcommand& subcommand) NewTerminalArgs } ``` ### File-Level Changes | Change | Details | Files | | ------ | ------- | ----- | | Introduced a new command-line argument `-L` or `--localstate` to allow users to specify a custom local state directory for Windows Terminal. | <ul><li>Added `_localState` field to `AppCommandlineArgs` class to store the local state path.</li><li>Added `-L,--localstate` option to the command-line argument parser.</li><li>Implemented `GetLocalState()` method in `AppCommandlineArgs` to retrieve the local state path.</li><li>Added `LocalState()` property to the `CommandlineArgs` class in `Remoting.idl` and implemented it in `Remoting.cpp`.</li><li>Modified `WindowEmperor::HandleCommandlineArgs` to retrieve the settings path from the command line arguments.</li><li>Updated `FileUtils::GetBaseSettingsPath` to retrieve the settings path from the environment variables.</li></ul> | `src/cascadia/WindowsTerminal/WindowEmperor.cpp`<br/>`src/cascadia/TerminalSettingsModel/FileUtils.cpp`<br/>`src/cascadia/TerminalApp/AppCommandlineArgs.cpp`<br/>`src/cascadia/TerminalApp/Remoting.cpp`<br/>`src/cascadia/TerminalApp/AppCommandlineArgs.h`<br/>`src/cascadia/TerminalApp/Remoting.h`<br/>`src/cascadia/CascadiaPackage/Package-Dev.appxmanifest`<br/>`src/cascadia/TerminalApp/Remoting.idl`<br/>`src/cascadia/TerminalApp/Resources/en-US/Resources.resw` | --- ## PR Checklist - [x] Closes #18696 - [x] New feature ## Motivation I created Windows Terminal Layout Manager application. Which is an advanced yet user-friendly application designed to simplify and streamline the management of your Windows Terminal sessions. Effortlessly save, restore, and dynamically manage multiple terminal layouts and settings, ensuring a smooth and consistent workflow. [WTLayoutManager](https://github.com/dmitrykok/WTLayoutManager) ![Image](https://github.com/user-attachments/assets/944ca59c-75be-4b5e-8df9-af04b4a23ced) ![Image](https://github.com/user-attachments/assets/94b9b7ca-49a8-4dc4-83d8-0d28ce0f775b)
claunia added the pull-request label 2026-01-31 09:48:16 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31592