Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Add option to disable color with environment variable "NO_COLOR"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line should be under a ### Added heading while the next should be under ### Changed

review the keep a changelog link at the top

- Default coloring to true if $stdout is terminal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documenting this in the README too would be nice


## [0.3.0] - 2024-04-16

### Changed
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ GEM
unicode-display_width (2.5.0)

PLATFORMS
arm64-darwin-22
x86_64-linux

DEPENDENCIES
Expand Down
21 changes: 14 additions & 7 deletions lib/specdiff/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@ class << self
attr_reader :config
end

DEFAULT = Config.new(colorize: true).freeze
@config = DEFAULT.dup
# Generates the default configuration
def self.default_configuration
config = Config.new(colorize: true)

if !ENV["NO_COLOR"].nil? && !ENV["NO_COLOR"].empty?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider a spec for this (in specdiff_spec.rb)

it might be unexpected that NO_COLOR=0 sets color to true

config.colorize = false
else
config.colorize = $stdout.isatty
end

config.freeze
end

@config = default_configuration.dup

# private, used for testing
def self._set_config(new_config)
Expand All @@ -22,9 +34,4 @@ def self.configure
yield(@config)
@config
end

# Generates the default configuration
def self.default_configuration
DEFAULT
end
end