Skip to content

Fix PS2 and backslash continuation#1672

Merged
Anteru merged 3 commits intopygments:masterfrom
mathiasertl:master
Jan 30, 2021
Merged

Fix PS2 and backslash continuation#1672
Anteru merged 3 commits intopygments:masterfrom
mathiasertl:master

Conversation

@mathiasertl
Copy link
Copy Markdown
Contributor

Fix backslash continuation and set PS2 to include a space (so > instead of >), which is the default for most (all) shells. Currently, lines that end with a backslash are always rendered verbatim, effectively breaking any actual examples that want to show the PS2 prompt correctly. Using a common bash session, this is how you would split a command into multiple lines:

$ ls --many options \
> /some/location

... where both $ and > would be the prompt (configured by the PS1 and PS2 environment variables). So naturally, we want these tokens to be shown as prompt (and also not be copy-able).

Current test cases also do not reflect this behavior. For example, the test_newline_in_echo has a fragment of '$ echo \\\nhi\nhi\n', which would be impossible to actually create (unless PS2 where configured to an empty string), as a user typing echo \<enter> would imediately get a > in the next line.

As an example, here is how this renders without the patch. Note how this is actually inverted: The > from the certbot command is not detected as a prompt (even though it actually it is), while for the echo command output is detected as a prompt, even though it actually it isn't:

without-patch

Now with the patch... it's actually correct:

with-patch

@Anteru Anteru merged commit a186efe into pygments:master Jan 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants