Skip to content

Commit

Permalink
Respect NO_COLOR ENV when present
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehjr committed Oct 13, 2024
1 parent a28a3f2 commit dce0bf3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pry/pry_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def self.start(target = nil, options = {})

options = options.to_hash

options[:color] = false if Pry::Env['NO_COLOR']

if in_critical_section?
output.puts "ERROR: Pry started inside Pry."
output.puts "This can happen if you have a binding.pry inside a #to_s " \
Expand Down
29 changes: 29 additions & 0 deletions spec/pry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@
end
end

describe 'NO_COLOR' do
let(:output) { StringIO.new }

before do
Pry.config.color = true
allow(Pry::Env).to receive(:[])
allow(Pry::Env).to receive(:[]).with('TERM').and_return('xterm-256color')

Pry.config.output = output
Pry.config.input = InputTester.new('"some string"')
end

after do
Pry.reset_defaults
end

it 'should respect NO_COLOR ENV precedence' do
allow(Pry::Env).to receive(:[]).with('NO_COLOR').and_return('1')

Pry.start
expect(output.string).to eql("=> \"some string\"\n")
end

it 'should colorize NO_COLOR is not present' do
Pry.start
expect(output.string).to include("\e[31m\e[1;31m")
end
end

describe 'FAIL_PRY' do
before do
allow(Pry::Env).to receive(:[])
Expand Down

0 comments on commit dce0bf3

Please sign in to comment.