Repository: microsoft/terminal
File: src/server/ConsoleShimPolicy.cpp (C++)

Code before:
        _isCmd = clientName.compare(L"cmd.exe") == 0;

        // For powershell, we need both Windows PowersShell (powershell.exe) and
        // PowerShell Core (pwsh.exe). If PowerShell Core is ever updated to use
        // ^[[3J for Clear-Host, then it won't ever hit the shim code path, but
        // we're keeping this for the long tail of pwsh versions that still
        // _don't_ use that sequence.
        const auto isInboxPowershell = clientName.compare(L"powershell.exe") == 0;
        const auto isPwsh = clientName.compare(L"pwsh.exe") == 0;
        _isPowershell = isInboxPowershell || isPwsh;

        // Inside Windows, we are guaranteed that we're building alongside a new (good) inbox PowerShell.
        // Therefore, we can default _requiresVtColorQuirk to false.
#ifndef __INSIDE_WINDOWS
        // Outside of Windows, we need to check the OS version: PowerShell was fixed in early Iron builds.
        static auto _doesInboxPowershellVersionRequireQuirk = [] {
            OSVERSIONINFOEXW osver{};
            osver.dwOSVersionInfoSize = sizeof(osver);
            osver.dwBuildNumber = 20348; // Windows Server 2022 RTM

            DWORDLONG dwlConditionMask = 0;
            VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, VER_LESS);

            return VerifyVersionInfoW(&osver, VER_BUILDNUMBER, dwlConditionMask) != FALSE;
        }();
        _requiresVtColorQuirk = isInboxPowershell && _doesInboxPowershellVersionRequireQuirk;
        // All modern versions of pwsh.exe have been fixed, and we can direct users to update.
#endif
    }
    CATCH_LOG();
}

// Method Description:
// - Returns true if the connected client application is literally "cmd.exe". If
//   it is, we'll need to enable certain compatibility shims.
// Arguments:
// - <none>
// Return Value:
// - rue iff the process is "cmd.exe"
bool ConsoleShimPolicy::IsCmdExe() const noexcept
{
    return _isCmd;
}

// Method Description:
// - Returns true if the connected client application is literally
//   "powershell.exe" or "pwsh.exe". If it is, we'll need to enable certain
//   compatibility shims.
// Arguments:
// - <none>
// Return Value:

Review comment (suggestion):
```suggestion
        _requiresVtColorQuirk = isInboxPowershell && doesInboxPowershellVersionRequireQuirk;
```

Code after:
        // we're keeping this for the long tail of pwsh versions that still
        // _don't_ use that sequence.
        const auto isInboxPowershell = til::equals_insensitive_ascii(clientName, L"powershell.exe");
        const auto isPwsh = til::equals_insensitive_ascii(clientName, L"pwsh.exe");
        _isPowershell = isInboxPowershell || isPwsh;

        // Inside Windows, we are guaranteed that we're building alongside a new (good) inbox Powershell.
        // Therefore, we can default _requiresVtColorQuirk to false.
#ifndef __INSIDE_WINDOWS
        // Outside of Windows, we need to check the OS version: Powershell was fixed in early Iron builds.
        static auto doesInboxPowershellVersionRequireQuirk = [] {
            OSVERSIONINFOEXW osver{};
            osver.dwOSVersionInfoSize = sizeof(osver);
            osver.dwBuildNumber = 20348; // Windows Server 2022 RTM

            DWORDLONG dwlConditionMask = 0;
            VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, VER_LESS);

            return VerifyVersionInfoW(&osver, VER_BUILDNUMBER, dwlConditionMask) != FALSE;
        }();
        _requiresVtColorQuirk = isInboxPowershell && doesInboxPowershellVersionRequireQuirk;
        // All modern versions of pwsh.exe have been fixed, and we can direct users to update.
#endif
    }
    CATCH_LOG();
}

// Method Description:
// - Returns true if the connected client application is literally "cmd.exe". If
//   it is, we'll need to enable certain compatibility shims.
// Arguments:
// - <none>
// Return Value:
// - rue iff the process is "cmd.exe"
bool ConsoleShimPolicy::IsCmdExe() const noexcept
{
    return _isCmd;
}

// Method Description:
// - Returns true if the connected client application is literally
//   "powershell.exe" or "pwsh.exe". If it is, we'll need to enable certain
//   compatibility shims.
// Arguments:
// - <none>
// Return Value:
// - rue iff the process is "powershell.exe" or "pwsh.exe"
bool ConsoleShimPolicy::IsPowershellExe() const noexcept
{
    return _isPowershell;
}