Need an API to set TabColor #19547

Closed
opened 2026-01-31 06:46:51 +00:00 by claunia · 8 comments
Owner

Originally created by @BobFrankston on GitHub (Mar 16, 2023).

Description of the new feature/enhancement

There is an API to set the window title (ui.RawUI.WindowTitle). There should be a way to set the TabColor programmatically. It can be done with WT but only when spawning a new window.

Proposed technical implementation details (optional)

I presume the underlying mechanisms are there, but it just lacks an API akin to that for WindowTitle.

Originally created by @BobFrankston on GitHub (Mar 16, 2023). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement There is an API to set the window title (ui.RawUI.WindowTitle). There should be a way to set the TabColor programmatically. It can be done with WT but only when spawning a new window. <!-- --> # Proposed technical implementation details (optional) I presume the underlying mechanisms are there, but it just lacks an API akin to that for WindowTitle. <!-- -->
claunia added the Issue-FeatureNeeds-TriageResolution-ExternalNeeds-Tag-Fix labels 2026-01-31 06:46:51 +00:00
Author
Owner

@lhecker commented on GitHub (Mar 16, 2023):

I believe this is a duplicate of #14910. You can try it out by running the command mentioned here in PowerShell: https://github.com/microsoft/terminal/discussions/14903#discussioncomment-5104434

@lhecker commented on GitHub (Mar 16, 2023): I believe this is a duplicate of #14910. You can try it out by running the command mentioned here in PowerShell: https://github.com/microsoft/terminal/discussions/14903#discussioncomment-5104434
Author
Owner

@BobFrankston commented on GitHub (Mar 17, 2023):

Thanks. I'd close this, but it would still be nice to have it in the API to be uniform.

@BobFrankston commented on GitHub (Mar 17, 2023): Thanks. I'd close this, but it would still be nice to have it in the API to be uniform.
Author
Owner

@lhecker commented on GitHub (Mar 17, 2023):

I'm assuming you still mean PowerShell's PSHostRawUserInterface right? In that case, I believe this needs to be filed as a feature request at https://github.com/PowerShell/PowerShell. This project concerns itself only with the Console API, as well as conhost.exe (the old Windows "console") and Windows Terminal. In fact, if we wanted to have such a feature in PowerShell, we'd have to file such an issue as well. 😅

@lhecker commented on GitHub (Mar 17, 2023): I'm assuming you still mean PowerShell's `PSHostRawUserInterface` right? In that case, I believe this needs to be filed as a feature request at https://github.com/PowerShell/PowerShell. This project concerns itself only with the [Console API](https://learn.microsoft.com/en-us/windows/console/console-functions), as well as `conhost.exe` (the old Windows "console") and Windows Terminal. In fact, if we wanted to have such a feature in PowerShell, we'd have to file such an issue as well. 😅
Author
Owner

@BobFrankston commented on GitHub (Mar 17, 2023):

I want to make sure we're using the same terms.

There is an ambiguity between PowerShell as a console and PowerShell as a programming language. I have .ps1 files associated with pwsh, so I can run them in a cmd window in Windows Terminal. And it works fine to set the title. But the escape sequences only work in a PowerShell tab but not a cmd tab.

I want to make sure I properly understand this.

$host.ui.RawUI.WindowTitle = "hello"

seems to be associated with conhost since it works for any tab, whereas the escape sequence only works for a PowerShell tab.

So this is indeed a conhost request though I just happen to be using pwsh rather than a BAT file.

@BobFrankston commented on GitHub (Mar 17, 2023): I want to make sure we're using the same terms. There is an ambiguity between PowerShell as a console and PowerShell as a programming language. I have .ps1 files associated with pwsh, so I can run them in a cmd window in Windows Terminal. And it works fine to set the title. But the escape sequences only work in a PowerShell tab but not a cmd tab. I want to make sure I properly understand this. $host.ui.RawUI.WindowTitle = "hello" seems to be associated with conhost since it works for any tab, whereas the escape sequence only works for a PowerShell tab. So this is indeed a conhost request though I just happen to be using pwsh rather than a BAT file.
Author
Owner

@j4james commented on GitHub (Mar 19, 2023):

@BobFrankston Those escape sequences will work from any shell in Windows Terminal, but it's a little more complicated in a cmd shell or BAT file because it's not as easy to get an ESC character. From the cmd prompt you would need to type Ctrl+[ to generate ESC. You also need to be aware that the | character is reserved, so that has to be prefixed with ^|.

As a complete example, you can set the tab to white on red as follows:

  1. Type echo
  2. Press Ctrl+[
  3. Type [2;15;1,^|
  4. Press Return

What you should see at the prompt would be something like this:

image

To achieve the same thing with a BAT file, you'd need a way to get the ESC character into the file, which you can do like this:

  1. Type echo
  2. Press Ctrl+[
  3. Type > tabcolor.bat
  4. Press Return

At that point, if you edit the tabcolor.bat file in something like notepad, you'll see a glyph which is the ESC. If you prefix that with echo and add [2;15;1,^| on the end, you'll have a BAT file that sets the tab color.

@j4james commented on GitHub (Mar 19, 2023): @BobFrankston Those escape sequences will work from any shell in Windows Terminal, but it's a little more complicated in a cmd shell or BAT file because it's not as easy to get an `ESC` character. From the cmd prompt you would need to type <kbd>Ctrl</kbd>+<kbd>[</kbd> to generate `ESC`. You also need to be aware that the `|` character is reserved, so that has to be prefixed with `^|`. As a complete example, you can set the tab to white on red as follows: 1. Type `echo ` 2. Press <kbd>Ctrl</kbd>+<kbd>[</kbd> 3. Type `[2;15;1,^|` 4. Press <kbd>Return</kbd> What you should see at the prompt would be something like this: ![image](https://user-images.githubusercontent.com/4181424/226213915-a233a487-6c46-45b6-b95f-28d7ed4b59b2.png) To achieve the same thing with a BAT file, you'd need a way to get the `ESC` character into the file, which you can do like this: 1. Type `echo ` 2. Press <kbd>Ctrl</kbd>+<kbd>[</kbd> 3. Type `> tabcolor.bat` 4. Press <kbd>Return</kbd> At that point, if you edit the `tabcolor.bat` file in something like notepad, you'll see a `◻` glyph which is the `ESC`. If you prefix that with `echo ` and add `[2;15;1,^|` on the end, you'll have a BAT file that sets the tab color.
Author
Owner

@BobFrankston commented on GitHub (Mar 19, 2023):

You're right -- don't know why my earlier tests were off, but this works in Typescript.

 console.log("\x1b[2;5;82,|");

and pwsh

echo "$([char]27)[2;15;6,|"

One thing that made the bat file example a challenge is that it is not at all obvious that ^[ meant control -- even though I've used that notation for half a century (no exaggeration - the early days of Emacs). And ^| is not control? The other complicating factor is a plethora of examples that didn't seem consistent.

So, please, is there a URL to the documentation on this?

The RGB examples in https://github.com/microsoft/terminal/discussions/14903 don't seem to work.

@BobFrankston commented on GitHub (Mar 19, 2023): You're right -- don't know why my earlier tests were off, but this works in Typescript. ``` console.log("\x1b[2;5;82,|"); ``` and pwsh ``` echo "$([char]27)[2;15;6,|" ``` One thing that made the bat file example a challenge is that it is not at all obvious that ^[ meant control -- even though I've used that notation for half a century (no exaggeration - the early days of Emacs). And ^| is not control? The other complicating factor is a plethora of examples that didn't seem consistent. ### **So, please, is there a URL to the documentation on this?** The RGB examples in https://github.com/microsoft/terminal/discussions/14903 don't seem to work.
Author
Owner

@j4james commented on GitHub (Mar 20, 2023):

And ^| is not control?

No. Visually it may look the same as a control character, but it's two separate characters: ^ and |.

So, please, is there a URL to the documentation on this?

If you meant the ^ escaping syntax for the cmd shell, I found some old documentation on the subject here. Search for carat to find the relevant section.

If you mean the escape sequences for changing the tab color, they aren't covered in the Windows Terminal documentation yet. But DECAC and DECCTR are standard DEC sequences which you can find documented in the DEC VT520 manual (see here and here). And OSC 4 is an XTerm sequence which you can find documented here. The only thing specific to the Windows Terminal implementation is the assignment of palette entries 263 and 264 to the tab colors.

The RGB examples in https://github.com/microsoft/terminal/discussions/14903 don't seem to work.

If you've been using the DECAC sequence to change the tab color, make sure that you've set that back to the default values (with echo "`e[2;263;264,|"), before attempting the RGB examples. Alternatively you could just open a new terminal tab first.

@j4james commented on GitHub (Mar 20, 2023): > And ^| is not control? No. Visually it may look the same as a control character, but it's two separate characters: `^` and `|`. > So, please, is there a URL to the documentation on this? If you meant the `^` escaping syntax for the cmd shell, I found some old documentation on the subject [here](https://learn.microsoft.com/en-us/previous-versions//cc723564(v=technet.10)). Search for `carat` to find the relevant section. If you mean the escape sequences for changing the tab color, they aren't covered in the Windows Terminal documentation yet. But `DECAC` and `DECCTR` are standard DEC sequences which you can find documented in the DEC VT520 manual (see [here](https://www.manualslib.com/manual/1200903/Digital-Equipment-Vt520.html?page=170) and [here](https://www.manualslib.com/manual/1200903/Digital-Equipment-Vt520.html?page=272)). And `OSC 4` is an XTerm sequence which you can find documented [here](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Operating-System-Commands:OSC-Ps;Pt-ST:Ps-=-4;c;spec.123F). The only thing specific to the Windows Terminal implementation is the assignment of palette entries 263 and 264 to the tab colors. > The RGB examples in https://github.com/microsoft/terminal/discussions/14903 don't seem to work. If you've been using the `DECAC` sequence to change the tab color, make sure that you've set that back to the default values (with ``echo "`e[2;263;264,|"``), before attempting the RGB examples. Alternatively you could just open a new terminal tab first.
Author
Owner

@BobFrankston commented on GitHub (Mar 20, 2023):

Thanks.

I understand I should wait, but one problem with software is the incremental reward of figuring out each puzzle.

I don't think I need to tell you about all the ambiguities in the examples and [2 vs ]4 vs. ... and all those color indexes.

So I'll wait till I can find simple documentation for using RGB values for the foreground, background, tabs etc.

@BobFrankston commented on GitHub (Mar 20, 2023): Thanks. I understand I should wait, but one problem with software is the incremental reward of figuring out each puzzle. I don't think I need to tell you about all the ambiguities in the examples and [2 vs ]4 vs. ... and all those color indexes. So I'll wait till I can find simple documentation for using RGB values for the foreground, background, tabs etc.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19547