[PR #1828] Add TERM_PROGRAM[_VERSION] env vars, partial fix #1040 #24683

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

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

State: closed
Merged: No


Fix potential loss of data warning, size_t to int.

Summary of the Pull Request

Create the following environment variables for every conhost app spawned:

TERM_PROGRAM                   WindowsTerminal
TERM_PROGRAM_VERSION           0.0.1.0

This allows shell, shell scripts, PowerShell modules and console applications to determine if they need to tweak the console environment. For example, in the posh-git module we actually mess with low-level console mode settings for old versions of PowerShell.

a64e5e073f/src/ConsoleMode.ps1 (L3-L4)

Even for an old version (v5) of Windows PowerShell, if it's running in Windows Terminal, we probably do not need to call SetConsoleMode() to set the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag. I'd like to change that test above to also not mess with the console mode if $env:TERM_PROGRAM is defined.

References

Partially addresses #1040

PR Checklist

  • Closes #xxx
  • [x ] CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be updated
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

Detailed Description of the Pull Request / Additional comments

I "think" the right place to set these env vars is early on in the WindowsTerminal main() entry point. I wasn't able to access the package version number directly from that project. So I expose it from the TerminalApp project's App class. That is then in turn exposed by the WindowsTerminal AppHost class. I'm completely open to a better way to get the package version. Or if the env vars should be set in another project - like the headless conhost.

Validation Steps Performed

Start WindowsTerminal and checked for the existence of these two env vars in powershell.exe, pwsh.exe and cmd.exe.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/1828 **State:** closed **Merged:** No --- Fix potential loss of data warning, size_t to int. <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Create the following environment variables for every conhost app spawned: ``` TERM_PROGRAM WindowsTerminal TERM_PROGRAM_VERSION 0.0.1.0 ``` This allows shell, shell scripts, PowerShell modules and console applications to determine if they need to tweak the console environment. For example, in the `posh-git` module we actually mess with low-level console mode settings for old versions of PowerShell. https://github.com/dahlbyk/posh-git/blob/a64e5e073f6ce4dcd01394965bf0bbc91a0e3016/src/ConsoleMode.ps1#L3-L4 Even for an old version (v5) of Windows PowerShell, if it's running in Windows Terminal, we probably do not need to call `SetConsoleMode()` to set the `ENABLE_VIRTUAL_TERMINAL_PROCESSING` flag. I'd like to change that test above to also not mess with the console mode if `$env:TERM_PROGRAM` is defined. <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References Partially addresses #1040 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [ ] Closes #xxx * [x ] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [x] Requires documentation to be updated * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments I "think" the right place to set these env vars is early on in the WindowsTerminal `main()` entry point. I wasn't able to access the package version number directly from that project. So I expose it from the `TerminalApp` project's `App` class. That is then in turn exposed by the WindowsTerminal `AppHost` class. I'm completely open to a better way to get the package version. Or if the env vars should be set in another project - like the headless conhost. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Start WindowsTerminal and checked for the existence of these two env vars in powershell.exe, pwsh.exe and cmd.exe.
claunia added the pull-request label 2026-01-31 09:04:45 +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#24683