buildkite-builder 1.0.0.beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +56 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/buildkite-builder +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/buildkite-builder.gemspec +28 -0
- data/lib/buildkite-builder.rb +14 -0
- data/lib/buildkite/builder.rb +54 -0
- data/lib/buildkite/builder/commands.rb +49 -0
- data/lib/buildkite/builder/commands/abstract.rb +64 -0
- data/lib/buildkite/builder/commands/files.rb +25 -0
- data/lib/buildkite/builder/commands/preview.rb +29 -0
- data/lib/buildkite/builder/definition.rb +24 -0
- data/lib/buildkite/builder/file_resolver.rb +59 -0
- data/lib/buildkite/builder/github.rb +71 -0
- data/lib/buildkite/builder/loaders.rb +12 -0
- data/lib/buildkite/builder/loaders/abstract.rb +40 -0
- data/lib/buildkite/builder/loaders/manifests.rb +23 -0
- data/lib/buildkite/builder/loaders/processors.rb +37 -0
- data/lib/buildkite/builder/loaders/templates.rb +25 -0
- data/lib/buildkite/builder/logging_utils.rb +24 -0
- data/lib/buildkite/builder/manifest.rb +89 -0
- data/lib/buildkite/builder/manifest/rule.rb +51 -0
- data/lib/buildkite/builder/processors.rb +9 -0
- data/lib/buildkite/builder/processors/abstract.rb +76 -0
- data/lib/buildkite/builder/rainbow.rb +9 -0
- data/lib/buildkite/builder/runner.rb +114 -0
- data/lib/buildkite/env.rb +52 -0
- data/lib/buildkite/pipelines.rb +13 -0
- data/lib/buildkite/pipelines/api.rb +119 -0
- data/lib/buildkite/pipelines/attributes.rb +137 -0
- data/lib/buildkite/pipelines/command.rb +59 -0
- data/lib/buildkite/pipelines/helpers.rb +43 -0
- data/lib/buildkite/pipelines/helpers/block.rb +18 -0
- data/lib/buildkite/pipelines/helpers/command.rb +21 -0
- data/lib/buildkite/pipelines/helpers/depends_on.rb +13 -0
- data/lib/buildkite/pipelines/helpers/key.rb +13 -0
- data/lib/buildkite/pipelines/helpers/label.rb +18 -0
- data/lib/buildkite/pipelines/helpers/plugins.rb +24 -0
- data/lib/buildkite/pipelines/helpers/retry.rb +20 -0
- data/lib/buildkite/pipelines/helpers/skip.rb +15 -0
- data/lib/buildkite/pipelines/helpers/soft_fail.rb +15 -0
- data/lib/buildkite/pipelines/helpers/timeout_in_minutes.rb +17 -0
- data/lib/buildkite/pipelines/pipeline.rb +129 -0
- data/lib/buildkite/pipelines/plugin.rb +23 -0
- data/lib/buildkite/pipelines/steps.rb +15 -0
- data/lib/buildkite/pipelines/steps/abstract.rb +26 -0
- data/lib/buildkite/pipelines/steps/block.rb +20 -0
- data/lib/buildkite/pipelines/steps/command.rb +30 -0
- data/lib/buildkite/pipelines/steps/input.rb +20 -0
- data/lib/buildkite/pipelines/steps/skip.rb +28 -0
- data/lib/buildkite/pipelines/steps/trigger.rb +22 -0
- data/lib/buildkite/pipelines/steps/wait.rb +18 -0
- data/lib/vendor/rainbow/Changelog.md +101 -0
- data/lib/vendor/rainbow/Gemfile +30 -0
- data/lib/vendor/rainbow/LICENSE +20 -0
- data/lib/vendor/rainbow/README.markdown +225 -0
- data/lib/vendor/rainbow/Rakefile +11 -0
- data/lib/vendor/rainbow/lib/rainbow.rb +13 -0
- data/lib/vendor/rainbow/lib/rainbow/color.rb +150 -0
- data/lib/vendor/rainbow/lib/rainbow/ext/string.rb +64 -0
- data/lib/vendor/rainbow/lib/rainbow/global.rb +25 -0
- data/lib/vendor/rainbow/lib/rainbow/null_presenter.rb +100 -0
- data/lib/vendor/rainbow/lib/rainbow/presenter.rb +144 -0
- data/lib/vendor/rainbow/lib/rainbow/refinement.rb +14 -0
- data/lib/vendor/rainbow/lib/rainbow/string_utils.rb +22 -0
- data/lib/vendor/rainbow/lib/rainbow/version.rb +5 -0
- data/lib/vendor/rainbow/lib/rainbow/wrapper.rb +22 -0
- data/lib/vendor/rainbow/lib/rainbow/x11_color_names.rb +153 -0
- data/lib/vendor/rainbow/rainbow.gemspec +23 -0
- metadata +126 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buildkite
|
4
|
+
module Pipelines
|
5
|
+
class Plugin
|
6
|
+
attr_reader :uri, :version, :options
|
7
|
+
|
8
|
+
def initialize(uri, version, options = nil)
|
9
|
+
@uri = uri
|
10
|
+
@version = version
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
|
14
|
+
def full_uri
|
15
|
+
"#{uri}##{version}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_h
|
19
|
+
Helpers.sanitize(full_uri => options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buildkite
|
4
|
+
module Pipelines
|
5
|
+
module Steps
|
6
|
+
autoload :Abstract, File.expand_path('steps/abstract', __dir__)
|
7
|
+
autoload :Block, File.expand_path('steps/block', __dir__)
|
8
|
+
autoload :Command, File.expand_path('steps/command', __dir__)
|
9
|
+
autoload :Input, File.expand_path('steps/input', __dir__)
|
10
|
+
autoload :Skip, File.expand_path('steps/skip', __dir__)
|
11
|
+
autoload :Trigger, File.expand_path('steps/trigger', __dir__)
|
12
|
+
autoload :Wait, File.expand_path('steps/wait', __dir__)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buildkite
|
4
|
+
module Pipelines
|
5
|
+
module Steps
|
6
|
+
class Abstract
|
7
|
+
include Attributes
|
8
|
+
|
9
|
+
attr_reader :pipeline
|
10
|
+
attr_reader :template
|
11
|
+
|
12
|
+
def self.to_sym
|
13
|
+
name.split('::').last.downcase.to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(pipeline, template = nil, &block)
|
17
|
+
@pipeline = pipeline
|
18
|
+
@template = template
|
19
|
+
|
20
|
+
instance_eval(&template) if template
|
21
|
+
instance_eval(&block) if block_given?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buildkite
|
4
|
+
module Pipelines
|
5
|
+
module Steps
|
6
|
+
class Block < Abstract
|
7
|
+
# Do NOT sort this list. The order here is carried over to the YAML output.
|
8
|
+
# The order specified here was deliberate.
|
9
|
+
attribute :block
|
10
|
+
attribute :key
|
11
|
+
attribute :prompt
|
12
|
+
attribute :if, as: :condition
|
13
|
+
attribute :depends_on, append: true
|
14
|
+
attribute :allow_dependency_failure
|
15
|
+
attribute :branches
|
16
|
+
attribute :fields
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buildkite
|
4
|
+
module Pipelines
|
5
|
+
module Steps
|
6
|
+
class Command < Abstract
|
7
|
+
# Do NOT sort this list. The order here is carried over to the YAML output.
|
8
|
+
# The order specified here was deliberate.
|
9
|
+
attribute :label
|
10
|
+
attribute :key
|
11
|
+
attribute :command, append: true
|
12
|
+
attribute :skip
|
13
|
+
attribute :if, as: :condition
|
14
|
+
attribute :depends_on, append: true
|
15
|
+
attribute :allow_dependency_failure
|
16
|
+
attribute :parallelism
|
17
|
+
attribute :branches
|
18
|
+
attribute :artifact_paths
|
19
|
+
attribute :agents
|
20
|
+
attribute :concurrency
|
21
|
+
attribute :concurrency_group
|
22
|
+
attribute :retry
|
23
|
+
attribute :env
|
24
|
+
attribute :soft_fail, append: true
|
25
|
+
attribute :timeout_in_minutes
|
26
|
+
attribute :plugins, append: true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buildkite
|
4
|
+
module Pipelines
|
5
|
+
module Steps
|
6
|
+
class Input < Abstract
|
7
|
+
# Do NOT sort this list. The order here is carried over to the YAML output.
|
8
|
+
# The order specified here was deliberate.
|
9
|
+
attribute :input
|
10
|
+
attribute :key
|
11
|
+
attribute :prompt
|
12
|
+
attribute :if, as: :condition
|
13
|
+
attribute :depends_on, append: true
|
14
|
+
attribute :allow_dependency_failure
|
15
|
+
attribute :branches
|
16
|
+
attribute :fields
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buildkite
|
4
|
+
module Pipelines
|
5
|
+
module Steps
|
6
|
+
class Skip < Abstract
|
7
|
+
# This skip step is not an official Buildkite step. A skip step is really
|
8
|
+
# just a command step that does nothing and is used to portray a hidden
|
9
|
+
# step on the Buildkite web UI.
|
10
|
+
#
|
11
|
+
# Since it is it's own class, pipeline processors will be able to distinguish
|
12
|
+
# between this type of skip and a conditional skip. Conditional skips are
|
13
|
+
# full command or trigger steps skipped by the `skip` attribute. They can be
|
14
|
+
# unskipped in processors for certain situations. See the `DefaultBranch`
|
15
|
+
# processor for example.
|
16
|
+
|
17
|
+
# Do NOT sort this list. The order here is carried over to the YAML output.
|
18
|
+
# The order specified here was deliberate.
|
19
|
+
attribute :label
|
20
|
+
attribute :skip
|
21
|
+
attribute :if, as: :condition
|
22
|
+
attribute :depends_on, append: true
|
23
|
+
attribute :allow_dependency_failure
|
24
|
+
attribute :command
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buildkite
|
4
|
+
module Pipelines
|
5
|
+
module Steps
|
6
|
+
class Trigger < Abstract
|
7
|
+
# Do NOT sort this list. The order here is carried over to the YAML output.
|
8
|
+
# The order specified here was deliberate.
|
9
|
+
attribute :label
|
10
|
+
attribute :key
|
11
|
+
attribute :trigger
|
12
|
+
attribute :skip
|
13
|
+
attribute :if, as: :condition
|
14
|
+
attribute :depends_on, append: true
|
15
|
+
attribute :allow_dependency_failure
|
16
|
+
attribute :branches
|
17
|
+
attribute :async
|
18
|
+
attribute :build
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Buildkite
|
4
|
+
module Pipelines
|
5
|
+
module Steps
|
6
|
+
class Wait < Abstract
|
7
|
+
# Do NOT sort this list. The order here is carried over to the YAML output.
|
8
|
+
# The order specified here was deliberate.
|
9
|
+
attribute :wait
|
10
|
+
attribute :key
|
11
|
+
attribute :if, as: :condition
|
12
|
+
attribute :depends_on, append: true
|
13
|
+
attribute :allow_dependency_failure
|
14
|
+
attribute :continue_on_failure
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
# Rainbow changelog
|
2
|
+
|
3
|
+
## 3.1.0 (2020-08-26)
|
4
|
+
|
5
|
+
- added `cross_out` aka `strike`
|
6
|
+
- hexadecimal color names supported better, see #83
|
7
|
+
- gemspec: list files using a Ruby expression, avoiding git
|
8
|
+
|
9
|
+
## 3.0.0 (2017-11-29)
|
10
|
+
|
11
|
+
* added String refinement
|
12
|
+
* added new `Rainbow.uncolor` method
|
13
|
+
* dropped MRI 1.9.3 compatibility
|
14
|
+
* dropped MRI 2.0 compatibility
|
15
|
+
* removed Rake dependency
|
16
|
+
|
17
|
+
## 2.2.2 (2017-04-21)
|
18
|
+
|
19
|
+
* added explicit rake dependency to fix installation issue
|
20
|
+
|
21
|
+
## 2.2.1 (2016-12-28)
|
22
|
+
|
23
|
+
* fixed gem installation (2.2.0 was a broken release)
|
24
|
+
|
25
|
+
## 2.2.0 (2016-12-27)
|
26
|
+
|
27
|
+
* improved Windows support
|
28
|
+
* added Ruby 2.4 support
|
29
|
+
* added `bold` alias method for `bright`
|
30
|
+
|
31
|
+
## 2.1.0 (2016-01-24)
|
32
|
+
|
33
|
+
* added X11 color support
|
34
|
+
* fixed `require` issue when rainbow is used as a dependency in another gem
|
35
|
+
* improved Windows support
|
36
|
+
|
37
|
+
## 2.0.0 (2014-01-24)
|
38
|
+
|
39
|
+
* disable string mixin by default
|
40
|
+
|
41
|
+
## 1.99.2 (2014-01-24)
|
42
|
+
|
43
|
+
* bring back ruby 1.8 support
|
44
|
+
|
45
|
+
## 1.99.1 (2013-12-28)
|
46
|
+
|
47
|
+
* drop support for ruby 1.8
|
48
|
+
* `require "rainbow/string"` -> `require "rainbow/ext/string"`
|
49
|
+
* custom rainbow wrapper instances (with separate enabled/disabled state)
|
50
|
+
* shortcut methods for changing text color (`Rainbow("foo").red`)
|
51
|
+
|
52
|
+
## 1.99.0 (2013-12-26)
|
53
|
+
|
54
|
+
* preparation for dropping String monkey patching
|
55
|
+
* `require "rainbow/string"` if you want to use monkey patched String
|
56
|
+
* introduction of Rainbow() wrapper
|
57
|
+
* support for MRI 1.8.7, 1.9.2, 1.9.3, 2.0 and 2.1, JRuby and Rubinius
|
58
|
+
* deprecation of Sickill::Rainbow namespace (use Rainbow.enabled = true instead)
|
59
|
+
|
60
|
+
## 1.1.4 (2012-4-28)
|
61
|
+
|
62
|
+
* option for forcing coloring even when STDOUT is not a TTY (CLICOLOR_FORCE env var)
|
63
|
+
* fix for frozen strings
|
64
|
+
|
65
|
+
## 1.1.3 (2011-12-6)
|
66
|
+
|
67
|
+
* improved compatibility with MRI 1.8.7
|
68
|
+
* fix for regression with regards to original string mutation
|
69
|
+
|
70
|
+
## 1.1.2 (2011-11-13)
|
71
|
+
|
72
|
+
* improved compatibility with MRI 1.9.3
|
73
|
+
|
74
|
+
## 1.1.1 (2011-2-7)
|
75
|
+
|
76
|
+
* improved Windows support
|
77
|
+
|
78
|
+
## 1.1 (2010-6-7)
|
79
|
+
|
80
|
+
* option for enabling/disabling of escape code wrapping
|
81
|
+
* auto-disabling when STDOUT is not a TTY
|
82
|
+
|
83
|
+
## 1.0.4 (2009-11-27)
|
84
|
+
|
85
|
+
* support for 256 colors
|
86
|
+
|
87
|
+
## 1.0.3 (2009-7-26)
|
88
|
+
|
89
|
+
* rainbow methods don't mutate the original string object anymore
|
90
|
+
|
91
|
+
## 1.0.2 (2009-5-15)
|
92
|
+
|
93
|
+
* improved support for ruby 1.8.6 and 1.9.1
|
94
|
+
|
95
|
+
## 1.0.1 (2009-3-19)
|
96
|
+
|
97
|
+
* Windows support
|
98
|
+
|
99
|
+
## 1.0.0 (2008-7-21)
|
100
|
+
|
101
|
+
* initial version
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
gem 'rake'
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem 'coveralls', require: false
|
11
|
+
gem 'rspec'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :development do
|
15
|
+
gem 'mutant-rspec'
|
16
|
+
end
|
17
|
+
|
18
|
+
group :test, :development do
|
19
|
+
gem 'rubocop', '0.81.0', require: false # This version supports Ruby 2.3
|
20
|
+
end
|
21
|
+
|
22
|
+
group :guard do
|
23
|
+
gem 'guard'
|
24
|
+
gem 'guard-rspec'
|
25
|
+
end
|
26
|
+
|
27
|
+
platform :rbx do
|
28
|
+
gem 'json'
|
29
|
+
gem 'rubysl'
|
30
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) Marcin Kulik
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,225 @@
|
|
1
|
+
# Rainbow
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/rainbow)
|
4
|
+
[](https://travis-ci.org/sickill/rainbow)
|
5
|
+
[](https://ci.appveyor.com/project/sickill/rainbow)
|
6
|
+
[](https://codeclimate.com/github/sickill/rainbow)
|
7
|
+
[](https://coveralls.io/r/sickill/rainbow)
|
8
|
+
|
9
|
+
Rainbow is a ruby gem for colorizing printed text on ANSI terminals.
|
10
|
+
|
11
|
+
It provides a string presenter object, which adds several methods to your
|
12
|
+
strings for wrapping them in [ANSI escape
|
13
|
+
codes](http://en.wikipedia.org/wiki/ANSI_escape_code). These codes when printed
|
14
|
+
in a terminal change text attributes like text color, background color,
|
15
|
+
intensity etc.
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
To make your string colored wrap it with `Rainbow()` presenter and call
|
20
|
+
`.color(<color name>)` on it.
|
21
|
+
|
22
|
+
### Example
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'rainbow'
|
26
|
+
|
27
|
+
puts Rainbow("this is red").red + " and " + Rainbow("this on yellow bg").bg(:yellow) + " and " + Rainbow("even bright underlined!").underline.bright
|
28
|
+
|
29
|
+
# => "\e[31mthis is red\e[0m and \e[43mthis on yellow bg\e[0m and \e[4m\e[1meven bright underlined!\e[0m"
|
30
|
+
```
|
31
|
+
|
32
|
+
Or, [watch this video example](https://asciinema.org/a/J928KpHoUQ0sl54ulOSOLE71E?rows=20&speed=2.5)
|
33
|
+
|
34
|
+
### Rainbow presenter API
|
35
|
+
|
36
|
+
Rainbow presenter adds the following methods to presented string:
|
37
|
+
|
38
|
+
* `color(c)` (with `foreground`, and `fg` aliases)
|
39
|
+
* `background(c)` (with `bg` alias)
|
40
|
+
* `bright`
|
41
|
+
* `underline`
|
42
|
+
* `blink`
|
43
|
+
* `inverse`
|
44
|
+
* `hide`
|
45
|
+
* `faint` (not well supported by terminal emulators)
|
46
|
+
* `italic` (not well supported by terminal emulators)
|
47
|
+
* `cross_out`, `strike`
|
48
|
+
|
49
|
+
Text color can also be changed by calling a method named by a color:
|
50
|
+
|
51
|
+
* `black`
|
52
|
+
* `red`
|
53
|
+
* `green`
|
54
|
+
* `yellow`
|
55
|
+
* `blue`
|
56
|
+
* `magenta`
|
57
|
+
* `cyan`
|
58
|
+
* `white`
|
59
|
+
* `aqua`
|
60
|
+
* `silver`
|
61
|
+
* `aliceblue`
|
62
|
+
* `indianred`
|
63
|
+
|
64
|
+
All of the methods return `self` (the presenter object) so you can chain method
|
65
|
+
calls:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
Rainbow("hola!").blue.bright.underline
|
69
|
+
```
|
70
|
+
|
71
|
+
### Refinement
|
72
|
+
|
73
|
+
If you want to use the Refinements version, you can:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
require 'rainbow/refinement'
|
77
|
+
using Rainbow
|
78
|
+
puts "Hi!".green
|
79
|
+
```
|
80
|
+
|
81
|
+
Here's an IRB session example:
|
82
|
+
|
83
|
+
```
|
84
|
+
>> 'Hello, World!'.blue.bright.underline
|
85
|
+
NoMethodError: undefined method `blue' for "Hello, World!":String
|
86
|
+
(ripl):1:in `<main>'
|
87
|
+
>> using Rainbow
|
88
|
+
=> main
|
89
|
+
>> 'Hello, World!'.blue.bright.underline
|
90
|
+
=> "\e[34m\e[1m\e[4mHello, World!\e[0m"
|
91
|
+
```
|
92
|
+
|
93
|
+
### Color specification
|
94
|
+
|
95
|
+
Both `color` and `background` accept color specified in any
|
96
|
+
of the following ways:
|
97
|
+
|
98
|
+
* ANSI color number (where 0 is black, 1 is red, 2 is green and so on):
|
99
|
+
`Rainbow("hello").color(1)`
|
100
|
+
|
101
|
+
* [ANSI color](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) name or [X11 color](https://en.wikipedia.org/wiki/X11_color_names) name as a symbol:
|
102
|
+
`Rainbow("hello").color(:yellow)`.
|
103
|
+
This can be simplified to `Rainbow("hello").yellow`
|
104
|
+
|
105
|
+
See [Color list](#user-content-color-list) for all available color names.
|
106
|
+
Note that ANSI colors can be changed in accordance with terminal setting.
|
107
|
+
But X11 color is just a syntax sugar for RGB triplet. So you always see what you specified.
|
108
|
+
|
109
|
+
* RGB triplet as separate values in the range 0-255:
|
110
|
+
`Rainbow("hello").color(115, 23, 98)`
|
111
|
+
|
112
|
+
* RGB triplet as a hex string:
|
113
|
+
`Rainbow("hello").color("FFC482")` or `Rainbow("hello").color("#FFC482")`
|
114
|
+
|
115
|
+
When you specify a color with a RGB triplet rainbow finds the nearest match
|
116
|
+
from 256 colors palette. Note that it requires a 256-colors capable terminal to
|
117
|
+
display correctly.
|
118
|
+
|
119
|
+
#### Example: Choose a random color
|
120
|
+
|
121
|
+
You can pick a random color with Rainbow, it's a one-liner:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
colors = Range.new(0,7).to_a
|
125
|
+
"whoop dee doop".chars.map { |char| Rainbow(char).color(colors.sample) }.join
|
126
|
+
# => "\e[36mw\e[0m\e[37mh\e[0m\e[34mo\e[0m\e[34mo\e[0m\e[37mp\e[0m\e[34m \e[0m\e[36md\e[0m\e[33me\e[0m\e[34me\e[0m\e[37m \e[0m\e[32md\e[0m\e[35mo\e[0m\e[33mo\e[0m\e[36mp\e[0m"
|
127
|
+
|
128
|
+
colors = [:aliceblue, :antiquewhite, :aqua, :aquamarine, :azure, :beige, :bisque, :blanchedalmond, :blueviolet]
|
129
|
+
"whoop dee doop".chars.map { |char| Rainbow(char).color(colors.sample) }.join
|
130
|
+
# => "\e[38;5;135mw\e[0m\e[38;5;230mh\e[0m\e[38;5;231mo\e[0m\e[38;5;135mo\e[0m\e[38;5;231mp\e[0m\e[38;5;231m \e[0m\e[38;5;122md\e[0m\e[38;5;231me\e[0m\e[38;5;231me\e[0m\e[38;5;230m \e[0m\e[38;5;122md\e[0m\e[38;5;51mo\e[0m\e[38;5;51mo\e[0m\e[38;5;51mp\e[0m"
|
131
|
+
```
|
132
|
+
|
133
|
+
### Configuration
|
134
|
+
|
135
|
+
Rainbow can be enabled/disabled globally by setting:
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
Rainbow.enabled = true/false
|
139
|
+
```
|
140
|
+
|
141
|
+
When disabled all the methods return an unmodified string
|
142
|
+
(`Rainbow("hello").red == "hello"`).
|
143
|
+
|
144
|
+
It's enabled by default, unless STDOUT/STDERR is not a TTY or a terminal is
|
145
|
+
dumb.
|
146
|
+
|
147
|
+
### Advanced usage
|
148
|
+
|
149
|
+
`Rainbow()` and `Rainbow.enabled` operate on the global Rainbow wrapper
|
150
|
+
instance. If you would like to selectively enable/disable coloring in separate
|
151
|
+
parts of your application you can get a new Rainbow wrapper instance for each
|
152
|
+
of them and control the state of coloring during the runtime.
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
rainbow_one = Rainbow.new
|
156
|
+
rainbow_two = Rainbow.new
|
157
|
+
|
158
|
+
rainbow_one.enabled = false
|
159
|
+
|
160
|
+
Rainbow("hello").red # => "\e[31mhello\e[0m" ("hello" if not on TTY)
|
161
|
+
rainbow_one.wrap("hello").red # => "hello"
|
162
|
+
rainbow_two.wrap("hello").red # => "\e[31mhello\e[0m" ("hello" if not on TTY)
|
163
|
+
```
|
164
|
+
|
165
|
+
By default each new instance inherits enabled/disabled state from the global
|
166
|
+
`Rainbow.enabled`.
|
167
|
+
|
168
|
+
This feature comes handy for example when you have multiple output formatters
|
169
|
+
in your application and some of them print to a terminal but others write to a
|
170
|
+
file. Normally rainbow would detect that STDIN/STDERR is a TTY and would
|
171
|
+
colorize all the strings, even the ones that go through file writing
|
172
|
+
formatters. You can easily solve that by disabling coloring for the Rainbow
|
173
|
+
instances that are used by formatters with file output.
|
174
|
+
|
175
|
+
## Installation
|
176
|
+
|
177
|
+
Add it to your Gemfile:
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
gem 'rainbow'
|
181
|
+
```
|
182
|
+
|
183
|
+
Or just install it via rubygems:
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
gem install rainbow
|
187
|
+
```
|
188
|
+
|
189
|
+
## Color list
|
190
|
+
|
191
|
+
### ANSI colors
|
192
|
+
|
193
|
+
`black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`
|
194
|
+
|
195
|
+
### X11 colors
|
196
|
+
|
197
|
+
`aliceblue`, `antiquewhite`, `aqua`, `aquamarine`, `azure`, `beige`, `bisque`,
|
198
|
+
`blanchedalmond`, `blueviolet`, `brown`, `burlywood`, `cadetblue`, `chartreuse`,
|
199
|
+
`chocolate`, `coral`, `cornflower`, `cornsilk`, `crimson`, `darkblue`,
|
200
|
+
`darkcyan`, `darkgoldenrod`, `darkgray`, `darkgreen`, `darkkhaki`,
|
201
|
+
`darkmagenta`, `darkolivegreen`, `darkorange`, `darkorchid`, `darkred`,
|
202
|
+
`darksalmon`, `darkseagreen`, `darkslateblue`, `darkslategray`, `darkturquoise`,
|
203
|
+
`darkviolet`, `deeppink`, `deepskyblue`, `dimgray`, `dodgerblue`, `firebrick`,
|
204
|
+
`floralwhite`, `forestgreen`, `fuchsia`, `gainsboro`, `ghostwhite`, `gold`,
|
205
|
+
`goldenrod`, `gray`, `greenyellow`, `honeydew`, `hotpink`, `indianred`,
|
206
|
+
`indigo`, `ivory`, `khaki`, `lavender`, `lavenderblush`, `lawngreen`,
|
207
|
+
`lemonchiffon`, `lightblue`, `lightcoral`, `lightcyan`, `lightgoldenrod`,
|
208
|
+
`lightgray`, `lightgreen`, `lightpink`, `lightsalmon`, `lightseagreen`,
|
209
|
+
`lightskyblue`, `lightslategray`, `lightsteelblue`, `lightyellow`, `lime`,
|
210
|
+
`limegreen`, `linen`, `maroon`, `mediumaquamarine`, `mediumblue`,
|
211
|
+
`mediumorchid`, `mediumpurple`, `mediumseagreen`, `mediumslateblue`,
|
212
|
+
`mediumspringgreen`, `mediumturquoise`, `mediumvioletred`, `midnightblue`,
|
213
|
+
`mintcream`, `mistyrose`, `moccasin`, `navajowhite`, `navyblue`, `oldlace`,
|
214
|
+
`olive`, `olivedrab`, `orange`, `orangered`, `orchid`, `palegoldenrod`,
|
215
|
+
`palegreen`, `paleturquoise`, `palevioletred`, `papayawhip`, `peachpuff`,
|
216
|
+
`peru`, `pink`, `plum`, `powderblue`, `purple`, `rebeccapurple`, `rosybrown`,
|
217
|
+
`royalblue`, `saddlebrown`, `salmon`, `sandybrown`, `seagreen`, `seashell`,
|
218
|
+
`sienna`, `silver`, `skyblue`, `slateblue`, `slategray`, `snow`, `springgreen`,
|
219
|
+
`steelblue`, `tan`, `teal`, `thistle`, `tomato`, `turquoise`, `violet`,
|
220
|
+
`webgray`, `webgreen`, `webmaroon`, `webpurple`, `wheat`, `whitesmoke`,
|
221
|
+
`yellowgreen`
|
222
|
+
|
223
|
+
## Authors
|
224
|
+
|
225
|
+
[Marcin Kulik](http://ku1ik.com/) and [great open-source contributors](https://github.com/sickill/rainbow/graphs/contributors).
|