pastel 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +66 -12
  3. data/README.md +38 -29
  4. data/lib/pastel/alias_importer.rb +9 -7
  5. data/lib/pastel/ansi.rb +2 -2
  6. data/lib/pastel/color.rb +64 -24
  7. data/lib/pastel/color_parser.rb +24 -18
  8. data/lib/pastel/color_resolver.rb +3 -1
  9. data/lib/pastel/decorator_chain.rb +52 -8
  10. data/lib/pastel/delegator.rb +57 -26
  11. data/lib/pastel/detached.rb +41 -5
  12. data/lib/pastel/version.rb +2 -2
  13. data/lib/pastel.rb +17 -19
  14. metadata +35 -104
  15. data/.gitignore +0 -22
  16. data/.rspec +0 -3
  17. data/.travis.yml +0 -25
  18. data/Gemfile +0 -15
  19. data/Rakefile +0 -8
  20. data/assets/pastel_logo.png +0 -0
  21. data/assets/screenshot.png +0 -0
  22. data/benchmarks/nesting_speed.rb +0 -41
  23. data/benchmarks/speed.rb +0 -45
  24. data/examples/palette.rb +0 -14
  25. data/pastel.gemspec +0 -26
  26. data/spec/spec_helper.rb +0 -45
  27. data/spec/unit/alias_color_spec.rb +0 -24
  28. data/spec/unit/alias_importer_spec.rb +0 -29
  29. data/spec/unit/color/alias_color_spec.rb +0 -40
  30. data/spec/unit/color/code_spec.rb +0 -24
  31. data/spec/unit/color/colored_spec.rb +0 -15
  32. data/spec/unit/color/decorate_spec.rb +0 -79
  33. data/spec/unit/color/equal_spec.rb +0 -22
  34. data/spec/unit/color/lookup_spec.rb +0 -17
  35. data/spec/unit/color/new_spec.rb +0 -10
  36. data/spec/unit/color/strip_spec.rb +0 -56
  37. data/spec/unit/color/styles_spec.rb +0 -10
  38. data/spec/unit/color/valid_spec.rb +0 -19
  39. data/spec/unit/color_parser_spec.rb +0 -67
  40. data/spec/unit/decorate_dsl_spec.rb +0 -94
  41. data/spec/unit/decorator_chain_spec.rb +0 -47
  42. data/spec/unit/delegator_spec.rb +0 -38
  43. data/spec/unit/detach_spec.rb +0 -48
  44. data/spec/unit/new_spec.rb +0 -52
  45. data/spec/unit/respond_to_spec.rb +0 -17
  46. data/spec/unit/undecorate_spec.rb +0 -12
  47. data/tasks/console.rake +0 -10
  48. data/tasks/coverage.rake +0 -11
  49. data/tasks/spec.rake +0 -29
@@ -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
data/benchmarks/speed.rb DELETED
@@ -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
- #
data/examples/palette.rb DELETED
@@ -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')
data/pastel.gemspec DELETED
@@ -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.3.0'
23
-
24
- spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
25
- spec.add_development_dependency 'rake'
26
- end
data/spec/spec_helper.rb DELETED
@@ -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
@@ -1,22 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe Pastel::Color, '#==' do
4
- it "is true with the same enabled and eachline attributes" do
5
- expect(Pastel::Color.new(enabled: false, eachline: "\n")).
6
- to eq(Pastel::Color.new(enabled: false, eachline: "\n"))
7
- end
8
-
9
- it "is false with different enabled attribute" do
10
- expect(Pastel::Color.new(enabled: true, eachline: "\n")).
11
- not_to eq(Pastel::Color.new(enabled: false, eachline: "\n"))
12
- end
13
-
14
- it "is false with different eachline attribute" do
15
- expect(Pastel::Color.new(enabled: false, eachline: "\n")).
16
- not_to eq(Pastel::Color.new(enabled: false, eachline: "\r\n"))
17
- end
18
-
19
- it "is false with non-color" do
20
- expect(Pastel::Color.new(enabled: true)).not_to eq(:other)
21
- end
22
- end
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe Pastel::Color, '#lookup' do
4
- it "looksup colors" do
5
- color = described_class.new(enabled: true)
6
- expect(color.lookup(:red, :on_green, :bold)).to eq("\e[31;42;1m")
7
- end
8
-
9
- it "caches color lookups" do
10
- color = described_class.new(enabled: true)
11
- allow(color).to receive(:code).and_return([31])
12
- color.lookup(:red, :on_green)
13
- color.lookup(:red, :on_green)
14
- color.lookup(:red, :on_green)
15
- expect(color).to have_received(:code).once
16
- end
17
- end
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe Pastel::Color, '::new' do
4
- it "allows to disable coloring" do
5
- color = described_class.new(enabled: false)
6
-
7
- expect(color.enabled?).to eq(false)
8
- expect(color.decorate("Unicorn", :red)).to eq("Unicorn")
9
- end
10
- end
@@ -1,56 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe Pastel::Color, '.strip' do
4
-
5
- subject(:color) { described_class.new(enabled: true) }
6
-
7
- it 'strips ansi color from string' do
8
- string = "This is a \e[1m\e[34mbold blue text\e[0m"
9
- expect(color.strip(string)).to eq('This is a bold blue text')
10
- end
11
-
12
- it "strips partial ansi color" do
13
- string = "foo\e[1mbar"
14
- expect(color.strip(string)).to eq('foobar')
15
- end
16
-
17
- it 'preserves movement characters' do
18
- # [176A - move cursor up n lines
19
- expect(color.strip("foo\e[176Abar")).to eq("foo\e[176Abar")
20
- end
21
-
22
- it 'strips reset/setfg/setbg/italics/strike/underline sequence' do
23
- string = "\x1b[0;33;49;3;9;4mfoo\x1b[0m"
24
- expect(color.strip(string)).to eq("foo")
25
- end
26
-
27
- it 'strips octal in encapsulating brackets' do
28
- string = "\[\033[01;32m\]u@h \[\033[01;34m\]W $ \[\033[00m\]"
29
- expect(color.strip(string)).to eq('[]u@h []W $ []')
30
- end
31
-
32
- it 'strips octal codes without brackets' do
33
- string = "\033[01;32mu@h \033[01;34mW $ \033[00m"
34
- expect(color.strip(string)).to eq('u@h W $ ')
35
- end
36
-
37
- it 'strips octal with multiple colors' do
38
- string = "\e[3;0;0;mfoo\e[8;50;0m"
39
- expect(color.strip(string)).to eq('foo')
40
- end
41
-
42
- it "strips multiple colors delimited by :" do
43
- string = "\e[31:44:4mfoo\e[0m"
44
- expect(color.strip(string)).to eq('foo')
45
- end
46
-
47
- it 'strips control codes' do
48
- string = "WARN. \x1b[1m&\x1b[0m ERR. \x1b[7m&\x1b[0m"
49
- expect(color.strip(string)).to eq('WARN. & ERR. &')
50
- end
51
-
52
- it 'strips escape bytes' do
53
- string = "This is a \e[1m\e[34mbold blue text\e[0m"
54
- expect(color.strip(string)).to eq("This is a bold blue text")
55
- end
56
- end
@@ -1,10 +0,0 @@
1
- # coding: utf-8
2
-
3
- RSpec.describe Pastel::Color, '#styles' do
4
-
5
- subject(:color) { described_class.new(enabled: true) }
6
-
7
- it "exposes all available style ANSI codes" do
8
- expect(color.styles[:red]).to eq(31)
9
- end
10
- end
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe Pastel::Color, '.valid?' do
4
- it "detects valid colors" do
5
- color = described_class.new
6
- expect(color.valid?(:red, :on_green, :bold)).to eq(true)
7
- end
8
-
9
- it "detects valid color aliases" do
10
- color = described_class.new
11
- color.alias_color(:funky, :red)
12
- expect(color.valid?(:funky)).to eq(true)
13
- end
14
-
15
- it "detects invalid color" do
16
- color = described_class.new
17
- expect(color.valid?(:red, :unknown)).to eq(false)
18
- end
19
- end
@@ -1,67 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe Pastel::ColorParser, '::parse' do
4
- subject(:parser) { described_class }
5
-
6
- it "parses string with no color" do
7
- expect(parser.parse("foo")).to eq([{text: 'foo'}])
8
- end
9
-
10
- it "parses simple color" do
11
- expect(parser.parse("\e[32mfoo\e[0m")).to eq([
12
- {foreground: :green, text: 'foo'}
13
- ])
14
- end
15
-
16
- it "parses simple color and style" do
17
- expect(parser.parse("\e[32;1mfoo\e[0m")).to eq([
18
- {foreground: :green, style: :bold, text: 'foo'}
19
- ])
20
- end
21
-
22
- it "parses chained colors in shorthand syntax" do
23
- expect(parser.parse("\e[32;44mfoo\e[0m")).to eq([
24
- {foreground: :green, background: :on_blue, text: 'foo'}
25
- ])
26
- end
27
-
28
- it "parses chained colors in regular syntax" do
29
- expect(parser.parse("\e[32m\e[44mfoo\e[0m")).to eq([
30
- {foreground: :green, background: :on_blue, text: 'foo'}
31
- ])
32
- end
33
-
34
- it "parses many colors" do
35
- expect(parser.parse("\e[32mfoo\e[0m \e[31mbar\e[0m")).to eq([
36
- {foreground: :green, text: 'foo'},
37
- {text: ' '},
38
- {foreground: :red, text: 'bar'}
39
- ])
40
- end
41
-
42
- it "parses nested colors with one reset" do
43
- expect(parser.parse("\e[32mfoo\e[31mbar\e[0m")).to eq([
44
- {foreground: :green, text: 'foo'},
45
- {foreground: :red, text: 'bar'}
46
- ])
47
- end
48
-
49
- it "parses nested colors with two resets" do
50
- expect(parser.parse("\e[32mfoo\e[31mbar\e[0m\e[0m")).to eq([
51
- {foreground: :green, text: 'foo'},
52
- {foreground: :red, text: 'bar'}
53
- ])
54
- end
55
-
56
- it "parses unrest color" do
57
- expect(parser.parse("\e[32mfoo")).to eq([
58
- {foreground: :green, text: 'foo'}
59
- ])
60
- end
61
-
62
- it "parses malformed control sequence" do
63
- expect(parser.parse("\eA foo bar ESC\e")).to eq([
64
- {text: "\eA foo bar ESC\e"}
65
- ])
66
- end
67
- end