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
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Allow `enabled` option to be passed to `Rainbow.new`
- Development: Drop `rbx` section in Gemfile. No continued support effort for Rubinius.

## 3.1.1 (2022-01-11)
Expand Down
4 changes: 1 addition & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,9 @@ parts of your application you can get a new Rainbow wrapper instance for each
of them and control the state of coloring during the runtime.

```ruby
rainbow_one = Rainbow.new
rainbow_one = Rainbow.new(false)
rainbow_two = Rainbow.new

rainbow_one.enabled = false

Rainbow("hello").red # => "\e[31mhello\e[0m" ("hello" if not on TTY)
rainbow_one.wrap("hello").red # => "hello"
rainbow_two.wrap("hello").red # => "\e[31mhello\e[0m" ("hello" if not on TTY)
Expand Down
4 changes: 2 additions & 2 deletions lib/rainbow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require_relative 'rainbow/global'

module Rainbow
def self.new
Wrapper.new(global.enabled)
def self.new(enabled = global.enabled)
Wrapper.new(enabled)
end

self.enabled = false unless STDOUT.tty? && STDERR.tty?
Expand Down
6 changes: 6 additions & 0 deletions spec/integration/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
expect(rainbow.enabled).to eq(:nope)
end

it 'can be initialized with a different enabled state' do
Rainbow.enabled = :yep
rainbow = Rainbow.new(false)
expect(rainbow.enabled).to eq(false)
end

it 'wraps string with escape codes when enabled' do
rainbow = Rainbow.new
rainbow.enabled = true
Expand Down