pax_global_header00006660000000000000000000000064131513225530014512gustar00rootroot0000000000000052 comment=22d133cc9eb6eebd018c572212a4c8d8292a5fc3 ruby-rainbow-2.2.2/000077500000000000000000000000001315132255300141355ustar00rootroot00000000000000ruby-rainbow-2.2.2/.gitignore000066400000000000000000000002321315132255300161220ustar00rootroot00000000000000*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp ruby-rainbow-2.2.2/.rubocop.yml000066400000000000000000000002461315132255300164110ustar00rootroot00000000000000Documentation: Enabled: false EmptyLinesAroundBody: Enabled: false HashSyntax: Enabled: false MethodName: Enabled: false StringLiterals: Enabled: false ruby-rainbow-2.2.2/.travis.yml000066400000000000000000000007041315132255300162470ustar00rootroot00000000000000language: ruby cache: - bundler before_install: - gem update --system - gem install bundler bundler_args: --without guard development matrix: include: - rvm: 2.0.0 - rvm: 2.1.9 - rvm: 2.2.6 - rvm: 2.3.3 - rvm: 2.4.0 - rvm: jruby-9.1.6.0 jdk: oraclejdk8 env: - JRUBY_OPTS=--debug - rvm: 2.2.6 install: true # This skips 'bundle install' script: gem build rainbow && gem install *.gem ruby-rainbow-2.2.2/Changelog.md000066400000000000000000000036061315132255300163530ustar00rootroot00000000000000# Rainbow changelog ## 1.0.0 (2008-7-21) * initial version ## 1.0.1 (2009-3-19) * Windows support ## 1.0.2 (2009-5-15) * improved support for ruby 1.8.6 and 1.9.1 ## 1.0.3 (2009-7-26) * rainbow methods don't mutate the original string object anymore ## 1.0.4 (2009-11-27) * support for 256 colors ## 1.1 (2010-6-7) * option for enabling/disabling of escape code wrapping * auto-disabling when STDOUT is not a TTY ## 1.1.1 (2011-2-7) * improved Windows support ## 1.1.2 (2011-11-13) * improved compatibility with MRI 1.9.3 ## 1.1.3 (2011-12-6) * improved compatibility with MRI 1.8.7 * fix for regression with regards to original string mutation ## 1.1.4 (2012-4-28) * option for forcing coloring even when STDOUT is not a TTY (CLICOLOR_FORCE env var) * fix for frozen strings ## 1.99.0 (2013-12-26) * preparation for dropping String monkey patching * `require "rainbow/string"` if you want to use monkey patched String * introduction of Rainbow() wrapper * support for MRI 1.8.7, 1.9.2, 1.9.3, 2.0 and 2.1, JRuby and Rubinius * deprecation of Sickill::Rainbow namespace (use Rainbow.enabled = true instead) ## 1.99.1 (2013-12-28) * drop support for ruby 1.8 * `require "rainbow/string"` -> `require "rainbow/ext/string"` * custom rainbow wrapper instances (with separate enabled/disabled state) * shortcut methods for changing text color (`Rainbow("foo").red`) ## 1.99.2 (2014-01-24) * bring back ruby 1.8 support ## 2.0.0 (2014-01-24) * disable string mixin by default ## 2.1.0 (2016-01-24) * added X11 color support * fixed `require` issue when rainbow is used as a dependency in another gem * improved Windows support # 2.2.0 (2016-12-27) * improved Windows support * added Ruby 2.4 support * added `bold` alias method for `bright` # 2.2.1 (2016-12-28) * fixed gem installation (2.2.0 was a broken release) # 2.2.2 (2017-04-21) * added explicit rake dependency to fix installation issue ruby-rainbow-2.2.2/Gemfile000066400000000000000000000005401315132255300154270ustar00rootroot00000000000000source 'https://rubygems.org' # Specify your gem's dependencies in rainbow.gemspec gemspec gem 'rake' gem 'coveralls', require: false gem 'mime-types', '< 2.0.0', platforms: [:ruby_18] gem 'rspec' group :development do gem 'mutant-rspec' end group :guard do gem 'guard' gem 'guard-rspec' end platform :rbx do gem 'json' gem 'rubysl' end ruby-rainbow-2.2.2/Guardfile000066400000000000000000000003541315132255300157640ustar00rootroot00000000000000# A sample Guardfile # More info at https://github.com/guard/guard#readme guard :rspec, cmd: 'rspec --color' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { "spec" } watch('spec/spec_helper.rb') { "spec" } end ruby-rainbow-2.2.2/LICENSE000066400000000000000000000020331315132255300151400ustar00rootroot00000000000000Copyright (c) Marcin Kulik Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ruby-rainbow-2.2.2/README.markdown000066400000000000000000000170361315132255300166450ustar00rootroot00000000000000# Rainbow [![Build Status](https://travis-ci.org/sickill/rainbow.svg?branch=master)](https://travis-ci.org/sickill/rainbow) [![Code Climate](https://codeclimate.com/github/sickill/rainbow.svg)](https://codeclimate.com/github/sickill/rainbow) [![Coverage Status](https://coveralls.io/repos/sickill/rainbow/badge.svg)](https://coveralls.io/r/sickill/rainbow) Rainbow is a ruby gem for colorizing printed text on ANSI terminals. It provides a string presenter object, which adds several methods to your strings for wrapping them in [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code). These codes when printed in a terminal change text attributes like text color, background color, intensity etc. ## Usage To make your string colored wrap it with `Rainbow()` presenter and call `.color()` on it. ### Example ```ruby require 'rainbow' puts Rainbow("this is red").red + " and " + Rainbow("this on yellow bg").bg(:yellow) + " and " + Rainbow("even bright underlined!").underline.bright # => "\e[31mthis is red\e[0m and \e[43mthis on yellow bg\e[0m and \e[4m\e[1meven bright underlined!\e[0m" ``` ### Rainbow presenter API Rainbow presenter adds the following methods to presented string: * `color(c)` (with `foreground`, and `fg` aliases) * `background(c)` (with `bg` alias) * `bright` * `underline` * `blink` * `inverse` * `hide` * `faint` (not well supported by terminal emulators) * `italic` (not well supported by terminal emulators) Text color can also be changed by calling a method named by a color: * `black` * `red` * `green` * `yellow` * `blue` * `magenta` * `cyan` * `white` * `aqua` * `silver` * `aliceblue` * `indianred` All of the methods return `self` (the presenter object) so you can chain method calls: ```ruby Rainbow("hola!").blue.bright.underline ``` ### String mixin If you don't like wrapping every string you want to colorize with `Rainbow()` you can include all the rainbow presenter methods directly in a String class by requiring `rainbow/ext/string`: ```ruby require 'rainbow/ext/string' puts "this is red".color(:red) + " and " + "this on yellow bg".background(:yellow) + " and " + "even bright underlined!".underline.bright ``` This way of using Rainbow is not recommended though as it pollutes String's public interface with methods that are presentation specific. NOTE: the mixin doesn't include shortcut methods for changing text color, you should use "string".color(:blue) instead of "string".blue NOTE: the mixin is included in String by default in rainbow 1.x versions. In rainbow 2.x the behavior was changed - if you're upgrading from 1.x to 2.x and you used direct String methods then you can either require the string extension as shown above or update your code to use the new presenter API. ### Color specification Both `color` and `background` accept color specified in any of the following ways: * ANSI color number (where 0 is black, 1 is red, 2 is green and so on): `Rainbow("hello").color(1)` * [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: `Rainbow("hello").color(:yellow)`. This can be simplified to `Rainbow("hello").yellow` See [Color list](#user-content-color-list) for all available color names. Note that ANSI colors can be changed in accordance with terminal setting. But X11 color is just a syntax sugar for RGB triplet. So you always see what you specified. * RGB triplet as separate values in the range 0-255: `Rainbow("hello").color(115, 23, 98)` * RGB triplet as a hex string: `Rainbow("hello").color("FFC482")` or `Rainbow("hello").color("#FFC482")` When you specify a color with a RGB triplet rainbow finds the nearest match from 256 colors palette. Note that it requires a 256-colors capable terminal to display correctly. ### Configuration Rainbow can be enabled/disabled globally by setting: ```ruby Rainbow.enabled = true/false ``` When disabled all the methods return an unmodified string (`Rainbow("hello").red == "hello"`). It's enabled by default, unless STDOUT/STDERR is not a TTY or a terminal is dumb. ### Advanced usage `Rainbow()` and `Rainbow.enabled` operate on the global Rainbow wrapper instance. If you would like to selectively enable/disable coloring in separate 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_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) ``` By default each new instance inherits enabled/disabled state from the global `Rainbow.enabled`. This feature comes handy for example when you have multiple output formatters in your application and some of them print to a terminal but others write to a file. Normally rainbow would detect that STDIN/STDERR is a TTY and would colorize all the strings, even the ones that go through file writing formatters. You can easily solve that by disabling coloring for the Rainbow instances that are used by formatters with file output. ## Windows support For Windows support on Ruby < 2.0, you should install the following gems: ```ruby gem install windows-pr win32console ``` If the above gems aren't installed then all strings are returned unmodified. ## Installation Add it to your Gemfile: ```ruby gem 'rainbow' ``` Or just install it via rubygems: ```ruby gem install rainbow ``` ## Color list ### ANSI colors `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white` ### X11 colors `aliceblue`, `antiquewhite`, `aqua`, `aquamarine`, `azure`, `beige`, `bisque`, `blanchedalmond`, `blueviolet`, `brown`, `burlywood`, `cadetblue`, `chartreuse`, `chocolate`, `coral`, `cornflower`, `cornsilk`, `crimson`, `darkblue`, `darkcyan`, `darkgoldenrod`, `darkgray`, `darkgreen`, `darkkhaki`, `darkmagenta`, `darkolivegreen`, `darkorange`, `darkorchid`, `darkred`, `darksalmon`, `darkseagreen`, `darkslateblue`, `darkslategray`, `darkturquoise`, `darkviolet`, `deeppink`, `deepskyblue`, `dimgray`, `dodgerblue`, `firebrick`, `floralwhite`, `forestgreen`, `fuchsia`, `gainsboro`, `ghostwhite`, `gold`, `goldenrod`, `gray`, `greenyellow`, `honeydew`, `hotpink`, `indianred`, `indigo`, `ivory`, `khaki`, `lavender`, `lavenderblush`, `lawngreen`, `lemonchiffon`, `lightblue`, `lightcoral`, `lightcyan`, `lightgoldenrod`, `lightgray`, `lightgreen`, `lightpink`, `lightsalmon`, `lightseagreen`, `lightskyblue`, `lightslategray`, `lightsteelblue`, `lightyellow`, `lime`, `limegreen`, `linen`, `maroon`, `mediumaquamarine`, `mediumblue`, `mediumorchid`, `mediumpurple`, `mediumseagreen`, `mediumslateblue`, `mediumspringgreen`, `mediumturquoise`, `mediumvioletred`, `midnightblue`, `mintcream`, `mistyrose`, `moccasin`, `navajowhite`, `navyblue`, `oldlace`, `olive`, `olivedrab`, `orange`, `orangered`, `orchid`, `palegoldenrod`, `palegreen`, `paleturquoise`, `palevioletred`, `papayawhip`, `peachpuff`, `peru`, `pink`, `plum`, `powderblue`, `purple`, `rebeccapurple`, `rosybrown`, `royalblue`, `saddlebrown`, `salmon`, `sandybrown`, `seagreen`, `seashell`, `sienna`, `silver`, `skyblue`, `slateblue`, `slategray`, `snow`, `springgreen`, `steelblue`, `tan`, `teal`, `thistle`, `tomato`, `turquoise`, `violet`, `webgray`, `webgreen`, `webmaroon`, `webpurple`, `wheat`, `whitesmoke`, `yellowgreen` ## Authors [Marcin Kulik](http://ku1ik.com/) and [great open-source contributors](https://github.com/sickill/rainbow/graphs/contributors). ruby-rainbow-2.2.2/Rakefile000066400000000000000000000001651315132255300156040ustar00rootroot00000000000000require "bundler/gem_tasks" require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) task :default => :spec ruby-rainbow-2.2.2/ext/000077500000000000000000000000001315132255300147355ustar00rootroot00000000000000ruby-rainbow-2.2.2/ext/mkrf_conf.rb000066400000000000000000000007071315132255300172320ustar00rootroot00000000000000require 'rubygems' require 'rubygems/command' require 'rubygems/dependency_installer' begin Gem::Command.build_args = ARGV rescue NoMethodError exit 1 end installer = Gem::DependencyInstaller.new begin if RUBY_PLATFORM =~ /mswin|cygwin|mingw/ && RUBY_VERSION.to_i < 2 installer.install('windows-pr') installer.install('win32console') end rescue exit 1 end File.write(File.join(File.dirname(__FILE__), 'Rakefile'), "task :default\n") ruby-rainbow-2.2.2/lib/000077500000000000000000000000001315132255300147035ustar00rootroot00000000000000ruby-rainbow-2.2.2/lib/rainbow.rb000066400000000000000000000011461315132255300166730ustar00rootroot00000000000000require_relative 'rainbow/global' require_relative 'rainbow/legacy' module Rainbow def self.new Wrapper.new(global.enabled) end self.enabled = false unless STDOUT.tty? && STDERR.tty? self.enabled = false if ENV['TERM'] == 'dumb' self.enabled = true if ENV['CLICOLOR_FORCE'] == '1' # On Windows systems, try to load the local ANSI support library if Ruby version < 2 # Ruby 2.x on Windows includes ANSI support. if RUBY_PLATFORM =~ /mswin|cygwin|mingw/ && RUBY_VERSION.to_i < 2 begin require 'Win32/Console/ANSI' rescue LoadError self.enabled = false end end end ruby-rainbow-2.2.2/lib/rainbow/000077500000000000000000000000001315132255300163445ustar00rootroot00000000000000ruby-rainbow-2.2.2/lib/rainbow/color.rb000066400000000000000000000061141315132255300200110ustar00rootroot00000000000000module Rainbow class Color attr_reader :ground def self.build(ground, values) unless [1, 3].include?(values.size) fail ArgumentError, "Wrong number of arguments for color definition, should be 1 or 3" end color = values.size == 1 ? values.first : values case color # NOTE: Properly handle versions before/after Ruby 2.4.0. # Ruby 2.4+ unifies Fixnum & Bignum into Integer. # However previous versions would still use Fixnum. # To avoid missing `Fixnum` input, call `0.class` which would # return either `Integer` or `Fixnum`. when 0.class Indexed.new(ground, color) when Symbol if Named.color_names.include?(color) Named.new(ground, color) elsif X11Named.color_names.include?(color) X11Named.new(ground, color) else fail ArgumentError, "Unknown color name, valid names: " + (Named.color_names + X11Named.color_names).join(', ') end when Array RGB.new(ground, *color) when String RGB.new(ground, *parse_hex_color(color)) end end def self.parse_hex_color(hex) hex = hex.sub(/^#/, '') r = hex[0..1].to_i(16) g = hex[2..3].to_i(16) b = hex[4..5].to_i(16) [r, g, b] end class Indexed < Color attr_reader :num def initialize(ground, num) @ground = ground @num = num end def codes code = num + (ground == :foreground ? 30 : 40) [code] end end class Named < Indexed NAMES = { black: 0, red: 1, green: 2, yellow: 3, blue: 4, magenta: 5, cyan: 6, white: 7, default: 9, } def self.color_names NAMES.keys end def initialize(ground, name) unless Named.color_names.include?(name) fail ArgumentError, "Unknown color name, valid names: #{Named.color_names.join(', ')}" end super(ground, NAMES[name]) end end class RGB < Indexed attr_reader :r, :g, :b def self.to_ansi_domain(value) (6 * (value / 256.0)).to_i end def initialize(ground, *values) if values.min < 0 || values.max > 255 fail ArgumentError, "RGB value outside 0-255 range" end super(ground, 8) @r, @g, @b = values end def codes super + [5, code_from_rgb] end private def code_from_rgb 16 + self.class.to_ansi_domain(r) * 36 + self.class.to_ansi_domain(g) * 6 + self.class.to_ansi_domain(b) end end class X11Named < RGB include X11ColorNames def self.color_names NAMES.keys end def initialize(ground, name) unless X11Named.color_names.include?(name) fail ArgumentError, "Unknown color name, valid names: #{X11Named.color_names.join(', ')}" end super(ground, *NAMES[name]) end end end end ruby-rainbow-2.2.2/lib/rainbow/ext/000077500000000000000000000000001315132255300171445ustar00rootroot00000000000000ruby-rainbow-2.2.2/lib/rainbow/ext/string.rb000066400000000000000000000016631315132255300210050ustar00rootroot00000000000000require 'rainbow' module Rainbow module Ext module String module InstanceMethods def foreground(*color) Rainbow(self).foreground(*color) end alias_method :color, :foreground alias_method :colour, :foreground def background(*color) Rainbow(self).background(*color) end def reset Rainbow(self).reset end def bright Rainbow(self).bright end def faint Rainbow(self).faint end def italic Rainbow(self).italic end def underline Rainbow(self).underline end def blink Rainbow(self).blink end def inverse Rainbow(self).inverse end def hide Rainbow(self).hide end end end end end ::String.send(:include, Rainbow::Ext::String::InstanceMethods) ruby-rainbow-2.2.2/lib/rainbow/global.rb000066400000000000000000000004131315132255300201270ustar00rootroot00000000000000require_relative 'wrapper' module Rainbow def self.global @global ||= Wrapper.new end def self.enabled global.enabled end def self.enabled=(value) global.enabled = value end end def Rainbow(string) Rainbow.global.wrap(string.to_s) end ruby-rainbow-2.2.2/lib/rainbow/legacy.rb000066400000000000000000000004561315132255300201420ustar00rootroot00000000000000module Sickill module Rainbow def self.enabled=(value) STDERR.puts("Rainbow gem notice: Sickill::Rainbow.enabled= is " \ "deprecated, use Rainbow.enabled= instead.") ::Rainbow.enabled = value end def self.enabled ::Rainbow.enabled end end end ruby-rainbow-2.2.2/lib/rainbow/null_presenter.rb000066400000000000000000000015641315132255300217400ustar00rootroot00000000000000module Rainbow class NullPresenter < ::String def color(*values); self; end def background(*values); self; end def reset; self; end def bright; self; end def faint; self; end def italic; self; end def underline; self; end def blink; self; end def inverse; self; end def hide; self; end def black; self; end def red; self; end def green; self; end def yellow; self; end def blue; self; end def magenta; self; end def cyan; self; end def white; self; end def method_missing(method_name,*args) if Color::X11Named.color_names.include? method_name and args.empty? then self else super end end alias_method :foreground, :color alias_method :fg, :color alias_method :bg, :background alias_method :bold, :bright alias_method :dark, :faint end end ruby-rainbow-2.2.2/lib/rainbow/presenter.rb000066400000000000000000000052301315132255300207000ustar00rootroot00000000000000require_relative 'string_utils' require_relative 'x11_color_names' require_relative 'color' module Rainbow class Presenter < ::String TERM_EFFECTS = { reset: 0, bright: 1, faint: 2, italic: 3, underline: 4, blink: 5, inverse: 7, hide: 8, } # Sets color of this text. def color(*values) wrap_with_sgr(Color.build(:foreground, values).codes) end alias_method :foreground, :color alias_method :fg, :color # Sets background color of this text. def background(*values) wrap_with_sgr(Color.build(:background, values).codes) end alias_method :bg, :background # Resets terminal to default colors/backgrounds. # # It shouldn't be needed to use this method because all methods # append terminal reset code to end of string. def reset wrap_with_sgr(TERM_EFFECTS[:reset]) end # Turns on bright/bold for this text. def bright wrap_with_sgr(TERM_EFFECTS[:bright]) end alias_method :bold, :bright # Turns on faint/dark for this text (not well supported by terminal # emulators). def faint wrap_with_sgr(TERM_EFFECTS[:faint]) end alias_method :dark, :faint # Turns on italic style for this text (not well supported by terminal # emulators). def italic wrap_with_sgr(TERM_EFFECTS[:italic]) end # Turns on underline decoration for this text. def underline wrap_with_sgr(TERM_EFFECTS[:underline]) end # Turns on blinking attribute for this text (not well supported by terminal # emulators). def blink wrap_with_sgr(TERM_EFFECTS[:blink]) end # Inverses current foreground/background colors. def inverse wrap_with_sgr(TERM_EFFECTS[:inverse]) end # Hides this text (set its color to the same as background). def hide wrap_with_sgr(TERM_EFFECTS[:hide]) end def black color(:black) end def red color(:red) end def green color(:green) end def yellow color(:yellow) end def blue color(:blue) end def magenta color(:magenta) end def cyan color(:cyan) end def white color(:white) end # We take care of X11 color method call here. # Such as #aqua, #ghostwhite. def method_missing(method_name,*args) if Color::X11Named.color_names.include? method_name and args.empty? then color(method_name) else super end end private def wrap_with_sgr(codes) #:nodoc: self.class.new(StringUtils.wrap_with_sgr(self, [*codes])) end end end ruby-rainbow-2.2.2/lib/rainbow/string_utils.rb000066400000000000000000000006301315132255300214160ustar00rootroot00000000000000module Rainbow class StringUtils def self.wrap_with_sgr(string, codes) return string if codes.empty? seq = "\e[" + codes.join(";") + "m" match = string.match(/^(\e\[([\d;]+)m)*/) seq_pos = match.end(0) string = string[0...seq_pos] + seq + string[seq_pos..-1] unless string =~ /\e\[0m$/ string = string + "\e[0m" end string end end end ruby-rainbow-2.2.2/lib/rainbow/version.rb000066400000000000000000000000561315132255300203570ustar00rootroot00000000000000module Rainbow VERSION = "2.2.2".freeze end ruby-rainbow-2.2.2/lib/rainbow/wrapper.rb000066400000000000000000000005311315132255300203500ustar00rootroot00000000000000require_relative 'presenter' require_relative 'null_presenter' module Rainbow class Wrapper attr_accessor :enabled def initialize(enabled = true) @enabled = enabled end def wrap(string) if enabled Presenter.new(string.to_s) else NullPresenter.new(string.to_s) end end end end ruby-rainbow-2.2.2/lib/rainbow/x11_color_names.rb000066400000000000000000000113301315132255300216610ustar00rootroot00000000000000module Rainbow module X11ColorNames NAMES= { aqua: [0, 255, 255], aquamarine: [127, 255, 212], mediumaquamarine: [102, 205, 170], azure: [240, 255, 255], beige: [245, 245, 220], bisque: [255, 228, 196], black: [0, 0, 0], blanchedalmond: [255, 235, 205], blue: [0, 0, 255], darkblue: [0, 0, 139], lightblue: [173, 216, 230], mediumblue: [0, 0, 205], aliceblue: [240, 248, 255], cadetblue: [95, 158, 160], dodgerblue: [30, 144, 255], midnightblue: [25, 25, 112], navyblue: [0, 0, 128], powderblue: [176, 224, 230], royalblue: [65, 105, 225], skyblue: [135, 206, 235], deepskyblue: [0, 191, 255], lightskyblue: [135, 206, 250], slateblue: [106, 90, 205], darkslateblue: [72, 61, 139], mediumslateblue: [123, 104, 238], steelblue: [70, 130, 180], lightsteelblue: [176, 196, 222], brown: [165, 42, 42], rosybrown: [188, 143, 143], saddlebrown: [139, 69, 19], sandybrown: [244, 164, 96], burlywood: [222, 184, 135], chartreuse: [127, 255, 0], chocolate: [210, 105, 30], coral: [255, 127, 80], lightcoral: [240, 128, 128], cornflower: [100, 149, 237], cornsilk: [255, 248, 220], crimson: [220, 20, 60], cyan: [0, 255, 255], darkcyan: [0, 139, 139], lightcyan: [224, 255, 255], firebrick: [178, 34, 34], fuchsia: [255, 0, 255], gainsboro: [220, 220, 220], gold: [255, 215, 0], goldenrod: [218, 165, 32], darkgoldenrod: [184, 134, 11], lightgoldenrod: [250, 250, 210], palegoldenrod: [238, 232, 170], gray: [190, 190, 190], darkgray: [169, 169, 169], dimgray: [105, 105, 105], lightgray: [211, 211, 211], slategray: [112, 128, 144], lightslategray: [119, 136, 153], webgray: [128, 128, 128], green: [0, 255, 0], darkgreen: [0, 100, 0], lightgreen: [144, 238, 144], palegreen: [152, 251, 152], darkolivegreen: [85, 107, 47], yellowgreen: [154, 205, 50], forestgreen: [34, 139, 34], lawngreen: [124, 252, 0], limegreen: [50, 205, 50], seagreen: [46, 139, 87], darkseagreen: [143, 188, 143], lightseagreen: [32, 178, 170], mediumseagreen: [60, 179, 113], springgreen: [0, 255, 127], mediumspringgreen: [0, 250, 154], webgreen: [0, 128, 0], honeydew: [240, 255, 240], indianred: [205, 92, 92], indigo: [75, 0, 130], ivory: [255, 255, 240], khaki: [240, 230, 140], darkkhaki: [189, 183, 107], lavender: [230, 230, 250], lavenderblush: [255, 240, 245], lemonchiffon: [255, 250, 205], lime: [0, 255, 0], linen: [250, 240, 230], magenta: [255, 0, 255], darkmagenta: [139, 0, 139], maroon: [176, 48, 96], webmaroon: [127, 0, 0], mintcream: [245, 255, 250], mistyrose: [255, 228, 225], moccasin: [255, 228, 181], oldlace: [253, 245, 230], olive: [128, 128, 0], olivedrab: [107, 142, 35], orange: [255, 165, 0], darkorange: [255, 140, 0], orchid: [218, 112, 214], darkorchid: [153, 50, 204], mediumorchid: [186, 85, 211], papayawhip: [255, 239, 213], peachpuff: [255, 218, 185], peru: [205, 133, 63], pink: [255, 192, 203], deeppink: [255, 20, 147], lightpink: [255, 182, 193], hotpink: [255, 105, 180], plum: [221, 160, 221], purple: [160, 32, 240], mediumpurple: [147, 112, 219], rebeccapurple: [102, 51, 153], webpurple: [127, 0, 127], red: [255, 0, 0], darkred: [139, 0, 0], orangered: [255, 69, 0], mediumvioletred: [199, 21, 133], palevioletred: [219, 112, 147], salmon: [250, 128, 114], darksalmon: [233, 150, 122], lightsalmon: [255, 160, 122], seashell: [255, 245, 238], sienna: [160, 82, 45], silver: [192, 192, 192], darkslategray: [47, 79, 79], snow: [255, 250, 250], tan: [210, 180, 140], teal: [0, 128, 128], thistle: [216, 191, 216], tomato: [255, 99, 71], turquoise: [64, 224, 208], darkturquoise: [0, 206, 209], mediumturquoise: [72, 209, 204], paleturquoise: [175, 238, 238], violet: [238, 130, 238], darkviolet: [148, 0, 211], blueviolet: [138, 43, 226], wheat: [245, 222, 179], white: [255, 255, 255], antiquewhite: [250, 235, 215], floralwhite: [255, 250, 240], ghostwhite: [248, 248, 255], navajowhite: [255, 222, 173], whitesmoke: [245, 245, 245], yellow: [255, 255, 0], lightyellow: [255, 255, 224], greenyellow: [173, 255, 47] } end endruby-rainbow-2.2.2/rainbow.gemspec000066400000000000000000000020101315132255300171340ustar00rootroot00000000000000# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'rainbow/version' Gem::Specification.new do |spec| spec.name = "rainbow" spec.version = Rainbow::VERSION spec.authors = ["Marcin Kulik"] spec.email = ["m@ku1ik.com"] spec.description = %q(Colorize printed text on ANSI terminals) spec.summary = %q(Colorize printed text on ANSI terminals) spec.homepage = "https://github.com/sickill/rainbow" spec.license = "MIT" spec.required_ruby_version = '>= 1.9.2' spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] spec.add_dependency "rake" spec.add_development_dependency "bundler", "~> 1.3" spec.extensions = ["ext/mkrf_conf.rb"] end ruby-rainbow-2.2.2/spec/000077500000000000000000000000001315132255300150675ustar00rootroot00000000000000ruby-rainbow-2.2.2/spec/integration/000077500000000000000000000000001315132255300174125ustar00rootroot00000000000000ruby-rainbow-2.2.2/spec/integration/instance_spec.rb000066400000000000000000000015401315132255300225550ustar00rootroot00000000000000require 'spec_helper' require 'rainbow' describe 'Custom Rainbow instance' do it 'inherits enabled state from the global instance' do Rainbow.enabled = :yep expect(Rainbow.new.enabled).to eq(:yep) end it 'tracks its own state separately from the global instance' do Rainbow.enabled = :yep rainbow = Rainbow.new expect(Rainbow.new.enabled).to eq(:yep) rainbow.enabled = :nope expect(Rainbow.enabled).to eq(:yep) expect(rainbow.enabled).to eq(:nope) end it 'wraps string with escape codes when enabled' do rainbow = Rainbow.new rainbow.enabled = true expect(rainbow.wrap('hello').green).to eq("\e[32mhello\e[0m") end it "doesn't wrap string with any escape code when disabled" do rainbow = Rainbow.new rainbow.enabled = false expect(rainbow.wrap('hello').green).to eq('hello') end end ruby-rainbow-2.2.2/spec/integration/rainbow_spec.rb000066400000000000000000000077241315132255300224240ustar00rootroot00000000000000require 'spec_helper' require 'rainbow' describe 'Rainbow() wrapper' do before do Rainbow.enabled = true end it 'allows foreground coloring by color number' do result = Rainbow('hello').foreground(5) expect(result).to eq("\e[35mhello\e[0m") end it 'allows foreground coloring by color name' do result = Rainbow('hello').foreground(:red) expect(result).to eq("\e[31mhello\e[0m") end it 'allows foreground coloring directly by ANSI method name' do result = Rainbow('hello').red expect(result).to eq("\e[31mhello\e[0m") end it 'allows foreground coloring directly by X11 method name' do result = Rainbow('hello').midnightblue expect(result).to eq("\e[38;5;18mhello\e[0m") end it 'allows foreground coloring by ANSI color name (color alias)' do result = Rainbow('hello').color(:red) expect(result).to eq("\e[31mhello\e[0m") end it 'allows foreground coloring by color name (colour alias)' do result = Rainbow('hello').colour(:red) expect(result).to eq("\e[31mhello\e[0m") end it 'allows foreground coloring by X11 color name' do result = Rainbow('hello').foreground(:midnightblue) expect(result).to eq("\e[38;5;18mhello\e[0m") end it 'allows foreground coloring by color rgb' do result = Rainbow('hello').foreground(255, 128, 64) expect(result).to eq("\e[38;5;215mhello\e[0m") end it 'allows foreground coloring by color rgb (hex string)' do result = Rainbow('hello').foreground('ff8040') expect(result).to eq("\e[38;5;215mhello\e[0m") end it 'allows background coloring by color number' do result = Rainbow('hello').background(3) expect(result).to eq("\e[43mhello\e[0m") end it 'allows background coloring by ANSI color name' do result = Rainbow('hello').background(:green) expect(result).to eq("\e[42mhello\e[0m") end it 'allows background coloring by X11 color name' do result = Rainbow('hello').background(:midnightblue) expect(result).to eq("\e[48;5;18mhello\e[0m") end it 'allows background coloring by color rgb' do result = Rainbow('hello').background(255, 128, 64) expect(result).to eq("\e[48;5;215mhello\e[0m") end it 'allows making text bright' do result = Rainbow('hello').bright expect(result).to eq("\e[1mhello\e[0m") end it 'allows making text faint' do result = Rainbow('hello').faint expect(result).to eq("\e[2mhello\e[0m") end it 'allows making text italic' do result = Rainbow('hello').italic expect(result).to eq("\e[3mhello\e[0m") end it 'allows making text underlined' do result = Rainbow('hello').underline expect(result).to eq("\e[4mhello\e[0m") end it 'allows making text blinking' do result = Rainbow('hello').blink expect(result).to eq("\e[5mhello\e[0m") end it 'allows making text inversed' do result = Rainbow('hello').inverse expect(result).to eq("\e[7mhello\e[0m") end it 'allows making text hidden' do result = Rainbow('hello').hide expect(result).to eq("\e[8mhello\e[0m") end it 'allows resetting all the attributes' do result = Rainbow('hello').reset expect(result).to eq("\e[0mhello\e[0m") end it 'allows chaining' do result = Rainbow('hello'). foreground(:red). bright. bold. faint. dark. italic. background('#ff8040'). underline. color(:blue). blink. inverse. hide expect(result).to eq( "\e[31m\e[1m\e[1m\e[2m\e[2m\e[3m\e[48;5;215m\e[4m\e[34m\e[5m\e[7m\e[8mhello\e[0m" ) end context "when Rainbow is disabled" do before do Rainbow.enabled = false end it "allows chaining but doesn't wrap with escape codes" do result = Rainbow('hello'). foreground(:red). bright. bold. faint. dark. italic. background('#ff8040'). underline. color(:blue). blink. inverse. hide expect(result).to eq('hello') end end end ruby-rainbow-2.2.2/spec/integration/string_spec.rb000066400000000000000000000040261315132255300222610ustar00rootroot00000000000000require 'spec_helper' require 'rainbow/ext/string' describe 'String mixin' do before do Rainbow.enabled = true end it 'proxies foreground to Rainbow().foreground' do expect('hello'.foreground(:red)).to eq(Rainbow('hello').foreground(:red)) end it 'proxies color to Rainbow().color' do expect('hello'.color(:red)).to eq(Rainbow('hello').color(:red)) end it 'proxies x11 color to Rainbow().color' do expect('hello'.color(:midnightblue)).to eq(Rainbow('hello').color(:midnightblue)) end it 'proxies colour to Rainbow().colour' do expect('hello'.colour(:red)).to eq(Rainbow('hello').colour(:red)) end it 'proxies background to Rainbow().background' do expect('hello'.background(:red)).to eq(Rainbow('hello').background(:red)) end it 'proxies bright to Rainbow().bright' do expect('hello'.bright).to eq(Rainbow('hello').bright) end it 'proxies faint to Rainbow().faint' do expect('hello'.faint).to eq(Rainbow('hello').faint) end it 'proxies italic to Rainbow().italic' do expect('hello'.italic).to eq(Rainbow('hello').italic) end it 'proxies underline to Rainbow().underline' do expect('hello'.underline).to eq(Rainbow('hello').underline) end it 'proxies blink to Rainbow().blink' do expect('hello'.blink).to eq(Rainbow('hello').blink) end it 'proxies inverse to Rainbow().inverse' do expect('hello'.inverse).to eq(Rainbow('hello').inverse) end it 'proxies hide to Rainbow().hide' do expect('hello'.hide).to eq(Rainbow('hello').hide) end it 'proxies reset to Rainbow().reset' do expect('hello'.reset).to eq(Rainbow('hello').reset) end context "when Rainbow is disabled" do before do Rainbow.enabled = false end it "allows chaining but doesn't wrap with escape codes" do result = 'hello'. foreground(:red). bright. italic. background('#ff8040'). underline. color(:blue). blink. inverse. hide expect(result).to eq('hello') end end end ruby-rainbow-2.2.2/spec/spec_helper.rb000066400000000000000000000003021315132255300177000ustar00rootroot00000000000000if ENV["CI"] && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby") require 'coveralls' Coveralls.wear! end Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |file| require file } ruby-rainbow-2.2.2/spec/support/000077500000000000000000000000001315132255300166035ustar00rootroot00000000000000ruby-rainbow-2.2.2/spec/support/presenter_shared_examples.rb000066400000000000000000000004411315132255300243620ustar00rootroot00000000000000shared_examples_for "presenter with shortcut color methods" do [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :aqua].each do |name| describe "##{name}" do subject { presenter.public_send(name) } it { should eq(presenter.color(name)) } end end end ruby-rainbow-2.2.2/spec/unit/000077500000000000000000000000001315132255300160465ustar00rootroot00000000000000ruby-rainbow-2.2.2/spec/unit/color_spec.rb000066400000000000000000000152331315132255300205270ustar00rootroot00000000000000require 'spec_helper' require 'rainbow/color' module Rainbow describe Color do describe '.build' do subject { described_class.build(ground, values) } let(:ground) { :foreground } context "when single fixnum given" do let(:values) { [1] } it { should be_instance_of(Color::Indexed) } specify { expect(subject.ground).to eq(ground) } specify { expect(subject.num).to eq(1) } end context "when single ansi symbol given" do let(:values) { [:red] } it { should be_instance_of(Color::Named) } specify { expect(subject.ground).to eq(ground) } specify { expect(subject.num).to eq(1) } end context "when single x11 symbol given" do let(:values) { [:midnightblue] } it { should be_instance_of(Color::X11Named) } specify { expect(subject.ground).to eq(ground) } specify { expect(subject.r).to eq(25) } specify { expect(subject.g).to eq(25) } specify { expect(subject.b).to eq(112) } end context "when single string given" do let(:values) { ['#deadcc'] } it { should be_instance_of(Color::RGB) } specify { expect(subject.ground).to eq(ground) } specify { expect(subject.r).to eq(222) } specify { expect(subject.g).to eq(173) } specify { expect(subject.b).to eq(204) } end context "when 2 elements" do let(:values) { [1, 2] } it 'raises ArgumentError' do expect { subject }.to raise_error(ArgumentError) end end context "when 3 elements given" do let(:values) { [1, 2, 3] } it { should be_instance_of(Color::RGB) } specify { expect(subject.ground).to eq(ground) } specify { expect(subject.r).to eq(1) } specify { expect(subject.g).to eq(2) } specify { expect(subject.b).to eq(3) } end context "when 4 elements" do let(:values) { [1, 2, 3, 4] } it 'raises ArgumentError' do expect { subject }.to raise_error(ArgumentError) end end end end describe Color::Indexed do let(:color) { described_class.new(ground, 5) } describe '#codes' do subject { color.codes } context "when ground is :foreground" do let(:ground) { :foreground } it { should eq([35]) } end context "when ground is :background" do let(:ground) { :background } it { should eq([45]) } end end end describe Color::Named do let(:color) { described_class.new(ground, name) } describe '#codes' do subject { color.codes } context "when ground is :foreground" do let(:ground) { :foreground } context "and name is :black" do let(:name) { :black } it { should eq([30]) } end context "and name is :red" do let(:name) { :red } it { should eq([31]) } end context "and name is :green" do let(:name) { :green } it { should eq([32]) } end context "and name is :yellow" do let(:name) { :yellow } it { should eq([33]) } end context "and name is :blue" do let(:name) { :blue } it { should eq([34]) } end context "and name is :magenta" do let(:name) { :magenta } it { should eq([35]) } end context "and name is :cyan" do let(:name) { :cyan } it { should eq([36]) } end context "and name is :white" do let(:name) { :white } it { should eq([37]) } end context "and name is invalid" do let(:name) { :foo } it 'raises ArgumentError' do expect { subject }.to raise_error(ArgumentError) end end end context "when ground is :background" do let(:ground) { :background } context "and name is :black" do let(:name) { :black } it { should eq([40]) } end context "and name is :red" do let(:name) { :red } it { should eq([41]) } end context "and name is :green" do let(:name) { :green } it { should eq([42]) } end context "and name is :yellow" do let(:name) { :yellow } it { should eq([43]) } end context "and name is :blue" do let(:name) { :blue } it { should eq([44]) } end context "and name is :magenta" do let(:name) { :magenta } it { should eq([45]) } end context "and name is :cyan" do let(:name) { :cyan } it { should eq([46]) } end context "and name is :white" do let(:name) { :white } it { should eq([47]) } end context "and name is invalid" do let(:name) { :foo } it 'raises ArgumentError' do expect { subject }.to raise_error(ArgumentError) end end end end end describe Color::RGB do let(:color) { described_class.new(ground, r, g, b) } describe '#codes' do subject { color.codes } let(:ground) { :foreground } let(:r) { 0 } let(:g) { 128 } let(:b) { 255 } context "when ground is :foreground" do let(:ground) { :foreground } it { should eq([38, 5, 39]) } end context "when ground is :background" do let(:ground) { :background } it { should eq([48, 5, 39]) } end context "when a component is lower than 0" do let(:r) { -1 } it 'raises ArgumentError' do expect { subject }.to raise_error(ArgumentError) end end context "when a component is greater than 255" do let(:b) { 256 } it 'raises ArgumentError' do expect { subject }.to raise_error(ArgumentError) end end end end describe Color::X11Named do let(:color) { described_class.new(ground, name) } describe '#codes' do subject { color.codes } context "when ground is :foreground" do let(:name) { :midnightblue } let(:ground) { :foreground } it { should eq([38, 5, 18]) } end context "when ground is :background" do let(:name) { :midnightblue } let(:ground) { :background } it { should eq([48, 5, 18]) } end context "when name is invalid" do let(:name) { :foo } let(:ground) { :background } it 'raises ArgumentError' do expect { subject }.to raise_error(ArgumentError) end end end end end ruby-rainbow-2.2.2/spec/unit/namespace_spec.rb000066400000000000000000000011001315132255300213310ustar00rootroot00000000000000require 'spec_helper' require 'rainbow' describe Sickill::Rainbow do describe '.enabled' do before do ::Rainbow.enabled = :nope end it 'returns ::Rainbow.enabled' do expect(Sickill::Rainbow.enabled).to eq(:nope) end end describe '.enabled=' do before do allow(STDERR).to receive(:puts) Sickill::Rainbow.enabled = :yep end it 'sets ::Rainbow.enabled=' do expect(::Rainbow.enabled).to eq(:yep) end it 'prints the deprecation notice' do expect(STDERR).to have_received(:puts) end end end ruby-rainbow-2.2.2/spec/unit/null_presenter_spec.rb000066400000000000000000000045661315132255300224610ustar00rootroot00000000000000require 'spec_helper' require 'rainbow/null_presenter' module Rainbow describe NullPresenter do let(:presenter) { described_class.new('hello') } shared_examples_for "rainbow null string method" do it "doesn't wrap the text with any sgr sequence" do expect(subject).to eq('hello') end it "returns an instance of Rainbow::NullPresenter" do expect(subject).to be_kind_of(Rainbow::NullPresenter) end end describe '#color' do subject { presenter.color(:arg1, 'arg2') } it_behaves_like "rainbow null string method" end describe '#foreground' do subject { presenter.foreground(:arg1, 'arg2') } it_behaves_like "rainbow null string method" end describe '#fg' do subject { presenter.fg(:arg1, 'arg2') } it_behaves_like "rainbow null string method" end describe '#background' do subject { presenter.background(:arg1, 'arg2') } it_behaves_like "rainbow null string method" end describe '#bg' do subject { presenter.bg(:arg1, 'arg2') } it_behaves_like "rainbow null string method" end describe '#reset' do subject { presenter.reset } it_behaves_like "rainbow null string method" end describe '#bright' do subject { presenter.bright } it_behaves_like "rainbow null string method" end describe '#bold' do subject { presenter.bold } it_behaves_like "rainbow null string method" end describe '#faint' do subject { presenter.faint } it_behaves_like "rainbow null string method" end describe '#dark' do subject { presenter.dark } it_behaves_like "rainbow null string method" end describe '#italic' do subject { presenter.italic } it_behaves_like "rainbow null string method" end describe '#underline' do subject { presenter.underline } it_behaves_like "rainbow null string method" end describe '#blink' do subject { presenter.blink } it_behaves_like "rainbow null string method" end describe '#inverse' do subject { presenter.inverse } it_behaves_like "rainbow null string method" end describe '#hide' do subject { presenter.hide } it_behaves_like "rainbow null string method" end it_behaves_like "presenter with shortcut color methods" end end ruby-rainbow-2.2.2/spec/unit/presenter_spec.rb000066400000000000000000000111061315132255300214130ustar00rootroot00000000000000require 'spec_helper' require 'rainbow/presenter' module Rainbow describe Presenter do let(:presenter) { described_class.new('hello') } shared_examples_for "rainbow string method" do it "wraps the text with a sgr sequence" do expect(subject).to eq('[hello]') end it "returns an instance of Rainbow::Presenter" do expect(subject).to be_kind_of(Rainbow::Presenter) end end shared_examples_for "text color method" do let(:color) { double('color', codes: [1, 2]) } before do allow(Color).to receive(:build). with(:foreground, [:arg1, 'arg2']) { color } end it_behaves_like "rainbow string method" it 'wraps with color codes' do subject expect(StringUtils).to have_received(:wrap_with_sgr). with('hello', [1, 2]) end end shared_examples_for "text background method" do let(:color) { double('color', codes: [1, 2]) } before do allow(Color).to receive(:build). with(:background, [:arg1, 'arg2']) { color } end it_behaves_like "rainbow string method" it 'wraps with color codes' do subject expect(StringUtils).to have_received(:wrap_with_sgr). with('hello', [1, 2]) end end before do allow(StringUtils).to receive(:wrap_with_sgr) { '[hello]' } end describe '#color' do subject { presenter.color(:arg1, 'arg2') } it_behaves_like "text color method" end describe '#foreground' do subject { presenter.foreground(:arg1, 'arg2') } it_behaves_like "text color method" end describe '#fg' do subject { presenter.fg(:arg1, 'arg2') } it_behaves_like "text color method" end describe '#background' do subject { presenter.background(:arg1, 'arg2') } it_behaves_like "text background method" end describe '#bg' do subject { presenter.bg(:arg1, 'arg2') } it_behaves_like "text background method" end describe '#reset' do subject { presenter.reset } it_behaves_like "rainbow string method" it 'wraps with 0 code' do subject expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [0]) end end describe '#bright' do subject { presenter.bright } it_behaves_like "rainbow string method" it 'wraps with 1 code' do subject expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [1]) end end describe '#bold' do subject { presenter.bold } it_behaves_like "rainbow string method" it 'wraps with 1 code' do subject expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [1]) end end describe '#faint' do subject { presenter.faint } it_behaves_like "rainbow string method" it 'wraps with 2 code' do subject expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [2]) end end describe '#dark' do subject { presenter.dark } it_behaves_like "rainbow string method" it 'wraps with 2 code' do subject expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [2]) end end describe '#italic' do subject { presenter.italic } it_behaves_like "rainbow string method" it 'wraps with 3 code' do subject expect(StringUtils).to have_received(:wrap_with_sgr). with('hello', [3]) end end describe '#underline' do subject { presenter.underline } it_behaves_like "rainbow string method" it 'wraps with 4 code' do subject expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [4]) end end describe '#blink' do subject { presenter.blink } it_behaves_like "rainbow string method" it 'wraps with 5 code' do subject expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [5]) end end describe '#inverse' do subject { presenter.inverse } it_behaves_like "rainbow string method" it 'wraps with 7 code' do subject expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [7]) end end describe '#hide' do subject { presenter.hide } it_behaves_like "rainbow string method" it 'wraps with 8 code' do subject expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [8]) end end it_behaves_like "presenter with shortcut color methods" end end ruby-rainbow-2.2.2/spec/unit/string_utils_spec.rb000066400000000000000000000030371315132255300221360ustar00rootroot00000000000000require 'spec_helper' require 'rainbow/string_utils' module Rainbow describe StringUtils do describe '.wrap_with_sgr' do subject { described_class.wrap_with_sgr(string, codes) } let(:string) { 'hello' } let(:codes) { [1] } it "doesn't mutate original string" do string.freeze expect(subject).to eq("\e[1mhello\e[0m") expect(string).to eq('hello') end context "when subclass of String class given" do class Stringgg < ::String; end let(:string) { Stringgg.new('hello') } it { should eq("\e[1mhello\e[0m") } end context "when no codes given" do let(:codes) { [] } it "doesn't wrap the given string with any sgr sequence" do expect(subject).to eq("hello") end end context "when single code given" do let(:codes) { [1] } it "wraps the given string with sgr sequence for given codes" do expect(subject).to eq("\e[1mhello\e[0m") end end context "when multiple codes given" do let(:codes) { [1, 2] } it "wraps the given string with sgr sequence for given codes" do expect(subject).to eq("\e[1;2mhello\e[0m") end end context "when wrapping an already wrapped string" do let(:string) { "\e[1;2mhello\e[0m" } let(:codes) { [3, 4] } it "wraps the given string with sgr sequence for given codes" do expect(subject).to eq("\e[1;2m\e[3;4mhello\e[0m") end end end end end ruby-rainbow-2.2.2/spec/unit/wrapper_spec.rb000066400000000000000000000013131315132255300210630ustar00rootroot00000000000000require 'spec_helper' require 'rainbow/wrapper' module Rainbow describe Wrapper do let(:wrapper) { described_class.new(enabled) } it "is enabled by default" do expect(described_class.new.enabled).to be(true) end describe '#wrap' do subject { wrapper.wrap(object) } let(:object) { Object.new } context "when wrapping is enabled" do let(:enabled) { true } it { should eq(object.to_s) } it { should be_kind_of(Rainbow::Presenter) } end context "when wrapping is disabled" do let(:enabled) { false } it { should eq(object.to_s) } it { should be_kind_of(Rainbow::NullPresenter) } end end end end