Skip to content

Commit

Permalink
Merge pull request #105 from pact-foundation/fix/rainbow_enable_color…
Browse files Browse the repository at this point in the history
…_on_non_tty

fix: enable color on non-tty if color_enabled
  • Loading branch information
YOU54F committed Aug 8, 2024
2 parents 169b49c + 0585424 commit 9736dee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/pact/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'pact/shared/text_differ'
require 'pact/shared/form_differ'
require 'pact/shared/multipart_form_differ'
require 'rainbow'


module Pact
Expand Down Expand Up @@ -114,7 +115,9 @@ def log_path

def color_enabled
# Can't use ||= when the variable might be false, it will execute the expression if it's false
defined?(@color_enabled) ? @color_enabled : true
color_enabled = defined?(@color_enabled) ? @color_enabled : true
Rainbow.enabled = true if color_enabled
color_enabled
end

def color_enabled= color_enabled
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Pact
expect(subject.color_enabled).to be true
end

it "allows configuration of colour_enabled" do
it "allows configuration of color_enabled" do
subject.color_enabled = false
expect(subject.color_enabled).to be false
end
Expand Down

0 comments on commit 9736dee

Please sign in to comment.