Skip to content

Conversation

@tzmfreedom
Copy link

@tzmfreedom tzmfreedom commented Feb 7, 2018

This pullrequest solve the problem that REPL response display source code on first request, and contain color escape code if we use pry (>= 0.11.0) for REPL.

REPL response sample before (contain source code with color escape code)

\e[1mFrom:\e[0m /Users/hoge/rails5/hoge.rb @ line 10 :

     \e[1;34m5\e[0m:         raise
     \e[1;34m6\e[0m:     \e[32mrescue\e[0m => e
     \e[1;34m7\e[0m:         e
     \e[1;34m8\e[0m:     \e[32mend\e[0m
     \e[1;34m9\e[0m: 
 => \e[1;34m10\e[0m: ins = \e[1;34;4mBetterErrors\e[0m::\e[1;34;4mREPL\e[0m::\e[1;34;4mPry\e[0m.new(binding, e)
    \e[1;34m11\e[0m: pp ins.send_input(\e[31m\e[1;31m'\e[0m\e[31m1*2\e[1;31m'\e[0m\e[31m\e[0m)
    \e[1;34m12\e[0m: pp ins.send_input(\e[31m\e[1;31m'\e[0m\e[31m3\e[1;31m'\e[0m\e[31m\e[0m)

 => \e[1;34m1\e[0m

after(this pullrequest), it contains only REPL response, so does not contain source code with color escape code.

 => 1

@tzmfreedom tzmfreedom force-pushed the fix_bug_for_pry branch 2 times, most recently from f0f6f2d to 4dd99c2 Compare March 15, 2018 15:26
@RobinDaugherty
Copy link
Member

@tzmfreedom can you give an example to reproduce this issue? I would prefer to add a test that covers this fix.

@tzmfreedom
Copy link
Author

tzmfreedom commented Aug 21, 2018

@RobinDaugherty sorry for my late reply.

This is example code to reproduce this issue. (run bybundle exec rails runner xxx.rb). pry version is 0.11.3.

require 'better_errors/repl/pry'

e = begin
        raise
    rescue => e
        e
    end

repl = BetterErrors::REPL::Pry.new(binding, e)
pp repl.send_input('1*2')

# => 
# ["\n" +
# "\e[1mFrom:\e[0m /Users/hoge/rails5/hoge.rb @ line 10 :\n" +
# "\n" +
# "     \e[1;34m5\e[0m:         raise\n" +
# "     \e[1;34m6\e[0m:     \e[32mrescue\e[0m => e\n" +
# "     \e[1;34m7\e[0m:         e\n" +
# "     \e[1;34m8\e[0m:     \e[32mend\e[0m\n" +
# "     \e[1;34m9\e[0m: \n" +
# " => \e[1;34m10\e[0m: ins = \e[1;34;4mBetterErrors\e[0m::\e[1;34;4mREPL\e[0m::\e[1;34;4mPry\e[0m.new(binding, e)\n" +
# "    \e[1;34m11\e[0m: pp ins.send_input(\e[31m\e[1;31m'\e[0m\e[31m1*2\e[1;31m'\e[0m\e[31m\e[0m)\n" +
# "    \e[1;34m12\e[0m: pp ins.send_input(\e[31m\e[1;31m'\e[0m\e[31m3\e[1;31m'\e[0m\e[31m\e[0m)\n"  +
# "\n" +
# "=> \e[1;34m2\e[0m\n",
# ">>",
# ""]

If this PR is applied, output doesn't contain source code with color escape code.

["=> 2\n", ">>", ""]

@tzmfreedom tzmfreedom force-pushed the fix_bug_for_pry branch 4 times, most recently from e62b149 to b6b45cc Compare August 23, 2018 13:32
@tzmfreedom
Copy link
Author

@RobinDaugherty
I changed issue description #417 (comment).
Please check it.

@RobinDaugherty
Copy link
Member

Thanks @tzmfreedom, sorry this hasn't been moving. My plan is to separate Pry support into a separate gem (#400) but I haven't had time to finish that transition yet. My plan in that project is to support color output rather than disable it by default, but perhaps your change is best for the core project while we wait to transition.

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