Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix breakage in output with colors disabled #2158

Merged
merged 2 commits into from Mar 27, 2021

Conversation

andrehjr
Copy link
Member

@andrehjr andrehjr commented Oct 6, 2020

Investigating Pry::Helpers#strip_color I've found out that\e[1A\e[0G and the prompt was being removed from the text.

When the string was big enough, it wouldn't cause any trouble, as the output would just 'overwrite' it. But for strings such as 'puts "Hello"', or "'hello'.upcase" it would break the output in unexpected ways.

On master:

"\e[1A\e[0G[2] pry(main)> puts \e[31m\e[1;31m'\e[0m\e[31mhello\e[1;31m'\e[0m\e[31m\e[0m\e[1B\e[0G"

would become:

'hello'\e[1B\e[0G

With this fix:

"\e[1A\e[0G[2] pry(main)> puts 'hello'\e[1B\e[0G"

After my fix a spec on spec/pry_repl_spec.rb:127 started failing with RegexpError: premature end of char-class. A simple "string".match("do\n break #note the tab here\nend\n\e[1B\e[0G=> nil") raises an error. I've fixed that escaping the [ on 31590ea

It wasn't failing before because those strings were being matched by RSpec's fuzzy matcher and not by the regex itself.

Fixes #2148

The previous implementation was removing more than that. When Pry.color = false, it was messing up the output of a few commands.
@xjunior
Copy link
Contributor

xjunior commented Mar 26, 2021

👍

@kyrylo kyrylo merged commit 033f69b into pry:master Mar 27, 2021
@kyrylo
Copy link
Member

kyrylo commented Mar 27, 2021

Thanks!

@andrehjr andrehjr deleted the fix-color-off-overwrite branch March 27, 2021 23:27
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.

Disabling colors causes breakage in output
3 participants