Skip to content

Commit

Permalink
Merge 1744e7d into e4d7bc4
Browse files Browse the repository at this point in the history
  • Loading branch information
olleolleolle committed May 15, 2017
2 parents e4d7bc4 + 1744e7d commit c877c88
Show file tree
Hide file tree
Showing 25 changed files with 205 additions and 163 deletions.
9 changes: 6 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
Documentation:
Enabled: false
inherit_from: .rubocop_todo.yml

EmptyLinesAroundBody:
AllCops:
TargetRubyVersion: "2.1"
Exclude:
- "spec/**/*"
Documentation:
Enabled: false

HashSyntax:
Expand Down
41 changes: 41 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-05-15 22:22:19 +0200 using RuboCop version 0.48.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
Metrics/AbcSize:
Max: 25

# Offense count: 1
Metrics/CyclomaticComplexity:
Max: 9

# Offense count: 2
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 85

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 23

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 147

# Offense count: 1
Metrics/PerceivedComplexity:
Max: 8

# Offense count: 2
Style/MethodMissing:
Exclude:
- 'lib/rainbow/null_presenter.rb'
- 'lib/rainbow/presenter.rb'
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in rainbow.gemspec
gemspec

gem 'rake'
gem 'coveralls', require: false
gem 'rake'
gem 'rspec'

group :development do
Expand Down
1 change: 0 additions & 1 deletion Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ guard :rspec, cmd: 'rspec --color' do
watch(%r{^lib/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
end

2 changes: 0 additions & 2 deletions lib/rainbow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
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'

end
37 changes: 14 additions & 23 deletions lib/rainbow/color.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module 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"
raise ArgumentError,
"Wrong number of arguments for color definition, should be 1 or 3"
end

color = values.size == 1 ? values.first : values
Expand All @@ -25,9 +24,9 @@ def self.build(ground, values)
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(', ')
raise ArgumentError,
"Unknown color name, valid names: " +
(Named.color_names + X11Named.color_names).join(', ')
end
when Array
RGB.new(ground, *color)
Expand All @@ -46,7 +45,6 @@ def self.parse_hex_color(hex)
end

class Indexed < Color

attr_reader :num

def initialize(ground, num)
Expand All @@ -59,11 +57,9 @@ def codes

[code]
end

end

class Named < Indexed

NAMES = {
black: 0,
red: 1,
Expand All @@ -73,26 +69,24 @@ class Named < Indexed
magenta: 5,
cyan: 6,
white: 7,
default: 9,
}
default: 9
}.freeze

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(', ')}"
raise 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)
Expand All @@ -101,7 +95,7 @@ def self.to_ansi_domain(value)

def initialize(ground, *values)
if values.min < 0 || values.max > 255
fail ArgumentError, "RGB value outside 0-255 range"
raise ArgumentError, "RGB value outside 0-255 range"
end

super(ground, 8)
Expand All @@ -116,10 +110,9 @@ def codes

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)
self.class.to_ansi_domain(g) * 6 +
self.class.to_ansi_domain(b)
end

end

class X11Named < RGB
Expand All @@ -131,14 +124,12 @@ def self.color_names

def initialize(ground, name)
unless X11Named.color_names.include?(name)
fail ArgumentError,
"Unknown color name, valid names: #{X11Named.color_names.join(', ')}"
raise ArgumentError,
"Unknown color name, valid names: #{X11Named.color_names.join(', ')}"
end

super(ground, *NAMES[name])
end

end

end
end
6 changes: 2 additions & 4 deletions lib/rainbow/ext/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ module Rainbow
module Ext
module String
module InstanceMethods

def foreground(*color)
Rainbow(self).foreground(*color)
end

alias_method :color, :foreground
alias_method :colour, :foreground
alias color foreground
alias colour foreground

def background(*color)
Rainbow(self).background(*color)
Expand Down Expand Up @@ -47,7 +46,6 @@ def inverse
def hide
Rainbow(self).hide
end

end
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/rainbow/global.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require_relative 'wrapper'

module Rainbow

def self.global
@global ||= Wrapper.new
end
Expand All @@ -13,7 +12,6 @@ def self.enabled
def self.enabled=(value)
global.enabled = value
end

end

def Rainbow(string)
Expand Down
2 changes: 0 additions & 2 deletions lib/rainbow/legacy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Sickill
module Rainbow

def self.enabled=(value)
STDERR.puts("Rainbow gem notice: Sickill::Rainbow.enabled= is " \
"deprecated, use Rainbow.enabled= instead.")
Expand All @@ -10,6 +9,5 @@ def self.enabled=(value)
def self.enabled
::Rainbow.enabled
end

end
end
108 changes: 78 additions & 30 deletions lib/rainbow/null_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,89 @@
module 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 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
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) && args.empty?
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

alias foreground color
alias fg color
alias bg background
alias bold bright
alias dark faint
end

end
Loading

0 comments on commit c877c88

Please sign in to comment.