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

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/1828
Author: @rkeithhill
Created: 7/4/2019
Status: Closed

Base: masterHead: add-term-program-envvars


📝 Commits (1)

  • e594df8 Add TERM_PROGRAM[_VERSION] env vars, partial fix #1040

📊 Changes

6 files changed (+39 additions, -1 deletions)

View changed files

📝 src/cascadia/TerminalApp/App.cpp (+18 -1)
📝 src/cascadia/TerminalApp/App.h (+1 -0)
📝 src/cascadia/TerminalApp/App.idl (+1 -0)
📝 src/cascadia/WindowsTerminal/AppHost.cpp (+11 -0)
📝 src/cascadia/WindowsTerminal/AppHost.h (+1 -0)
📝 src/cascadia/WindowsTerminal/main.cpp (+7 -0)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/1828 **Author:** [@rkeithhill](https://github.com/rkeithhill) **Created:** 7/4/2019 **Status:** ❌ Closed **Base:** `master` ← **Head:** `add-term-program-envvars` --- ### 📝 Commits (1) - [`e594df8`](https://github.com/microsoft/terminal/commit/e594df8f78b5ce0af7124ee3e976b5a8aae02045) Add TERM_PROGRAM[_VERSION] env vars, partial fix #1040 ### 📊 Changes **6 files changed** (+39 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalApp/App.cpp` (+18 -1) 📝 `src/cascadia/TerminalApp/App.h` (+1 -0) 📝 `src/cascadia/TerminalApp/App.idl` (+1 -0) 📝 `src/cascadia/WindowsTerminal/AppHost.cpp` (+11 -0) 📝 `src/cascadia/WindowsTerminal/AppHost.h` (+1 -0) 📝 `src/cascadia/WindowsTerminal/main.cpp` (+7 -0) </details> ### 📄 Description 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:04:44 +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#24678