Window line-wrapping can cause colored output to break copied text #20667

Open
opened 2026-01-31 07:20:40 +00:00 by claunia · 0 comments
Owner

Originally created by @lindhe on GitHub (Oct 13, 2023).

Windows Terminal version

1.17.11461.0

Windows build number

10.0.22621.0

Other Software

bat 0.19.0

Steps to reproduce

I have found this very specific scenario for reproducing the issue reliably:

  1. Install bat.

  2. Create EXAMPLE.md with the following contents (including the markdown code fence, because we want syntax highlighting to color the output):

    ```shell
    echo '1 22 333 4444 55555 666666 7777777 88888888 999999999 0000000000 1 22 333 4444 55555 666666 7777777 88888888 999999999 0000000000'
    ```
    
  3. Resize the terminal to be narrower than that long echo line.

  4. Run the following:

    /usr/bin/batcat --color=always --style=header --decorations=always EXAMPLE.md
    
  5. Copy the output.

  6. Paste the output in a wider window.

It's worth noting that it works fine (i.e. "as expected") if the window is wide enough to not wrap when the command is run. If I resize the window later, the problem is not there.

Something that really surprises me is that piping the output via cat fixes the issue while looking exactly the same visually:

image

This bug is very similar to, or actually the same as, #5113.

Expected Behavior

For clarity, I think we need to distinguish between the line breaks introduced by Windows Terminal for the purposes of displaying a long line in a wrapped format and the line breaks that are part of the original string. I will call them wrapping line breaks and string line breaks respectively.

When copying a string from the terminal, I expect to copy the string line breaks but not the wrapping line breaks, so that when I paste it I get the "original" string (not the one with line wrappings).

Actual Behavior

When I copy text under these circumstances, it keeps the wrapping line breaks as well as he string line breaks.

Originally created by @lindhe on GitHub (Oct 13, 2023). ### Windows Terminal version 1.17.11461.0 ### Windows build number 10.0.22621.0 ### Other Software bat 0.19.0 ### Steps to reproduce I have found this very specific scenario for reproducing the issue reliably: 1. Install [bat](https://github.com/sharkdp/bat). 1. Create `EXAMPLE.md` with the following contents (_including_ the markdown code fence, because we want syntax highlighting to color the output): ~~~ ```shell echo '1 22 333 4444 55555 666666 7777777 88888888 999999999 0000000000 1 22 333 4444 55555 666666 7777777 88888888 999999999 0000000000' ``` ~~~ 1. Resize the terminal to be narrower than that long `echo` line. 1. Run the following: ```shell /usr/bin/batcat --color=always --style=header --decorations=always EXAMPLE.md ``` 1. Copy the output. 1. Paste the output in a wider window. It's worth noting that it works fine (i.e. "as expected") if the window is wide enough to not wrap when the command is run. If I resize the window later, the problem is not there. Something that _really_ surprises me is that piping the output via `cat` fixes the issue while looking exactly the same visually: ![image](https://github.com/microsoft/terminal/assets/7773090/49dd15a7-294a-4942-bbed-8af03063185c) This bug is very similar to, or actually the same as, #5113. ### Expected Behavior For clarity, I think we need to distinguish between the line breaks introduced by Windows Terminal for the purposes of displaying a long line in a wrapped format and the line breaks that are part of the original string. I will call them _wrapping line breaks_ and _string line breaks_ respectively. When copying a string from the terminal, I expect to copy the string line breaks but not the wrapping line breaks, so that when I paste it I get the "original" string (not the one with line wrappings). ### Actual Behavior When I copy text under these circumstances, it keeps the _wrapping_ line breaks as well as he string line breaks.
claunia added the Needs-TriageIssue-BugResolution-ExternalNeeds-Attention labels 2026-01-31 07:20:40 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20667