pastel 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +57 -13
  3. data/README.md +36 -29
  4. data/lib/pastel.rb +17 -19
  5. data/lib/pastel/alias_importer.rb +9 -7
  6. data/lib/pastel/ansi.rb +2 -2
  7. data/lib/pastel/color.rb +63 -23
  8. data/lib/pastel/color_parser.rb +24 -18
  9. data/lib/pastel/color_resolver.rb +3 -1
  10. data/lib/pastel/decorator_chain.rb +47 -7
  11. data/lib/pastel/delegator.rb +57 -26
  12. data/lib/pastel/detached.rb +41 -5
  13. data/lib/pastel/version.rb +2 -2
  14. metadata +27 -97
  15. data/.gitignore +0 -22
  16. data/.rspec +0 -3
  17. data/.travis.yml +0 -26
  18. data/Gemfile +0 -16
  19. data/Rakefile +0 -8
  20. data/appveyor.yml +0 -23
  21. data/assets/pastel_logo.png +0 -0
  22. data/assets/screenshot.png +0 -0
  23. data/benchmarks/nesting_speed.rb +0 -41
  24. data/benchmarks/speed.rb +0 -45
  25. data/examples/palette.rb +0 -14
  26. data/pastel.gemspec +0 -26
  27. data/spec/spec_helper.rb +0 -45
  28. data/spec/unit/alias_color_spec.rb +0 -24
  29. data/spec/unit/alias_importer_spec.rb +0 -29
  30. data/spec/unit/color/alias_color_spec.rb +0 -40
  31. data/spec/unit/color/code_spec.rb +0 -24
  32. data/spec/unit/color/colored_spec.rb +0 -15
  33. data/spec/unit/color/decorate_spec.rb +0 -79
  34. data/spec/unit/color/equal_spec.rb +0 -22
  35. data/spec/unit/color/lookup_spec.rb +0 -17
  36. data/spec/unit/color/new_spec.rb +0 -10
  37. data/spec/unit/color/strip_spec.rb +0 -56
  38. data/spec/unit/color/styles_spec.rb +0 -10
  39. data/spec/unit/color/valid_spec.rb +0 -19
  40. data/spec/unit/color_parser_spec.rb +0 -67
  41. data/spec/unit/decorate_dsl_spec.rb +0 -98
  42. data/spec/unit/decorator_chain_spec.rb +0 -47
  43. data/spec/unit/delegator_spec.rb +0 -38
  44. data/spec/unit/detach_spec.rb +0 -48
  45. data/spec/unit/new_spec.rb +0 -63
  46. data/spec/unit/respond_to_spec.rb +0 -17
  47. data/spec/unit/undecorate_spec.rb +0 -12
  48. data/tasks/console.rake +0 -11
  49. data/tasks/coverage.rake +0 -11
  50. data/tasks/spec.rake +0 -29
data/.gitignore DELETED
@@ -1,22 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --require spec_helper
3
- --warnings
@@ -1,26 +0,0 @@
1
- ---
2
- language: ruby
3
- sudo: false
4
- cache: bundler
5
- bundler_args: --without yard benchmarks
6
- script: "bundle exec rake ci"
7
- rvm:
8
- - 1.9.3
9
- - 2.0.0
10
- - 2.1.10
11
- - 2.2.5
12
- - 2.3.1
13
- - jruby-9000
14
- - jruby-head
15
- - ruby-head
16
- - rbx-2
17
- matrix:
18
- allow_failures:
19
- - rvm: ruby-head
20
- - rvm: jruby-head
21
- - rvm: rbx-2
22
- fast_finish: true
23
- branches:
24
- only: master
25
- notifications:
26
- email: false
data/Gemfile DELETED
@@ -1,16 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :development do
6
- gem 'rspec', '~> 3.5.0'
7
- gem 'yard', '~> 0.8.7'
8
- gem 'benchmark-ips', '~> 2.0.0'
9
- end
10
-
11
- group :metrics do
12
- gem 'coveralls', '~> 0.8.9'
13
- gem 'simplecov', '~> 0.10.0'
14
- gem 'yardstick', '~> 0.9.9'
15
- gem 'term-ansicolor', '=1.3.2'
16
- end
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "bundler/gem_tasks"
4
-
5
- FileList['tasks/**/*.rake'].each(&method(:import))
6
-
7
- desc 'Run all specs'
8
- task ci: %w[ spec ]
@@ -1,23 +0,0 @@
1
- ---
2
- install:
3
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
4
- - ruby --version
5
- - gem --version
6
- - bundle install
7
- build: off
8
- test_script:
9
- - bundle exec rake ci
10
- environment:
11
- matrix:
12
- - ruby_version: "193"
13
- - ruby_version: "200"
14
- - ruby_version: "200-x64"
15
- - ruby_version: "21"
16
- - ruby_version: "21-x64"
17
- - ruby_version: "22"
18
- - ruby_version: "22-x64"
19
- - ruby_version: "23"
20
- - ruby_version: "23-x64"
21
- matrix:
22
- allow_failures:
23
- - ruby_version: "193"
Binary file
Binary file
@@ -1,41 +0,0 @@
1
- require 'pastel'
2
- require 'benchmark/ips'
3
-
4
- pastel = Pastel.new
5
-
6
- Benchmark.ips do |bench|
7
- bench.config(time: 5, warmup: 2)
8
-
9
- bench.report('regular nesting') do
10
- pastel.red.on_green('Unicorns' +
11
- pastel.green.on_red('will ', 'dominate' + pastel.yellow('the world!')))
12
- end
13
-
14
- bench.report('block nesting') do
15
- pastel.red.on_green('Unicorns') do
16
- green.on_red('will ', 'dominate') do
17
- yellow('the world!')
18
- end
19
- end
20
- end
21
-
22
- bench.compare!
23
- end
24
-
25
- # version 0.6.0
26
-
27
- # Calculating -------------------------------------
28
- # regular nesting 1282 i/100ms
29
- # block nesting 1013 i/100ms
30
- # -------------------------------------------------
31
- # regular nesting 13881.5 (±16.3%) i/s - 67946 in 5.043220s
32
- # block nesting 11411.6 (±25.4%) i/s - 53689 in 5.088911s
33
- #
34
- # Comparison:
35
- # regular nesting: 13881.5 i/s
36
- # block nesting: 11411.6 i/s - 1.22x slower
37
-
38
- # version 0.5.3
39
-
40
- # regular nesting: 2800/s
41
- # block nesting: 2600/s
@@ -1,45 +0,0 @@
1
- require 'pastel'
2
- require 'benchmark/ips'
3
-
4
- pastel = Pastel.new
5
-
6
- Benchmark.ips do |bench|
7
- bench.config(time: 5, warmup: 2)
8
-
9
- bench.report('color decorate') do
10
- pastel.decorate('string', :red, :on_green, :bold)
11
- end
12
-
13
- bench.report('dsl styling') do
14
- pastel.red.on_green.bold('string')
15
- end
16
-
17
- bench.compare!
18
- end
19
-
20
- # version 0.6.0
21
-
22
- # Calculating -------------------------------------
23
- # color decorate 7346 i/100ms
24
- # dsl styling 3436 i/100ms
25
- # -------------------------------------------------
26
- # color decorate 96062.1 (±7.9%) i/s - 484836 in 5.081126s
27
- # dsl styling 38761.1 (±13.9%) i/s - 192416 in 5.065053s
28
- #
29
- # Comparison:
30
- # color decorate: 96062.1 i/s
31
- # dsl styling: 38761.1 i/s - 2.48x slower
32
-
33
- # version 0.5.3
34
-
35
- # Calculating -------------------------------------
36
- # color decorate 1428 i/100ms
37
- # dsl styling 1174 i/100ms
38
- # -------------------------------------------------
39
- # color decorate 16113.1 (±21.5%) i/s - 77112 in 5.054487s
40
- # dsl styling 12622.9 (±20.8%) i/s - 61048 in 5.076738s
41
- #
42
- # Comparison:
43
- # color decorate: 16113.1 i/s
44
- # dsl styling: 12622.9 i/s - 1.28x slower
45
- #
@@ -1,14 +0,0 @@
1
- require_relative 'lib/pastel'
2
-
3
- pastel = Pastel.new
4
-
5
- puts pastel.bold('bold ') + ' ' + pastel.dim('dim ') + ' ' + pastel.italic('italic ') + ' ' + pastel.underline('underline') + ' ' + pastel.inverse('inverse ') + ' ' + pastel.strikethrough('strikethrough')
6
-
7
- puts pastel.red('red ') + ' ' + pastel.green('green ') + ' ' + pastel.yellow('yellow ') + ' ' + pastel.blue('blue ') + ' ' + pastel.magenta('magenta ') + ' ' + pastel.cyan('cyan ') + ' ' + pastel.white('white')
8
-
9
- puts pastel.bright_red('red ') + ' ' + pastel.bright_green('green ') + ' ' + pastel.bright_yellow('yellow ') + ' ' + pastel.bright_blue('blue ') + ' ' + pastel.bright_magenta('magenta ') + ' ' + pastel.bright_cyan('cyan ') + ' ' + pastel.bright_white('white')
10
-
11
-
12
- puts pastel.on_red('on_red') + ' ' + pastel.on_green('on_green') + ' ' + pastel.on_yellow('on_yellow') + ' ' + pastel.on_blue('on_blue') + ' ' + pastel.on_magenta('on_magenta') + ' ' + pastel.on_cyan('on_cyan') + ' ' + pastel.on_white('on_white')
13
-
14
- puts pastel.on_bright_red('on_red') + ' ' + pastel.on_bright_green('on_green') + ' ' + pastel.on_bright_yellow('on_yellow') + ' ' + pastel.on_bright_blue('on_blue') + ' ' + pastel.on_bright_magenta('on_magenta') + ' ' + pastel.on_bright_cyan('on_cyan') + ' ' + pastel.on_bright_white('on_white')
@@ -1,26 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'pastel/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "pastel"
8
- spec.version = Pastel::VERSION
9
- spec.authors = ["Piotr Murach"]
10
- spec.email = [""]
11
- spec.summary = %q{Terminal strings styling with intuitive and clean API.}
12
- spec.description = %q{Terminal strings styling with intuitive and clean API.}
13
- spec.homepage = "https://github.com/piotrmurach/pastel"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^spec/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_dependency 'equatable', '~> 0.5.0'
22
- spec.add_dependency 'tty-color', '~> 0.4.0'
23
-
24
- spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
25
- spec.add_development_dependency 'rake'
26
- end
@@ -1,45 +0,0 @@
1
- # encoding: utf-8
2
-
3
- if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ]
11
-
12
- SimpleCov.start do
13
- command_name 'spec'
14
- add_filter 'spec'
15
- end
16
- end
17
-
18
- require 'pastel'
19
-
20
- RSpec.configure do |config|
21
- config.expect_with :rspec do |expectations|
22
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
23
- end
24
-
25
- config.mock_with :rspec do |mocks|
26
- mocks.verify_partial_doubles = true
27
- end
28
-
29
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
30
- config.disable_monkey_patching!
31
-
32
- # This setting enables warnings. It's recommended, but in some cases may
33
- # be too noisy due to issues in dependencies.
34
- config.warnings = true
35
-
36
- if config.files_to_run.one?
37
- config.default_formatter = 'doc'
38
- end
39
-
40
- config.profile_examples = 2
41
-
42
- config.order = :random
43
-
44
- Kernel.srand config.seed
45
- end
@@ -1,24 +0,0 @@
1
- # coding: utf-8
2
-
3
- RSpec.describe Pastel, '#alias_color' do
4
-
5
- subject(:pastel) { described_class.new(enabled: true) }
6
-
7
- it "aliases color" do
8
- pastel.alias_color(:funky, :red)
9
- expect(pastel.funky('unicorn')).to eq("\e[31municorn\e[0m")
10
- end
11
-
12
- it "aliases color and combines with regular ones" do
13
- pastel.alias_color(:funky, :red)
14
- expect(pastel.funky.on_green('unicorn')).to eq("\e[31;42municorn\e[0m")
15
- end
16
-
17
- it "reads aliases from the environment" do
18
- color_aliases = "funky=red"
19
- allow(ENV).to receive(:[]).with('PASTEL_COLORS_ALIASES').
20
- and_return(color_aliases)
21
- described_class.new(enabled: true)
22
- expect(pastel.valid?(:funky)).to eq(true)
23
- end
24
- end
@@ -1,29 +0,0 @@
1
- # coding: utf-8
2
-
3
- RSpec.describe Pastel::AliasImporter, '#import' do
4
- let(:color) { spy(:color, alias_color: true) }
5
- let(:output) { StringIO.new }
6
-
7
- it "imports aliases from environment" do
8
- color_aliases = "funky=red,base=bright_yellow"
9
- env = {'PASTEL_COLORS_ALIASES' => color_aliases}
10
- importer = described_class.new(color, env)
11
-
12
- importer.import
13
-
14
- expect(color).to have_received(:alias_color).with(:funky, :red)
15
- expect(color).to have_received(:alias_color).with(:base, :bright_yellow)
16
- end
17
-
18
- it "fails to import incorrectly formatted colors" do
19
- color_aliases = "funky red,base=bright_yellow"
20
- env = {'PASTEL_COLORS_ALIASES' => color_aliases}
21
- importer = described_class.new(color, env, output)
22
- output.rewind
23
-
24
- importer.import
25
-
26
- expect(output.string).to eq("Bad color mapping `funky red`\n")
27
- expect(color).to have_received(:alias_color).with(:base, :bright_yellow)
28
- end
29
- end
@@ -1,40 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe Pastel::Color, '.alias_color' do
4
-
5
- subject(:color) { described_class.new(enabled: true) }
6
-
7
- it 'aliases non existent color' do
8
- expect {
9
- color.alias_color(:funky, :unknown)
10
- }.to raise_error(Pastel::InvalidAttributeNameError)
11
- end
12
-
13
- it 'aliases color with invalid name' do
14
- expect {
15
- color.alias_color('some name', :red)
16
- }.to raise_error(Pastel::InvalidAliasNameError, /Invalid alias name/)
17
- end
18
-
19
- it 'aliases standard color' do
20
- expect {
21
- color.alias_color(:red, :red)
22
- }.to raise_error(Pastel::InvalidAliasNameError, /alias standard color/)
23
- end
24
-
25
- it 'aliases color :red to :funky' do
26
- color.alias_color(:funky, :red)
27
- expect(color.valid?(:funky)).to eq(true)
28
- expect(color.code(:funky)).to eq([31])
29
- expect(color.lookup(:funky)).to eq("\e[31m")
30
- end
31
-
32
- it "has global aliases" do
33
- color_foo = described_class.new(enabled: true)
34
- color_bar = described_class.new(enabled: true)
35
- color_foo.alias_color(:foo, :red)
36
- color_bar.alias_color(:bar, :red)
37
- expect(color_foo.valid?(:foo)).to eq(true)
38
- expect(color_foo.valid?(:bar)).to eq(true)
39
- end
40
- end
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe Pastel::Color, '#code' do
4
- let(:string) { "This is a \e[1m\e[34mbold blue text\e[0m" }
5
-
6
- subject(:color) { described_class.new(enabled: true) }
7
-
8
- it 'finds single code' do
9
- expect(color.code(:black)).to eq([30])
10
- end
11
-
12
- it 'finds more than one code' do
13
- expect(color.code(:black, :green)).to eq([30, 32])
14
- end
15
-
16
- it "doesn't find code" do
17
- expect { color.code(:unkown) }.to raise_error(ArgumentError)
18
- end
19
-
20
- it "finds alias code" do
21
- color.alias_color(:funky, :red)
22
- expect(color.code(:funky)).to eq(color.code(:red))
23
- end
24
- end
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe Pastel::Color, '#colored?' do
4
- subject(:color) { described_class.new(enabled: true) }
5
-
6
- it "checks if string has color codes" do
7
- string = "foo\e[31mbar\e[0m"
8
- expect(color.colored?(string)).to eq(true)
9
- end
10
-
11
- it "checks that string doesn't contain color codes" do
12
- string = "foo\nbar"
13
- expect(color.colored?(string)).to eq(false)
14
- end
15
- end
@@ -1,79 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe Pastel::Color, '.decorate' do
4
- let(:string) { 'string' }
5
-
6
- subject(:color) { described_class.new(enabled: true) }
7
-
8
- it "doesn't output styling when disabled" do
9
- color = described_class.new(enabled: false)
10
- expect(color.decorate('foo', :red)).to eq('foo')
11
- end
12
-
13
- it "doesn't apply styling to empty string" do
14
- expect(color.decorate('')).to eq('')
15
- end
16
-
17
- it "doesn't decorate without color" do
18
- expect(color.decorate(string)).to eq(string)
19
- end
20
-
21
- it 'applies green text to string' do
22
- expect(color.decorate(string, :green)).to eq("\e[32m#{string}\e[0m")
23
- end
24
-
25
- it 'applies red text background to string' do
26
- expect(color.decorate(string, :on_red)).to eq("\e[41m#{string}\e[0m")
27
- end
28
-
29
- it 'applies style and color to string' do
30
- expect(color.decorate(string, :bold, :green)).to eq("\e[1;32m#{string}\e[0m")
31
- end
32
-
33
- it 'applies style, color and background to string' do
34
- text = color.decorate(string, :bold, :green, :on_blue)
35
- expect(text).to eq("\e[1;32;44m#{string}\e[0m")
36
- end
37
-
38
- it "applies styles to nested text" do
39
- decorated = color.decorate(string + color.decorate(string, :red) + string, :green)
40
- expect(decorated).to eq("\e[32m#{string}\e[31m#{string}\e[0m\e[32m#{string}\e[0m")
41
- end
42
-
43
- it "decorates multiline string as regular by default" do
44
- string = "foo\nbar\nbaz"
45
- expect(color.decorate(string, :red)).to eq("\e[31mfoo\nbar\nbaz\e[0m")
46
- end
47
-
48
- it "allows to decorate each line separately" do
49
- string = "foo\nbar\nbaz"
50
- color = described_class.new(enabled: true, eachline: "\n")
51
- expect(color.decorate(string, :red)).to eq([
52
- "\e[31mfoo\e[0m",
53
- "\e[31mbar\e[0m",
54
- "\e[31mbaz\e[0m"
55
- ].join("\n"))
56
- end
57
-
58
- it 'errors for unknown color' do
59
- expect {
60
- color.decorate(string, :crimson)
61
- }.to raise_error(Pastel::InvalidAttributeNameError)
62
- end
63
-
64
- it "doesn't decorate non-string instance" do
65
- expect(color.decorate({}, :red)).to eq({})
66
- end
67
-
68
- it "doesn't decorate nil" do
69
- expect(color.decorate(nil, :red)).to eq(nil)
70
- end
71
-
72
- it "doesn't decorate zero length string" do
73
- expect(color.decorate('', :red)).to eq('')
74
- end
75
-
76
- it "doesn't decorate non-zero length string" do
77
- expect(color.decorate(' ', :red)).to eq("\e[31m \e[0m")
78
- end
79
- end