Incorrect background color when copying content to the clipboard as HTML #16191

Open
opened 2026-01-31 05:00:18 +00:00 by claunia · 0 comments
Owner

Originally created by @j4james on GitHub (Dec 17, 2021).

Windows Terminal version

1.12.3472.0

Windows build number

10.0.19041.1348

Other Software

No response

Steps to reproduce

  1. Open a bash shell in Windows Terminal.
  2. Change the default palette to pink on purple using an OSC escape sequence:
    printf "\e]10;rgb:ff/88/88;rgb:88/44/88\e\\"
  3. Enable the reverse screen mode, so it changes to purple on pink:
    printf "\e[?5h"
  4. Copy some content from the window and paste somewhere that accepts HTML. You can test in a simple html file like this:
    <p contenteditable="true"></p>
  5. Repeat the same process in an OpenConsole/conhost window. You'll need a recent build for the palette and mode sequences to work, and remember to hold down Alt while copying in order for it to copy the content as HTML.

Expected Behavior

The background color of the pasted content should match the pink background that is displayed on screen.

Actual Behavior

When copying from Windows Terminal, the default background fill is black (or whatever the background was of the starting color scheme).

image

When copying from OpenConsole/conhost, the default background fill is purple, i.e. it's taking the palette change into account, but not the reverse screen mode.

image

Just looking at the code, I think the WPF control probably gets this right. It calculates the background using GetAttributeColors with a default TextAttribute instance, and then takes the second returned value (i.e. the background). That should return the actual runtime color that the renderer is using.

So my proposed fix is we do exactly the same thing in the Windows Terminal and conhost implementations.

Originally created by @j4james on GitHub (Dec 17, 2021). ### Windows Terminal version 1.12.3472.0 ### Windows build number 10.0.19041.1348 ### Other Software _No response_ ### Steps to reproduce 1. Open a bash shell in Windows Terminal. 2. Change the default palette to pink on purple using an OSC escape sequence: `printf "\e]10;rgb:ff/88/88;rgb:88/44/88\e\\"` 3. Enable the reverse screen mode, so it changes to purple on pink: `printf "\e[?5h"` 4. Copy some content from the window and paste somewhere that accepts HTML. You can test in a simple html file like this: `<p contenteditable="true"></p>` 5. Repeat the same process in an OpenConsole/conhost window. You'll need a recent build for the palette and mode sequences to work, and remember to hold down <kbd>Alt</kbd> while copying in order for it to copy the content as HTML. ### Expected Behavior The background color of the pasted content should match the pink background that is displayed on screen. ### Actual Behavior When copying from Windows Terminal, the default background fill is black (or whatever the background was of the starting color scheme). ![image](https://user-images.githubusercontent.com/4181424/146619995-5629e97a-8964-4574-b577-b237f32a329d.png) When copying from OpenConsole/conhost, the default background fill is purple, i.e. it's taking the palette change into account, but not the reverse screen mode. ![image](https://user-images.githubusercontent.com/4181424/146620071-c0452f2e-0e8d-48ea-8ae7-176abad94622.png) Just looking at the code, I think the WPF control probably gets this right. It calculates the background using `GetAttributeColors` with a default `TextAttribute` instance, and then takes the second returned value (i.e. the background). That should return the actual runtime color that the renderer is using. So my proposed fix is we do exactly the same thing in the Windows Terminal and conhost implementations.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#16191