termin-ansicolor 1.3.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+
3
+ class AttributeTest < Test::Unit::TestCase
4
+ include Termin::ANSIColor
5
+
6
+ def test_cast
7
+ color = Attribute.get(:color123)
8
+ on_color = Attribute.get(:on_color123)
9
+ assert_equal color, Attribute[color]
10
+ assert_equal color, Attribute[:color123]
11
+ assert_equal color, Attribute[123]
12
+ assert_equal color, Attribute['123']
13
+ assert_equal color, Attribute['#87ffff']
14
+ assert_equal color, Attribute[ [ 0x87, 0xff, 0xff ] ]
15
+ assert_equal on_color, Attribute['on_123']
16
+ assert_equal on_color, Attribute['on_#87ffff']
17
+ end
18
+
19
+ def test_gray
20
+ a1 = Attribute[ [ 0, 0, 0 ] ]
21
+ assert_equal false, a1.gray?
22
+ a2 = Attribute[ [ 255, 255, 255 ] ]
23
+ assert_equal false, a2.gray?
24
+ a3 = Attribute[ [ 00, 0x7f, 0xff ] ]
25
+ assert_equal false, a3.gray?
26
+ a4 = Attribute[ [ 0x7f, 0x7f, 0x7f ] ]
27
+ assert_equal true, a4.gray?
28
+ end
29
+
30
+ def test_distance_to
31
+ color = Attribute.nearest_rgb_color('#0f0')
32
+ assert_in_delta 250.954, Attribute.get(:color0).distance_to(color), 1e-3
33
+ color = Attribute.nearest_rgb_color('#0f0')
34
+ assert_in_delta 255, Attribute.get(:color0).distance_to(color,
35
+ :metric => RGBColorMetrics::Euclidean), 1e-3
36
+ assert_equal 1 / 0.0, Attribute.get(:color0).distance_to(nil)
37
+ end
38
+
39
+ def test_nearest_rgb_color
40
+ assert_equal Attribute.get(:color0).rgb, Attribute.nearest_rgb_color('#000').rgb
41
+ assert_equal Attribute.get(:color15).rgb, Attribute.nearest_rgb_color('#ffffff').rgb
42
+ assert_equal :color247, Attribute.nearest_rgb_color('#aaa').name
43
+ assert_equal :color109, Attribute.nearest_rgb_color('#aaa', :gray => false).name
44
+ end
45
+
46
+ def test_nearest_rgb_on_color
47
+ assert_equal Attribute.get(:on_color0).rgb, Attribute.nearest_rgb_on_color('#000').rgb
48
+ assert_equal Attribute.get(:on_color15).rgb, Attribute.nearest_rgb_on_color('#ffffff').rgb
49
+ assert_equal :on_color247, Attribute.nearest_rgb_on_color('#aaa').name
50
+ assert_equal :on_color109, Attribute.nearest_rgb_on_color('#aaa', :gray => false).name
51
+ end
52
+
53
+ def test_apply
54
+ assert_equal "\e[5m", Attribute[:blink].apply
55
+ assert_equal "\e[5mfoo\e[0m", Attribute[:blink].apply('foo')
56
+ assert_equal "\e[5mfoo\e[0m", Attribute[:blink].apply { 'foo' }
57
+ end
58
+
59
+ def test_gradient
60
+ g0 = Attribute[:blink].gradient_to Attribute['#30ffaa']
61
+ assert_equal [], g0
62
+ g1 = Attribute['#30ffaa'].gradient_to(Attribute['#ff507f'], :steps => 9)
63
+ assert_equal [ :color49, :color49, :color43, :color79, :color108,
64
+ :color247, :color138, :color168, :color204 ], g1.map(&:name)
65
+ g2 = Attribute['#30ffaa'].gradient_to(
66
+ Attribute['#ff507f'],
67
+ :steps => 9,
68
+ :metric => RGBColorMetrics::Euclidean
69
+ )
70
+ assert_equal [ :color49, :color43, :color79, :color73, :color108,
71
+ :color247, :color138, :color168, :color204 ], g2.map(&:name)
72
+ end
73
+ end
@@ -0,0 +1,46 @@
1
+ require 'test_helper'
2
+ require 'digest/md5'
3
+
4
+ class PPMReaderTest < Test::Unit::TestCase
5
+ include Termin::ANSIColor
6
+
7
+ def test_loading_ppm6
8
+ File.open(example_path('lambda-red.ppm')) do |ppm6|
9
+ ppm_reader = PPMReader.new(ppm6)
10
+ assert_equal '2035155a4242e498f4852ae8425dac6b',
11
+ Digest::MD5.hexdigest(ppm_reader.to_s)
12
+ end
13
+ end
14
+
15
+ def test_loading_ppm3
16
+ File.open(example_path('lambda-red-plain.ppm')) do |ppm6|
17
+ ppm_reader = PPMReader.new(ppm6)
18
+ assert_equal '2035155a4242e498f4852ae8425dac6b',
19
+ Digest::MD5.hexdigest(ppm_reader.to_s)
20
+ end
21
+ end
22
+
23
+ def test_rendering_ppm_without_gray
24
+ File.open(example_path('lambda-red.ppm')) do |ppm6|
25
+ ppm_reader = PPMReader.new(ppm6, :gray => false)
26
+ assert_equal '0653f40e42a87fc480e09db1c58f71ba',
27
+ Digest::MD5.hexdigest(ppm_reader.to_s)
28
+ end
29
+ end
30
+
31
+ def test_to_a
32
+ File.open(example_path('lambda-red.ppm')) do |ppm6|
33
+ ppm_reader = PPMReader.new(ppm6, :gray => false)
34
+ ary = ppm_reader.to_a
35
+ assert_equal 22, ary.size
36
+ assert_equal 44, ary.first.size
37
+ assert_equal [ 255, 255, 255 ], ary.first.last
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def example_path(path = [])
44
+ File.expand_path(File.join(File.dirname(__FILE__), '..', 'examples', *path))
45
+ end
46
+ end
@@ -0,0 +1,100 @@
1
+ require 'test_helper'
2
+
3
+ class RGBColorMetrics < Test::Unit::TestCase
4
+ include Termin::ANSIColor
5
+
6
+ def setup
7
+ @black = RGBTriple.new(0, 0, 0)
8
+ @white = RGBTriple.new(255, 255, 255)
9
+ @red = RGBTriple.new(255, 0, 0)
10
+ @bright_orange = RGBTriple.new(0, 200, 128)
11
+ end
12
+
13
+ def test_metric_getters
14
+ assert_raise(ArgumentError) { RGBColorMetrics.metric('Foo') }
15
+ assert_equal RGBColorMetrics::Euclidean, RGBColorMetrics.metric('Euclidean')
16
+ assert_equal RGBColorMetrics::Euclidean, RGBColorMetrics.metric(:Euclidean)
17
+ assert_operator RGBColorMetrics.metrics.size, :>, 1
18
+ assert_equal true, RGBColorMetrics.metrics.include?(:Euclidean)
19
+ assert RGBColorMetrics.metric?(:Euclidean)
20
+ assert_equal RGBColorMetrics::Euclidean, RGBColorMetrics.metric?(:Euclidean)
21
+ end
22
+
23
+ def test_euclidean
24
+ assert_in_delta 255, RGBColorMetrics::Euclidean.distance(@black, @red), 1e-3
25
+ assert_in_delta 255, RGBColorMetrics::Euclidean.distance(@red, @black), 1e-3
26
+ assert_in_delta 360.624, RGBColorMetrics::Euclidean.distance(@white, @red), 1e-3
27
+ assert_in_delta 360.624, RGBColorMetrics::Euclidean.distance(@red, @white), 1e-3
28
+ assert_in_delta 441.672, RGBColorMetrics::Euclidean.distance(@white, @black), 1e-3
29
+ assert_in_delta 441.672, RGBColorMetrics::Euclidean.distance(@black, @white), 1e-3
30
+ assert_in_delta 237.453, RGBColorMetrics::Euclidean.distance(@black, @bright_orange), 1e-3
31
+ assert_in_delta 237.453, RGBColorMetrics::Euclidean.distance(@bright_orange, @black), 1e-3
32
+ assert_in_delta 290.136, RGBColorMetrics::Euclidean.distance(@white, @bright_orange), 1e-3
33
+ assert_in_delta 290.136, RGBColorMetrics::Euclidean.distance(@bright_orange, @white), 1e-3
34
+ end
35
+
36
+ def test_ntsc
37
+ assert_in_delta 139.436, RGBColorMetrics::NTSC.distance(@black, @red), 1e-3
38
+ assert_in_delta 139.436, RGBColorMetrics::NTSC.distance(@red, @black), 1e-3
39
+ assert_in_delta 213.500, RGBColorMetrics::NTSC.distance(@white, @red), 1e-3
40
+ assert_in_delta 213.500, RGBColorMetrics::NTSC.distance(@red, @white), 1e-3
41
+ assert_in_delta 255, RGBColorMetrics::NTSC.distance(@white, @black), 1e-3
42
+ assert_in_delta 255, RGBColorMetrics::NTSC.distance(@black, @white), 1e-3
43
+ assert_in_delta 159.209, RGBColorMetrics::NTSC.distance(@black, @bright_orange), 1e-3
44
+ assert_in_delta 159.209, RGBColorMetrics::NTSC.distance(@bright_orange, @black), 1e-3
45
+ assert_in_delta 151.844, RGBColorMetrics::NTSC.distance(@white, @bright_orange), 1e-3
46
+ assert_in_delta 151.844, RGBColorMetrics::NTSC.distance(@bright_orange, @white), 1e-3
47
+ end
48
+
49
+ def test_compu_phase
50
+ assert_in_delta 360.624, RGBColorMetrics::CompuPhase.distance(@black, @red), 1e-3
51
+ assert_in_delta 360.624, RGBColorMetrics::CompuPhase.distance(@red, @black), 1e-3
52
+ assert_in_delta 624.619, RGBColorMetrics::CompuPhase.distance(@white, @red), 1e-3
53
+ assert_in_delta 624.619, RGBColorMetrics::CompuPhase.distance(@red, @white), 1e-3
54
+ assert_in_delta 721.248, RGBColorMetrics::CompuPhase.distance(@white, @black), 1e-3
55
+ assert_in_delta 721.248, RGBColorMetrics::CompuPhase.distance(@black, @white), 1e-3
56
+ assert_in_delta 439.053, RGBColorMetrics::CompuPhase.distance(@black, @bright_orange), 1e-3
57
+ assert_in_delta 439.053, RGBColorMetrics::CompuPhase.distance(@bright_orange, @black), 1e-3
58
+ assert_in_delta 417.621, RGBColorMetrics::CompuPhase.distance(@white, @bright_orange), 1e-3
59
+ assert_in_delta 417.621, RGBColorMetrics::CompuPhase.distance(@bright_orange, @white), 1e-3
60
+ end
61
+
62
+ def test_yuv
63
+ assert_in_delta 178.308, RGBColorMetrics::YUV.distance(@black, @red), 1e-3
64
+ assert_in_delta 178.308, RGBColorMetrics::YUV.distance(@red, @black), 1e-3
65
+ assert_in_delta 240.954, RGBColorMetrics::YUV.distance(@white, @red), 1e-3
66
+ assert_in_delta 240.954, RGBColorMetrics::YUV.distance(@red, @white), 1e-3
67
+ assert_in_delta 255, RGBColorMetrics::YUV.distance(@white, @black), 1e-3
68
+ assert_in_delta 255, RGBColorMetrics::YUV.distance(@black, @white), 1e-3
69
+ assert_in_delta 175.738, RGBColorMetrics::YUV.distance(@black, @bright_orange), 1e-3
70
+ assert_in_delta 175.738, RGBColorMetrics::YUV.distance(@bright_orange, @black), 1e-3
71
+ assert_in_delta 169.082, RGBColorMetrics::YUV.distance(@white, @bright_orange), 1e-3
72
+ assert_in_delta 169.082, RGBColorMetrics::YUV.distance(@bright_orange, @white), 1e-3
73
+ end
74
+
75
+ def test_ciexyz
76
+ assert_in_delta 124.843, RGBColorMetrics::CIEXYZ.distance(@black, @red), 1e-3
77
+ assert_in_delta 124.843, RGBColorMetrics::CIEXYZ.distance(@red, @black), 1e-3
78
+ assert_in_delta 316.014, RGBColorMetrics::CIEXYZ.distance(@white, @red), 1e-3
79
+ assert_in_delta 316.014, RGBColorMetrics::CIEXYZ.distance(@red, @white), 1e-3
80
+ assert_in_delta 411.874, RGBColorMetrics::CIEXYZ.distance(@white, @black), 1e-3
81
+ assert_in_delta 411.874, RGBColorMetrics::CIEXYZ.distance(@black, @white), 1e-3
82
+ assert_in_delta 137.920, RGBColorMetrics::CIEXYZ.distance(@black, @bright_orange), 1e-3
83
+ assert_in_delta 137.920, RGBColorMetrics::CIEXYZ.distance(@bright_orange, @black), 1e-3
84
+ assert_in_delta 280.023, RGBColorMetrics::CIEXYZ.distance(@white, @bright_orange), 1e-3
85
+ assert_in_delta 280.023, RGBColorMetrics::CIEXYZ.distance(@bright_orange, @white), 1e-3
86
+ end
87
+
88
+ def test_cielab
89
+ assert_in_delta 174.656, RGBColorMetrics::CIELab.distance(@black, @red), 1e-3
90
+ assert_in_delta 174.656, RGBColorMetrics::CIELab.distance(@red, @black), 1e-3
91
+ assert_in_delta 158.587, RGBColorMetrics::CIELab.distance(@white, @red), 1e-3
92
+ assert_in_delta 158.587, RGBColorMetrics::CIELab.distance(@red, @white), 1e-3
93
+ assert_in_delta 255, RGBColorMetrics::CIELab.distance(@white, @black), 1e-3
94
+ assert_in_delta 255, RGBColorMetrics::CIELab.distance(@black, @white), 1e-3
95
+ assert_in_delta 191.927, RGBColorMetrics::CIELab.distance(@black, @bright_orange), 1e-3
96
+ assert_in_delta 191.927, RGBColorMetrics::CIELab.distance(@bright_orange, @black), 1e-3
97
+ assert_in_delta 95.084, RGBColorMetrics::CIELab.distance(@white, @bright_orange), 1e-3
98
+ assert_in_delta 95.084, RGBColorMetrics::CIELab.distance(@bright_orange, @white), 1e-3
99
+ end
100
+ end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+
3
+ class RgbTripleTest < Test::Unit::TestCase
4
+ include Termin::ANSIColor
5
+
6
+ def test_rgb_cast
7
+ rgb = RGBTriple.new(128, 0, 255)
8
+ assert_equal '#8000ff', RGBTriple[ rgb ].html
9
+ assert_equal '#8000ff', RGBTriple[ [ 128, 0, 255 ] ].html
10
+ assert_equal '#8000ff', RGBTriple[ :red => 128, :green => 0, :blue => 255 ].html
11
+ assert_raise ArgumentError do
12
+ RGBTriple[ nil ]
13
+ end
14
+ end
15
+
16
+ def test_rgb_to_a
17
+ rgb = RGBTriple.new(128, 0, 255)
18
+ assert_equal [ 128, 0, 255 ], rgb.to_a
19
+ end
20
+
21
+ def test_rgb_distance
22
+ rgb1 = RGBTriple.new(128, 0, 255)
23
+ rgb2 = RGBTriple.new(128, 200, 64)
24
+ assert_in_delta 0.0, rgb1.distance_to(rgb1), 1e-3
25
+ assert_in_delta 255, RGBTriple.new(0, 0, 0).distance_to(RGBTriple.new(255, 255, 255)), 1e-3
26
+ assert_in_delta 209.935, rgb1.distance_to(rgb2), 1e-3
27
+ end
28
+
29
+ def test_rgb_gray
30
+ rgb1 = RGBTriple.new(0, 0, 0)
31
+ assert_equal false, rgb1.gray?
32
+ rgb2 = RGBTriple.new(255, 255, 255)
33
+ assert_equal false, rgb2.gray?
34
+ rgb3 = RGBTriple.new(12, 23, 34)
35
+ assert_equal false, rgb3.gray?
36
+ rgb4 = RGBTriple.new(127, 127, 127)
37
+ assert_equal true, rgb4.gray?
38
+ end
39
+
40
+ def test_gradient
41
+ rgb1 = RGBTriple.new(0, 0, 0)
42
+ rgb2 = RGBTriple.new(255, 255, 255)
43
+ g0 = rgb1.gradient_to(rgb2, :steps => 2)
44
+ assert_equal 2, g0.size
45
+ assert_equal rgb1, g0[0]
46
+ assert_equal rgb2, g0[1]
47
+ g1 = rgb1.gradient_to(rgb2, :steps => 3)
48
+ assert_equal 3, g1.size
49
+ assert_equal rgb1, g1[0]
50
+ assert_equal 127, g1[1].red
51
+ assert_equal 127, g1[1].green
52
+ assert_equal 127, g1[1].blue
53
+ assert_equal rgb2, g1[2]
54
+ g2 = rgb1.gradient_to(rgb2, :steps => 6)
55
+ assert_equal 6, g2.size
56
+ assert_equal rgb1, g2[0]
57
+ assert_equal 51, g2[1].red
58
+ assert_equal 51, g2[1].green
59
+ assert_equal 51, g2[1].blue
60
+ assert_equal 102, g2[2].red
61
+ assert_equal 102, g2[2].green
62
+ assert_equal 102, g2[2].blue
63
+ assert_equal 153, g2[3].red
64
+ assert_equal 153, g2[3].green
65
+ assert_equal 153, g2[3].blue
66
+ assert_equal 204, g2[4].red
67
+ assert_equal 204, g2[4].green
68
+ assert_equal 204, g2[4].blue
69
+ assert_equal rgb2, g2[5]
70
+ end
71
+ end
@@ -0,0 +1,8 @@
1
+ if ENV['START_SIMPLECOV'].to_i == 1
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "#{File.basename(File.dirname(__FILE__))}/"
5
+ end
6
+ end
7
+ require 'test/unit'
8
+ require 'termin/ansicolor'
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: termin-ansicolor
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Florian Frank
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gem_hadar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: simplecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tins
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: This library uses ANSI escape sequences to control the attributes of
56
+ terminal output. Termin Ansicolor is the clone of term-ansicolor gem with fixed
57
+ bug. This gem is needed until merging pull request on official repo.
58
+ email: flori@ping.de
59
+ executables:
60
+ - cdiff
61
+ - decolor
62
+ - colortab
63
+ - term_mandel
64
+ - term_display
65
+ extensions: []
66
+ extra_rdoc_files:
67
+ - README.rdoc
68
+ - lib/termin/ansicolor.rb
69
+ - lib/termin/ansicolor/attribute.rb
70
+ - lib/termin/ansicolor/ppm_reader.rb
71
+ - lib/termin/ansicolor/rgb_color_metrics.rb
72
+ - lib/termin/ansicolor/rgb_triple.rb
73
+ - lib/termin/ansicolor/version.rb
74
+ files:
75
+ - ".gitignore"
76
+ - ".travis.yml"
77
+ - CHANGES
78
+ - COPYING
79
+ - Gemfile
80
+ - README.rdoc
81
+ - Rakefile
82
+ - VERSION
83
+ - bin/cdiff
84
+ - bin/colortab
85
+ - bin/decolor
86
+ - bin/term_display
87
+ - bin/term_mandel
88
+ - examples/ColorTest.gif
89
+ - examples/Mona_Lisa.jpg
90
+ - examples/Stilleben.jpg
91
+ - examples/example.rb
92
+ - examples/lambda-red-plain.ppm
93
+ - examples/lambda-red.png
94
+ - examples/lambda-red.ppm
95
+ - examples/pacman.jpg
96
+ - examples/smiley.png
97
+ - examples/wool.jpg
98
+ - lib/termin/ansicolor.rb
99
+ - lib/termin/ansicolor/.keep
100
+ - lib/termin/ansicolor/attribute.rb
101
+ - lib/termin/ansicolor/ppm_reader.rb
102
+ - lib/termin/ansicolor/rgb_color_metrics.rb
103
+ - lib/termin/ansicolor/rgb_triple.rb
104
+ - lib/termin/ansicolor/version.rb
105
+ - term-ansicolor.gemspec
106
+ - tests/ansicolor_test.rb
107
+ - tests/attribute_test.rb
108
+ - tests/ppm_reader_test.rb
109
+ - tests/rgb_color_metrics_test.rb
110
+ - tests/rgb_triple_test.rb
111
+ - tests/test_helper.rb
112
+ homepage: http://flori.github.com/term-ansicolor
113
+ licenses:
114
+ - GPL-2
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options:
118
+ - "--title"
119
+ - Term-ansicolor - Ruby library that colors strings using ANSI escape sequences
120
+ - "--main"
121
+ - README.rdoc
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Ruby library that colors strings using ANSI escape sequences
140
+ test_files:
141
+ - tests/ansicolor_test.rb
142
+ - tests/attribute_test.rb
143
+ - tests/ppm_reader_test.rb
144
+ - tests/rgb_color_metrics_test.rb
145
+ - tests/rgb_triple_test.rb
146
+ - tests/test_helper.rb