Repository navigation
Description
ESC ] aka OSC (operation system control) sequences are used in terminals to control things like the terminal window, or insert hyperlinks.
From wikipedia:
Starts a control string for the operating system to use, terminated by ST.[14]:8.3.89 In xterm, they may also be terminated by BEL.[15] In xterm, the window title can be set by
OSC 0;this is the window title BEL.
The sequence is followed by plain characters and terminated by ST/BEL. The plain characters are not shown to the user, they are interpreted by the terminal, therefor they should not be considered for line wrapping or truncation, but PowerShell does so.
This affects values in table format, group headers, etc.
Steps to reproduce
Run this a PowerShell terminal:
@{ test = "`e]8;;https://github.com/PowerShell/PowerShell#this_is_a_very_long_link_to_show_the_problem_with_osc_sequences`aThis is the link text which should not be truncated`e]8;;`a" }The OSC sequence used here as an example creates a hyperlink (works in iTerm2 and Gnome terminal, and will only show the link text in terminals without support).
Expected behavior
Output (make sure the resize the terminal so that the text should fit on the screen):
Name Value
---- -----
test This is the link text which should not be truncated
Actual behavior
Text gets truncated:
Name Value
---- -----
test This is the link text wh...
The amount of text truncated depends on the terminal size of course, but the point is it should not get truncated at all if it fits on the screen.
If you use a string without an OSC sequence, it will not get wrapped:
@{ test = "This is the link text which should not be truncated" }What's worst is that through truncation PowerShell can cut off the escape sequence terminator, making the sequence apply to all following terminal output (e.g. everything becomes the hyperlink).
This affects values in tables as shown, but also group headers:
github.com/sourcegraph/sourcegraph-classic > app/node_modules/jest-cli/node_modu
les/optimist/example/usage-options.js
Line Preview
---- -------
18 console.log('\n\nInspecting options');
github.com/sourcegraph/sourcegraph-classic > app/node_modules/jsfmt/node_m
odules/docopt/examples/any_options_example.coffee
Line Preview
---- -------
1 doc = """Example of program which uses [options] shortcut in pattern.
4 any_options_example.coffee [options
6 Options:
Note the wrongly wrapped the group headers (the links are also broken because of this).
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.4
PSEdition Core
GitCommitId v6.0.4
OS Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Activity
felixfbecker commentedon Sep 10, 2018
Ilya (@iSazonov) why is this
Issue-Discussionand notIssue-Bug?iSazonov commentedon Sep 10, 2018
Felix Becker (@felixfbecker) I don't see the problem on Windows. On WSL a console is frozen. I haven't MacOs to test.
We need more info. I don't know if the issue related with escapes.
felixfbecker commentedon Sep 10, 2018
I would bet the issue also happens in Linux, did you try a VM? I am almost certain it's caused by the escapes, because the point where truncation occurs is in direct relation to how long the link text inside the escape sequence is.
Builds are run on macOS/Linux, right? If there are unit tests for the truncation behaviour, maybe it would be possible to write a failing test?
iSazonov commentedon Sep 10, 2018
Rob Holt (@rjmholt) Have you time to look the Issue on Linux/MacOs? Does escapes really affect?
mklement0 commentedon Sep 12, 2018
While I haven't dug deep, there is definitely something going on with respect to escape sequences, and it affects all platforms:
The above the string
greenin green, as expected, on Windows, macOS, Linux (Ubuntu).That is, the length of the string is correctly recognized as 5, despite the presence of the escape sequences, which are seemingly ignored in this case.
Things go awry if you force truncation, however, simply by lowering the width to 4:
This should render
"g...", and that's what it does without escape sequences, but with them present what is rendered is the equivalent of"`e..."- i.e., the very first character in the string is blindly used, without regard to whether it is part of an escape sequence or not.How that renders depends on the platform / terminal application, but it's definitely broken.
Because the partial escape sequence doesn't succeed in changing the color in this case, there are no aftereffects, but, as in Felix Becker (@felixfbecker)'s example, if a complete start escape sequence happens to be rendered, but not its complementary end sequence, effects, such as color changes, linger - and solving that problem generically sounds nontrivial.
For instance, the following will print
gr...in green and persistently switch to green output, because the sequence that turns green off,e[m, is not sent to the terminal:rkeithhill commentedon Sep 12, 2018
I don't think the following is a valid terminating seq:
Try using:
mklement0 commentedon Sep 12, 2018
Keith Hill (@rkeithhill): The
0is optional; try the following (on any supported platform):"before `e[32mgreen`e[m after"rkeithhill commentedon Sep 12, 2018
Yeah, now I see the line in the docs that I missed:
Good to know.
felixfbecker commentedon Sep 12, 2018
Yeah, truncated text including opening escapes but possibly truncating the closing escapes is another problem, but I would say only loosely related to this issue.
Your experiment above seems to show that length is not a problem for color escape codes, but the issue description shows that it is a problem for OSC sequences. Perhaps PowerShell recognizes and filters ESC[ sequences (which are terminated with m), but not ESC]8 sequences (which are terminated with ST/BEL).
mklement0 commentedon Sep 12, 2018
Good point about the distinction between color codes and OSC sequences, Felix Becker (@felixfbecker), and I think your guess about PowerShell not recognizing the latter is correct:
The above breaks, even though
11is exactly the length ofexample.org, and it only renders correctly with a minimum width of41, which is the raw character count of the string including escape sequences.I've opened a separate issue for the end-escape-sequence-not-getting-output problem: #7767
felixfbecker commentedon Sep 20, 2018
cc Steve Lee (@SteveL-MSFT) Travis Plunk (@TravisEz13)
53 remaining items
microsoft-github-policy-service commentedon Apr 15, 2025
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.
BalassaMarton commentedon Apr 15, 2025
Issue is still relevant.
microsoft-github-policy-service commentedon Oct 12, 2025
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.
iSazonov commentedon Oct 13, 2025
For reference #23861 (where we have idea for better Unicode and Terminal supprt.)
microsoft-github-policy-service commentedon Apr 11, 2026
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.
zaneduffield commentedon Apr 13, 2026
Bump
microsoft-github-policy-service commentedon Oct 10, 2026
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.
oising commentedon Oct 13, 2026
Hey hey