colored2 3.1.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 924031901113f03f0694ea75208745920d7f38ab
4
- data.tar.gz: 835ee416fa88d5d903546a021da1e0792d6529fc
2
+ SHA256:
3
+ metadata.gz: 931fcb1dc0aebdc4cee8c0b71849879b22878076547172885d4a15fc6bd19e80
4
+ data.tar.gz: 07263f510c64006915085ba83c1c4ca84e16208c93ebe9696a4802eb6f4afb59
5
5
  SHA512:
6
- metadata.gz: '008631053e811a6694c199ddc6c0c5b2636c7c863a5a794835766effb93cb9afea9af5a51802f8b9943a206138b9555002b33e68eeb148b9f05ded8fc6fe2f5f'
7
- data.tar.gz: a3d40c57634d3753a2dcd9073f6841ef2f40d1b21b1a141a34ade7eff762a934e878f2e8b91051c0f072e8b392cff5abd77456b6415d2d0cb4f28fbcb4c473f8
6
+ metadata.gz: 7434349bb14787804acb8cf8692e522f0accf8d751ef45672bce10171ad4bce61318df04676af58dbf64a5fbe399e89f1b741e7ba6b0c5c8b608db7a42085874
7
+ data.tar.gz: 3a8a6bf7fe16badb197728f645c8e16c5c48f7f933e3c2e5d68a2b1dbdc24c6706638a8d39ae1fc38dec68a4f1348c2db673c6d21a80b5f314355b95a6601ff5
data/README.md CHANGED
@@ -1,18 +1,21 @@
1
+
2
+ [![RSpecs](https://github.com/kigster/colored2/actions/workflows/ruby-ci.yml/badge.svg)](https://github.com/kigster/colored2/actions/workflows/ruby-ci.yml)
3
+ [![Rubocop](https://github.com/kigster/colored2/actions/workflows/rubocop-ci.yml/badge.svg)](https://github.com/kigster/colored2/actions/workflows/rubocop-ci.yml)
4
+
1
5
  [![Gem Version](https://badge.fury.io/rb/colored2.svg)](https://badge.fury.io/rb/colored2)
2
- [![Downloads](http://ruby-gem-downloads-badge.herokuapp.com/colored2?type=total)](https://rubygems.org/gems/colored2)
3
6
  [![Gitter](https://img.shields.io/gitter/room/gitterHQ/gitter.svg)](https://gitter.im/colored2)
4
7
 
5
- [![Build Status](https://travis-ci.org/kigster/colored2.svg?branch=master)](https://travis-ci.org/kigster/colored2)
6
- [![Test Coverage](https://codeclimate.com/github/kigster/colored2/badges/coverage.svg)](https://codeclimate.com/github/kigster/colored2/coverage)
7
- [![Code Climate](https://codeclimate.com/github/kigster/colored2/badges/gpa.svg)](https://codeclimate.com/github/kigster/colored2)
8
- [![Issue Count](https://codeclimate.com/github/kigster/colored2/badges/issue_count.svg)](https://codeclimate.com/github/kigster/colored2)
9
-
10
8
  ## Colored2
11
9
 
12
10
  This is an actively maintained fork of Chris (defunkt) Wanstrath's gem [colored](https://github.com/defunkt/colored), which appears to be no longer supported.
13
11
 
14
12
  This fork comes with a slightly spruced up syntax, some additional features, and a test suite written in [RSpec](http://rspec.info/).
15
13
 
14
+ ## Please Consider Donating
15
+
16
+ <a href="https://liberapay.com/kigster/donate"><img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg" height="30"></a>
17
+ <a href="https://liberapay.com/kigster/donate"><img alt="Donate using Liberapay" src="https://img.shields.io/liberapay/goal/kigster.svg" height="30"></a>
18
+
16
19
  ## Usage
17
20
 
18
21
  In addition to the simple syntax of the original gem, which affected only the string to the left of the method call, the new "bang" syntax affects a string to the right. If the block or a method argument is provided, the contents is wrapped in the color, and the color is then reset back.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  require 'bundler'
2
4
  require 'bundler/gem_tasks'
3
5
  require 'rake/clean'
@@ -7,7 +9,9 @@ CLEAN.include %w(pkg coverage *.gem)
7
9
  begin
8
10
  require 'rspec/core/rake_task'
9
11
  RSpec::Core::RakeTask.new(:spec)
10
- rescue LoadError
12
+ rescue LoadError => e
13
+ warn "Error loading task: #{e.message}"
14
+ exit 1
11
15
  end
12
16
 
13
- task :default => [:spec]
17
+ task default: [:spec]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  require 'colored2/codes'
2
4
  require 'forwardable'
3
5
 
@@ -5,15 +7,19 @@ module Colored2
5
7
  def self.enable!
6
8
  Colored2::AsciiDecorator.enable!
7
9
  end
10
+
8
11
  def self.disable!
9
12
  Colored2::AsciiDecorator.disable!
10
13
  end
14
+
11
15
  def self.background_next!
12
16
  Colored2::AsciiDecorator.background_next!
13
17
  end
18
+
14
19
  def self.foreground_next!
15
20
  Colored2::AsciiDecorator.foreground_next!
16
21
  end
22
+
17
23
  def self.background_next?
18
24
  Colored2::AsciiDecorator.background_next?
19
25
  end
@@ -23,23 +29,29 @@ module Colored2
23
29
  @__colors_disabled = false
24
30
  class << self
25
31
  attr_accessor :__background_next, :__colors_disabled
32
+
26
33
  def enable!
27
34
  self.__colors_disabled = false
28
35
  end
36
+
29
37
  def enabled?
30
- !self.__colors_disabled
38
+ !__colors_disabled
31
39
  end
40
+
32
41
  def disable!
33
42
  self.__colors_disabled = true
34
43
  end
44
+
35
45
  def background_next!
36
46
  self.__background_next = true
37
47
  end
48
+
38
49
  def foreground_next!
39
50
  self.__background_next = false
40
51
  end
52
+
41
53
  def background_next?
42
- self.__background_next
54
+ __background_next
43
55
  end
44
56
  end
45
57
 
@@ -56,7 +68,8 @@ module Colored2
56
68
  # options[:start] = :color
57
69
  # options[:end] = :color | :no_color
58
70
  def decorate(options = {})
59
- return string if !self.class.enabled? || string.length == 0
71
+ return string if !self.class.enabled? || string.empty?
72
+
60
73
  escape_sequence = [
61
74
  Colored2::TextColor.new(options[:foreground]),
62
75
  Colored2::BackgroundColor.new(options[:background]),
@@ -74,7 +87,7 @@ module Colored2
74
87
  end
75
88
 
76
89
  def un_decorate
77
- string.gsub(%r{\e\[\d+(;\d+)*m}, '')
90
+ string.gsub(/\e\[\d+(;\d+)*m/, '')
78
91
  end
79
92
 
80
93
  private
@@ -1,34 +1,37 @@
1
- module Colored2
1
+ # frozen_string_literal: false
2
2
 
3
- COLORS = {
4
- black: 30,
5
- red: 31,
6
- green: 32,
7
- yellow: 33,
8
- blue: 34,
9
- magenta: 35,
10
- cyan: 36,
11
- white: 37
12
- }
3
+ module Colored2
4
+ COLORS = {
5
+ black: 30,
6
+ red: 31,
7
+ green: 32,
8
+ yellow: 33,
9
+ blue: 34,
10
+ magenta: 35,
11
+ cyan: 36,
12
+ white: 37
13
+ }.freeze
13
14
 
14
15
  EFFECTS = {
15
- no_color: 0,
16
- bold: 1,
17
- dark: 2,
18
- italic: 3,
16
+ no_color: 0,
17
+ bold: 1,
18
+ dark: 2,
19
+ italic: 3,
19
20
  underlined: 4,
20
- reversed: 7,
21
- plain: 21, # non-bold
22
- normal: 22
23
- }
21
+ reversed: 7,
22
+ plain: 21, # non-bold
23
+ normal: 22
24
+ }.freeze
24
25
 
25
26
  class Code
26
27
  attr_accessor :name, :escape
28
+
27
29
  def initialize(name)
28
30
  @name = name
29
31
  return if name.nil?
32
+
30
33
  @escape = codes[name.to_sym]
31
- raise ArgumentError.new("No color or effect named #{name} exists for #{self.class}.") if @escape.nil?
34
+ raise ArgumentError, "No color or effect named #{name} exists for #{self.class}." if @escape.nil?
32
35
  end
33
36
 
34
37
  def value(shift = nil)
@@ -59,5 +62,4 @@ module Colored2
59
62
  super 10
60
63
  end
61
64
  end
62
-
63
65
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: false
2
+
1
3
  require 'colored2' unless defined?(Colored2) && Colored2.respond_to?(:decorate)
2
4
 
3
5
  module Colored2
4
6
  def self.integer_class
5
- major, minor = RUBY_VERSION.split(/\./).map(&:to_i)
6
- major >= 2 && minor >= 4 ? Integer : Kernel.const_get(:Fixnum)
7
+ major, minor = RUBY_VERSION.split(".").map(&:to_i)
8
+ major >= 2 && minor >= 4 ? Integer : Numeric
7
9
  end
8
10
  end
9
11
 
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: false
2
+
1
3
  require 'colored2' unless defined?(Colored2) && Colored2.respond_to?(:decorate)
2
4
  Colored2.decorate(Object)
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: false
2
+
1
3
  require 'colored2' unless defined?(Colored2) && Colored2.respond_to?(:decorate)
2
4
  Colored2.decorate(String)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Colored2
2
- VERSION = '3.1.2'
4
+ VERSION = '4.0.0'
3
5
  end
data/lib/colored2.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  require 'colored2/codes'
2
4
  require 'colored2/ascii_decorator'
3
5
 
@@ -8,7 +10,6 @@ module Colored2
8
10
 
9
11
  def self.included(from_class)
10
12
  from_class.class_eval do
11
-
12
13
  def surround_with_color(color: nil, effect: nil, color_self: nil, string: nil, &block)
13
14
  color_type = if Colored2.background_next? && effect.nil?
14
15
  Colored2.foreground_next!
@@ -17,23 +18,23 @@ module Colored2
17
18
  :foreground
18
19
  end
19
20
 
20
- opts = {}
21
- opts.merge!(color_type => color) if color
22
- opts.merge!(effect: effect) if effect
21
+ opts = {}
22
+ opts.merge!(color_type => color) if color
23
+ opts.merge!(effect:) if effect
23
24
 
24
- if color_self then
25
+ if color_self
25
26
  opts.merge!( beginning: :on, end: :off)
26
27
  colored = Colored2::AsciiDecorator.new(self).decorate(opts)
27
28
  if string || block
28
- arg = "#{string}#{block.call if block}"
29
- colored << Colored2::AsciiDecorator.new(arg).decorate(opts) if arg.length > 0
29
+ arg = "#{string}#{block&.call}"
30
+ colored << Colored2::AsciiDecorator.new(arg).decorate(opts) if !arg.empty?
30
31
  end
31
32
  else
32
33
  opts.merge!( end: :on )
33
34
  colored = Colored2::AsciiDecorator.new(self).decorate(opts)
34
35
  if string || block
35
- arg = "#{string}#{block.call if block}"
36
- colored << Colored2::AsciiDecorator.new(arg).decorate(opts.merge(end: :off)) if arg.length > 0
36
+ arg = "#{string}#{block&.call}"
37
+ colored << Colored2::AsciiDecorator.new(arg).decorate(opts.merge(end: :off)) if !arg.empty?
37
38
  end
38
39
  end
39
40
  colored
@@ -46,24 +47,25 @@ module Colored2
46
47
  end
47
48
 
48
49
  from_class.instance_eval do
49
- COLORS.keys.each do |color|
50
+ COLORS.each_key do |color|
50
51
  define_method(color) do |string = nil, &block|
51
- surround_with_color(color: color, color_self: true, string: string, &block)
52
+ surround_with_color(color:, color_self: true, string:, &block)
52
53
  end
53
54
 
54
55
  define_method("#{color}!".to_sym) do |string = nil, &block|
55
- surround_with_color(color: color, color_self: false, string: string, &block)
56
+ surround_with_color(color:, color_self: false, string:, &block)
56
57
  end
57
58
  end
58
59
 
59
- EFFECTS.keys.each do |effect|
60
+ EFFECTS.each_key do |effect|
60
61
  next if effect == 'no_color'
62
+
61
63
  define_method(effect) do |string = nil, &block|
62
- surround_with_color(effect: effect, color_self: true, string: string, &block)
64
+ surround_with_color(effect:, color_self: true, string:, &block)
63
65
  end
64
66
 
65
67
  define_method("#{effect}!".to_sym) do |string = nil, &block|
66
- surround_with_color(effect: effect, color_self: false, string: string, &block)
68
+ surround_with_color(effect:, color_self: false, string:, &block)
67
69
  end
68
70
  end
69
71
 
@@ -72,6 +74,7 @@ module Colored2
72
74
  if tmp == self
73
75
  return "\e[2K" << self
74
76
  end
77
+
75
78
  tmp
76
79
  end
77
80
 
metadata CHANGED
@@ -1,58 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colored2
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
8
8
  - Konstantin Gredeskoul
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-14 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rake
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '10.0'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '10.0'
28
- - !ruby/object:Gem::Dependency
29
- name: rspec
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '3.4'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '3.4'
42
- - !ruby/object:Gem::Dependency
43
- name: codeclimate-test-reporter
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
12
+ date: 2023-08-24 00:00:00.000000000 Z
13
+ dependencies: []
56
14
  description: |+
57
15
  This is a heavily modified fork of http://github.com/defunkt/colored gem, with many
58
16
  sensible pull requests combined. Since the authors of the original gem no longer support it,
@@ -89,16 +47,12 @@ files:
89
47
  - lib/colored2/object.rb
90
48
  - lib/colored2/strings.rb
91
49
  - lib/colored2/version.rb
92
- - spec/colored2/numbers_spec.rb
93
- - spec/colored2/object_spec.rb
94
- - spec/colored2/strings_spec.rb
95
- - spec/colored2_spec.rb
96
- - spec/spec_helper.rb
97
50
  homepage: http://github.com/kigster/colored2
98
51
  licenses:
99
52
  - MIT
100
- metadata: {}
101
- post_install_message:
53
+ metadata:
54
+ rubygems_mfa_required: 'true'
55
+ post_install_message:
102
56
  rdoc_options: []
103
57
  require_paths:
104
58
  - lib
@@ -106,21 +60,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
60
  requirements:
107
61
  - - ">="
108
62
  - !ruby/object:Gem::Version
109
- version: 2.0.0
63
+ version: '3.1'
110
64
  required_rubygems_version: !ruby/object:Gem::Requirement
111
65
  requirements:
112
66
  - - ">="
113
67
  - !ruby/object:Gem::Version
114
- version: 1.3.6
68
+ version: '0'
115
69
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.6.8
118
- signing_key:
70
+ rubygems_version: 3.4.13
71
+ signing_key:
119
72
  specification_version: 4
120
73
  summary: Add even more color to your life.
121
- test_files:
122
- - spec/colored2/numbers_spec.rb
123
- - spec/colored2/object_spec.rb
124
- - spec/colored2/strings_spec.rb
125
- - spec/colored2_spec.rb
126
- - spec/spec_helper.rb
74
+ test_files: []
75
+ ...
@@ -1,26 +0,0 @@
1
- require File.expand_path('spec/spec_helper')
2
- require 'colored2/numbers'
3
- require 'colored2/strings'
4
-
5
- RSpec.describe Colored2.integer_class do
6
- describe 'with foreground and background colors' do
7
- it 'should work with one color' do
8
- expect(32.red).to eql('32'.red)
9
- end
10
- it 'should insert escape sequences' do
11
- expect(32.red).to eql("\e[31m32\e[0m")
12
- end
13
- end
14
- end
15
-
16
- RSpec.describe Float do
17
- describe 'with foreground and background colors' do
18
- it 'should add two colors chained' do
19
- expect((32.5).blue.on.red).to eql('32.5'.blue.on.red)
20
- end
21
-
22
- it 'should insert escape sequences' do
23
- expect((32.5).blue.on.red).to eql("\e[41m\e[34m32.5\e[0m")
24
- end
25
- end
26
- end
@@ -1,24 +0,0 @@
1
- require File.expand_path('spec/spec_helper')
2
- require 'colored2/object'
3
-
4
- subject1 = red('hello')
5
- subject2 = red('blue').on.blue
6
- subject3 = on.yellow('on yellow')
7
-
8
- RSpec.describe Object do
9
-
10
- describe 'with foreground and background colors' do
11
- it 'should work with one color' do
12
- expect(subject1).to eql('hello'.red)
13
- end
14
-
15
- it 'should work with color on color' do
16
- expect(subject2).to eql('blue'.red.on.blue)
17
- end
18
-
19
- it 'should add background color using on_<color>' do
20
- expect(subject3).to eql('on yellow'.on.yellow)
21
- end
22
-
23
- end
24
- end
@@ -1,77 +0,0 @@
1
- require File.expand_path('spec/spec_helper')
2
- require 'colored2/strings'
3
-
4
- RSpec.describe String do
5
- before do
6
- Colored2.decorate(String)
7
- end
8
-
9
- describe 'with foreground and background colors' do
10
- it 'should work with one color' do
11
- expect('red'.red).to eql("\e[31mred\e[0m")
12
- end
13
-
14
- it 'should add two colors chained' do
15
- expect('blue'.red.blue).to eql("\e[34m\e[31mblue\e[0m")
16
- end
17
-
18
- it 'should add background color using on_<color>' do
19
- expect('on yellow'.on.yellow).to eql("\e[43mon yellow\e[0m")
20
- end
21
-
22
- it 'should work with <color>_on_<color> syntax' do
23
- expect('red on blue'.red.on.blue).to eql("\e[44m\e[31mred on blue\e[0m")
24
- end
25
- end
26
-
27
- describe 'with effects' do
28
- it 'should add a bold modifier' do
29
- expect('way bold'.bold).to eql("\e[1mway bold\e[0m")
30
- end
31
-
32
- it 'should let modifiers stack' do
33
- expect('underlinedd bold'.bold.underlined).to eql("\e[4m\e[1munderlinedd bold\e[0m")
34
- end
35
-
36
- it 'should let modifiers stack with colors' do
37
- expect('cyan underlinedd bold'.bold.underlined.cyan).to eql("\e[36m\e[4m\e[1mcyan underlinedd bold\e[0m")
38
- end
39
- end
40
-
41
- describe 'new block syntax' do
42
- it 'should defined block syntax nested colors' do
43
- expect('No Color, then'.blue!('blue inside')).to eql('No Color, then' + 'blue inside'.blue)
44
- end
45
-
46
- it 'should defined block syntax nested colors two levels deep' do
47
- expect('regular here'.blue! + 'blue here'.no_color!).to eql('regular here' << 'blue here'.blue)
48
- end
49
-
50
- it 'should defined block syntax nested colors two levels deep' do
51
- expect('regular here'.blue! { 'something else'.red!('red riding hood') }).to eql('regular here'.blue! << 'something else'.red! << 'red riding hood'.no_color!)
52
- end
53
-
54
- it 'should defined block syntax nested colors two levels deep' do
55
- expectation = 'this is regular, but '.red! do
56
- 'this is red '.yellow! do
57
- ' and yellow'.no_color!
58
- end
59
- end
60
- expect(expectation).to eql('this is regular, but '.red! << 'this is red '.yellow! << ' and yellow'.no_color!)
61
- end
62
- end
63
-
64
- describe 'end of line' do
65
- it 'should work with eol' do
66
- expect('nothing to see here really.'.to_eol).to eql("\e[2Knothing to see here really.")
67
- end
68
-
69
- it 'should work with eol_with_with_two_colors' do
70
- expect('blue'.red.blue.to_eol).to eql("\e[34m\e[31m\e[2Kblue\e[0m")
71
- end
72
-
73
- it 'should work with eol_with_modifiers_stack_with_colors' do
74
- expect('cyan underlinedd bold'.bold.underlined.cyan.to_eol).to eql("\e[36m\e[4m\e[1m\e[2Kcyan underlinedd bold\e[0m")
75
- end
76
- end
77
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
- require 'colored2/strings'
3
-
4
- RSpec.describe Colored2 do
5
- describe 'global enable and disable' do
6
- before do
7
- Colored2.disable!
8
- end
9
- after do
10
- Colored2.enable!
11
- end
12
- let(:sample) { 'sample string' }
13
-
14
- describe 'colors' do
15
- subject { sample.red.on.blue }
16
- it { should eql(sample) }
17
- end
18
- describe 'effects' do
19
- subject { sample.bold.on.red }
20
- it { should eql(sample) }
21
- end
22
- end
23
- end
data/spec/spec_helper.rb DELETED
@@ -1,5 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start
3
-
4
- require 'rspec/core'
5
-