-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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