pry-theme 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +8 -1
  4. data/CHANGELOG.md +40 -0
  5. data/Gemfile +1 -1
  6. data/README.md +26 -48
  7. data/Rakefile +10 -1
  8. data/VERSION +1 -0
  9. data/lib/pry-theme/basic_editor.rb +116 -0
  10. data/lib/pry-theme/color.rb +431 -0
  11. data/lib/pry-theme/color_table.rb +39 -0
  12. data/lib/pry-theme/colors/color16.rb +35 -0
  13. data/lib/pry-theme/colors/color256.rb +30 -0
  14. data/lib/pry-theme/colors/color8.rb +31 -0
  15. data/lib/pry-theme/commands.rb +237 -275
  16. data/lib/pry-theme/declaration.rb +120 -0
  17. data/lib/pry-theme/definition.rb +111 -0
  18. data/lib/pry-theme/formattable.rb +26 -0
  19. data/lib/pry-theme/hex.rb +76 -0
  20. data/lib/pry-theme/preview.rb +74 -0
  21. data/lib/pry-theme/rgb.rb +238 -13
  22. data/lib/pry-theme/term.rb +66 -0
  23. data/lib/pry-theme/theme.rb +116 -26
  24. data/lib/pry-theme/theme_list.rb +52 -0
  25. data/lib/pry-theme/when_started_hook.rb +25 -27
  26. data/lib/pry-theme.rb +84 -158
  27. data/pry-theme.gemspec +14 -18
  28. data/spec/color_table.rb +53 -0
  29. data/spec/colors/color16_spec.rb +255 -0
  30. data/spec/colors/color256_spec.rb +323 -0
  31. data/spec/colors/color8_spec.rb +254 -0
  32. data/spec/commands_spec.rb +203 -0
  33. data/spec/helper.rb +16 -0
  34. data/spec/hex_spec.rb +52 -0
  35. data/spec/rgb_spec.rb +81 -0
  36. data/spec/term_spec.rb +23 -0
  37. data/spec/theme_spec.rb +486 -0
  38. data/themes/github.prytheme.rb +49 -0
  39. data/themes/monokai.prytheme.rb +48 -0
  40. data/themes/pry-classic-16.prytheme.rb +48 -0
  41. data/themes/pry-classic-256.prytheme.rb +48 -0
  42. data/themes/pry-classic-8.prytheme.rb +48 -0
  43. data/themes/pry-cold.prytheme.rb +49 -0
  44. data/themes/pry-love-16.prytheme.rb +48 -0
  45. data/themes/pry-love-8.prytheme.rb +48 -0
  46. data/themes/pry-modern-16.prytheme.rb +48 -0
  47. data/themes/pry-modern-256.prytheme.rb +48 -0
  48. data/themes/pry-modern-8.prytheme.rb +48 -0
  49. data/themes/pry-monochrome.prytheme.rb +32 -0
  50. data/themes/pry-siberia-16.prytheme.rb +48 -0
  51. data/themes/pry-siberia-8.prytheme.rb +48 -0
  52. data/themes/pry-tepid-16.prytheme.rb +48 -0
  53. data/themes/pry-tepid-8.prytheme.rb +48 -0
  54. data/themes/pry-zealand-16.prytheme.rb +48 -0
  55. data/themes/pry-zealand-8.prytheme.rb +49 -0
  56. data/themes/railscasts.prytheme.rb +50 -0
  57. data/themes/solarized.prytheme.rb +48 -0
  58. data/themes/tomorrow.prytheme.rb +48 -0
  59. data/themes/twilight.prytheme.rb +48 -0
  60. data/themes/vim-default.prytheme.rb +50 -0
  61. data/themes/vim-detailed.prytheme.rb +50 -0
  62. data/themes/zenburn.prytheme.rb +48 -0
  63. metadata +56 -41
  64. data/lib/pry-theme/color_converter.rb +0 -55
  65. data/lib/pry-theme/helper.rb +0 -87
  66. data/lib/pry-theme/palette.rb +0 -85
  67. data/lib/pry-theme/term_notation.rb +0 -17
  68. data/lib/pry-theme/version.rb +0 -3
  69. data/test/fixtures/pry-classic.prytheme +0 -38
  70. data/test/helper.rb +0 -56
  71. data/test/test_color_converter.rb +0 -38
  72. data/test/test_commands.rb +0 -55
  73. data/test/test_helper.rb +0 -45
  74. data/test/test_palette.rb +0 -11
  75. data/themes/github.prytheme +0 -43
  76. data/themes/monokai.prytheme +0 -42
  77. data/themes/pry-classic.prytheme +0 -43
  78. data/themes/pry-cold.prytheme +0 -43
  79. data/themes/pry-modern.prytheme +0 -42
  80. data/themes/railscasts.prytheme +0 -44
  81. data/themes/saturday.prytheme +0 -42
  82. data/themes/solarized.prytheme +0 -43
  83. data/themes/tomorrow.prytheme +0 -43
  84. data/themes/twilight.prytheme +0 -42
  85. data/themes/vim-default.prytheme +0 -42
  86. data/themes/vim-detailed.prytheme +0 -42
  87. data/themes/zenburn.prytheme +0 -43
@@ -0,0 +1,53 @@
1
+ require 'helper'
2
+
3
+ describe PryTheme::ColorTable do
4
+ describe "::build_color_string" do
5
+ before do
6
+ @color256 = PryTheme::Color256.new(:foreground => 100, :background => 101)
7
+ @color16 = PryTheme::Color16.new(:foreground => 9, :background => 10)
8
+ @color8 = PryTheme::Color8.new(:foreground => 3, :background => 4)
9
+ end
10
+
11
+ it "builds a suitable (visually) for colour table (256) row" do
12
+ output = PryTheme::ColorTable.build_color_string(@color256)
13
+ output.should ==
14
+ "\e[7;38;5;100;48;5;101m100\e[0m:\e[38;5;100;48;5;101molive01\e[0m"
15
+ end
16
+
17
+ it "builds a suitable (visually) for colour table (16) row" do
18
+ output = PryTheme::ColorTable.build_color_string(@color16)
19
+ output.should == "\e[7;31;1;42m31;1\e[0m:\e[31;1;42mbright_red\e[0m"
20
+ end
21
+
22
+ it "builds a suitable (visually) for colour table (8) row" do
23
+ output = PryTheme::ColorTable.build_color_string(@color8)
24
+ output.should == "\e[7;33;44m33\e[0m:\e[33;44myellow\e[0m"
25
+ end
26
+ end
27
+
28
+ describe "#table" do
29
+ it "returns proper table for with 256 colours" do
30
+ table = PryTheme::ColorTable.t256
31
+ table.should =~ /Color model 256/
32
+ table.should =~ /\e\[7;38;5;147m147\e\[0m:\e\[38;5;147mwisteria02\e\[0m/
33
+ table.should =~ /\n \e\[7;38;5;24m24\e\[0m:\e\[38;5;24mcerulean_grey01\e\[0m/
34
+ table.should =~ /\e\[7;38;5;0m0\e\[0m:\e\[38;5;0mblack\e\[0m/
35
+ end
36
+
37
+ it "returns proper table for with 16 colours" do
38
+ table = PryTheme::ColorTable.t16
39
+ table.should =~ /Color model 16/
40
+ table.should =~ /\n \e\[7;30m0\e\[0m:\e\[30mblack\e\[0m/
41
+ table.should =~ /\e\[7;35;1m13\e\[0m:\e\[35;1mbright_magenta\e\[0m/
42
+ table.should =~ /\e\[7;37;1m15\e\[0m:\e\[37;1mbright_white\e\[0m\n/
43
+ end
44
+
45
+ it "returns proper table for with 8 colours" do
46
+ table = PryTheme::ColorTable.t8
47
+ table.should =~ /Color model 8/
48
+ table.should =~ /: \e\[7;30m0\e\[0m:\e\[30mblack\e\[0m/
49
+ table.should =~ /\e\[7;33m3\e\[0m:\e\[33myellow\e\[0m/
50
+ table.should =~ /\e\[7;37m7\e\[0m:\e\[37mwhite\e\[0m\n/
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,255 @@
1
+ require 'helper'
2
+
3
+ describe PryTheme::Color16 do
4
+ Color16 = PryTheme::Color16
5
+
6
+ describe "foreground" do
7
+ it "can be set" do
8
+ color = Color16.new(:foreground => 'bright_red')
9
+ color.foreground(true).should == 'bright_red'
10
+ color.to_ansi.should == '31;1'
11
+
12
+ color = Color16.new(:foreground => 'red')
13
+ color.foreground(true).should == 'red'
14
+ color.to_ansi.should == '31'
15
+ end
16
+
17
+ it "defaults to no colour at all" do
18
+ color = Color16.new
19
+ color.foreground(true).should == false
20
+ color.to_ansi.should == '39;49'
21
+ end
22
+
23
+ it "raises error on invalid value" do
24
+ lambda { Color16.new(:foreground => 'blah') }.
25
+ should.raise(ArgumentError).
26
+ message.should.match /invalid foreground value "blah"/
27
+ end
28
+ end
29
+
30
+ describe "background" do
31
+ it "can be set" do
32
+ color = Color16.new(:background => 'blue')
33
+ color.background(true).should == 'blue'
34
+ color.to_ansi.should == '44'
35
+ end
36
+
37
+ it "raises error on invalid value" do
38
+ lambda { Color16.new(:background => 'blah') }.
39
+ should.raise(ArgumentError).
40
+ message.should.match /invalid background value "blah"/
41
+ end
42
+ end
43
+
44
+ describe "foreground combined with background" do
45
+ it "can be set" do
46
+ color = Color16.new(
47
+ :foreground => 'bright_yellow',
48
+ :background => 'bright_white')
49
+ color.foreground(true).should == 'bright_yellow'
50
+ color.background(true).should == 'bright_white'
51
+ color.to_ansi.should == '33;1;47'
52
+ end
53
+ end
54
+
55
+ describe "effects" do
56
+ it "can't be bold" do
57
+ lambda { Color16.new(:bold => true).bold? }.should.raise(NoMethodError)
58
+ end
59
+
60
+ it "can't be italic" do
61
+ lambda { Color16.new(:italic => true).italic?
62
+ }.should.raise(NoMethodError)
63
+ end
64
+
65
+ it "can't be underlined" do
66
+ lambda { Color16.new(:underline => true).underline?
67
+ }.should.raise(NoMethodError)
68
+ end
69
+ end
70
+
71
+ describe "argument types" do
72
+ describe "readable" do
73
+ it "works" do
74
+ lambda {
75
+ Color16.new(
76
+ :from => :readable,
77
+ :foreground => 'yellow',
78
+ :background => 'yellow')
79
+ }.should.not.raise
80
+ end
81
+
82
+ it "doesn't work with incorrect input" do
83
+ lambda {
84
+ Color16.new(
85
+ :from => :readable,
86
+ :foreground => 'yellow',
87
+ :background => '')
88
+ }.should.raise(ArgumentError)
89
+ end
90
+
91
+ it "sets background and foreground properly" do
92
+ color = Color16.new(:from => :readable,
93
+ :foreground => 'bright_black',
94
+ :background => 'green')
95
+ color.foreground.should == '30;1'
96
+ color.foreground(true).should == 'bright_black'
97
+ color.background.should == 42
98
+ color.background(true).should == 'green'
99
+ end
100
+
101
+ it "sets foreground properly" do
102
+ color = Color16.new(:from => :readable, :foreground => 'bright_black')
103
+ color.foreground.should == '30;1'
104
+ color.foreground(true).should == 'bright_black'
105
+ color.background.should == false
106
+ color.background(true).should == false
107
+ end
108
+
109
+ it "sets background properly" do
110
+ color = Color16.new(:from => :readable, :background => 'green')
111
+ color.foreground.should == false
112
+ color.foreground(true).should == false
113
+ color.background.should == 42
114
+ color.background(true).should == 'green'
115
+ end
116
+ end
117
+
118
+ describe "hex" do
119
+ it "works" do
120
+ lambda {
121
+ Color16.new(
122
+ :from => :hex,
123
+ :foreground => '#afaf11',
124
+ :background => '#eaeaea')
125
+ }.should.not.raise
126
+ end
127
+
128
+ it "doesn't work with incorrect input" do
129
+ lambda {
130
+ Color16.new(
131
+ :from => :hex,
132
+ :foreground => '#222222',
133
+ :background => [123, 11, 44])
134
+ }.should.raise(TypeError)
135
+ end
136
+
137
+ it "sets background and foreground properly" do
138
+ color = Color16.new(:from => :hex,
139
+ :foreground => '#afaf11',
140
+ :background => '#eaeaea')
141
+ color.foreground.should == '30;1'
142
+ color.foreground(true).should == 'bright_black'
143
+ color.background.should == 43
144
+ color.background(true).should == 'bright_yellow'
145
+ end
146
+
147
+ it "sets foreground properly" do
148
+ color = Color16.new(:from => :hex, :foreground => '#afaf11')
149
+ color.foreground.should == '30;1'
150
+ color.foreground(true).should == 'bright_black'
151
+ color.background.should == false
152
+ color.background(true).should == false
153
+ end
154
+
155
+ it "sets background properly" do
156
+ color = Color16.new(:from => :hex, :background => '#eaeaea')
157
+ color.foreground.should == false
158
+ color.foreground(true).should == false
159
+ color.background.should == 43
160
+ color.background(true).should == 'bright_yellow'
161
+ end
162
+ end
163
+
164
+ describe "rgb" do
165
+ it "works" do
166
+ lambda {
167
+ Color16.new(
168
+ :from => :rgb,
169
+ :foreground => '31, 125, 88',
170
+ :background => [123, 11, 44])
171
+ }.should.not.raise(ArgumentError)
172
+ end
173
+
174
+ it "doesn't work with incorrect input" do
175
+ lambda {
176
+ Color16.new(
177
+ :from => :rgb,
178
+ :foreground => '#222222',
179
+ :background => [123, 11, 44])
180
+ }.should.raise(ArgumentError)
181
+ end
182
+
183
+ it "sets background and foreground properly" do
184
+ color = Color16.new(:from => :rgb,
185
+ :foreground => '31, 31, 101',
186
+ :background => '125, 101, 255')
187
+ color.foreground.should == 31
188
+ color.foreground(true).should == 'red'
189
+ color.background.should == 46
190
+ color.background(true).should == 'cyan'
191
+ end
192
+
193
+ it "sets foreground properly" do
194
+ color = Color16.new(:from => :rgb, :foreground => '31, 31, 101')
195
+ color.foreground.should == 31
196
+ color.foreground(true).should == 'red'
197
+ color.background.should == false
198
+ color.background(true).should == false
199
+ end
200
+
201
+ it "sets background properly" do
202
+ color = Color16.new(:from => :rgb, :background => '125, 101, 255')
203
+ color.foreground.should == false
204
+ color.foreground(true).should == false
205
+ color.background.should == 46
206
+ color.background(true).should == 'cyan'
207
+ end
208
+ end
209
+
210
+ describe "term" do
211
+ it "works" do
212
+ lambda {
213
+ Color16.new(
214
+ :from => :term,
215
+ :foreground => 10,
216
+ :background => 7)
217
+ }.should.not.raise(ArgumentError)
218
+ end
219
+
220
+ it "doesn't work with incorrect input" do
221
+ lambda {
222
+ Color16.new(
223
+ :from => :term,
224
+ :foreground => 10,
225
+ :background => 'asd')
226
+ }.should.raise(TypeError)
227
+ end
228
+
229
+ it "sets background and foreground properly" do
230
+ color = Color16.new(:from => :term, :foreground => 4, :background => 8)
231
+ color.foreground.should == 34
232
+ color.foreground(true).should == 'blue'
233
+ color.background.should == 40
234
+ color.background(true).should == 'bright_black'
235
+ end
236
+
237
+ it "sets foreground properly" do
238
+ color = Color16.new(:from => :term, :foreground => 4)
239
+ color.foreground.should == 34
240
+ color.foreground(true).should == 'blue'
241
+ color.background.should == false
242
+ color.background(true).should == false
243
+ end
244
+
245
+ it "sets background properly" do
246
+ color = Color16.new(:from => :term, :background => 8)
247
+ color.foreground.should == false
248
+ color.foreground(true).should == false
249
+ color.background.should == 40
250
+ color.background(true).should == 'bright_black'
251
+ end
252
+ end
253
+ end
254
+
255
+ end
@@ -0,0 +1,323 @@
1
+ require 'helper'
2
+
3
+ describe PryTheme::Color256 do
4
+ Color256 = PryTheme::Color256
5
+
6
+ describe "foreground" do
7
+ it "can be set" do
8
+ color = Color256.new(:foreground => 'bright_violet')
9
+ color.foreground(true).should == 'bright_violet'
10
+ color.to_ansi.should == '38;5;128'
11
+ end
12
+
13
+ it "defaults to no colour at all" do
14
+ color = Color256.new
15
+ color.foreground(true).should == false
16
+ color.to_ansi.should == '0'
17
+ end
18
+
19
+ it "raises error on invalid value" do
20
+ lambda { Color256.new(:foreground => 'blah') }.
21
+ should.raise(ArgumentError).
22
+ message.should.match /invalid foreground value "blah"/
23
+ end
24
+
25
+ describe "effects" do
26
+ it "not used if there is a custom foreground" do
27
+ color = Color256.new(:foreground => 'bright_violet')
28
+ color.bold?.should == false
29
+ color.underline?.should == false
30
+ color.italic?.should == false
31
+ color.to_ansi.should == '38;5;128'
32
+ end
33
+
34
+ it "uses bold" do
35
+ color = Color256.new(:foreground => 'dark_pear', :bold => true)
36
+ color.bold?.should == true
37
+ color.underline?.should == false
38
+ color.italic?.should == false
39
+ color.to_ansi.should == '38;5;178;1'
40
+ end
41
+
42
+ it "uses underline" do
43
+ color = Color256.new(:foreground => 'royal_blue03', :underline => true)
44
+ color.bold?.should == false
45
+ color.underline?.should == true
46
+ color.italic?.should == false
47
+ color.to_ansi.should == '38;5;62;4'
48
+ end
49
+
50
+ it "uses italic" do
51
+ color = Color256.new(:foreground => 'cerise01', :italic => true)
52
+ color.bold?.should == false
53
+ color.underline?.should == false
54
+ color.italic?.should == true
55
+ color.to_ansi.should == '38;5;161;3'
56
+ end
57
+
58
+ it "combines everything" do
59
+ color = Color256.new(
60
+ :foreground => 'titian',
61
+ :italic => true,
62
+ :bold => true,
63
+ :underline => true)
64
+ color.bold?.should == true
65
+ color.underline?.should == true
66
+ color.italic?.should == true
67
+ color.to_ansi.should == '38;5;160;1;3;4'
68
+ end
69
+
70
+ describe "with defaults" do
71
+ it "not used for the default colours" do
72
+ color = Color256.new
73
+ color.bold?.should == false
74
+ color.underline?.should == false
75
+ color.italic?.should == false
76
+ color.to_ansi.should == '0'
77
+ end
78
+
79
+ it "can be used without foreground" do
80
+ color = Color256.new(:background => 'bistre', :bold => true)
81
+ color.bold?.should == true
82
+ color.underline?.should == false
83
+ color.italic?.should == false
84
+ color.to_ansi.should == '48;5;235;1'
85
+ end
86
+
87
+ it "can be used with the default colour" do
88
+ color = Color256.new(:bold => true, :italic => true, :underline => true)
89
+ color.bold?.should == true
90
+ color.underline?.should == true
91
+ color.italic?.should == true
92
+ color.to_ansi.should == '1;3;4'
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ describe "background" do
99
+ it "can be set" do
100
+ color = Color256.new(:background => 'bright_violet')
101
+ color.background(true).should == 'bright_violet'
102
+ color.to_ansi.should == '48;5;128'
103
+ end
104
+
105
+ it "defaults to no colour at all" do
106
+ color = Color256.new
107
+ color.background(true).should == false
108
+ color.to_ansi.should == '0'
109
+ end
110
+
111
+ it "raises error on invalid value" do
112
+ lambda { Color256.new(:background => 'BLACK') }.
113
+ should.raise(ArgumentError).
114
+ message.should.match /invalid background value "BLACK"/
115
+ end
116
+ end
117
+
118
+ describe "foreground combined with background" do
119
+ it "can be set" do
120
+ color = Color256.new(
121
+ :background => 'red_violet01',
122
+ :foreground => 'pale_brown')
123
+ color.foreground(true).should == 'pale_brown'
124
+ color.background(true).should == 'red_violet01'
125
+ color.to_ansi.should == '38;5;137;48;5;126'
126
+ end
127
+
128
+ it "can be set with effects" do
129
+ color = Color256.new(
130
+ :background => 'red_violet01',
131
+ :foreground => 'pale_brown',
132
+ :italic => true,
133
+ :bold => true,
134
+ :underline => true)
135
+ color.to_ansi.should == '38;5;137;1;3;4;48;5;126'
136
+ end
137
+ end
138
+
139
+ describe "argument types" do
140
+ describe "readable" do
141
+ it "works" do
142
+ lambda {
143
+ Color256.new(
144
+ :from => :readable,
145
+ :foreground => 'tan',
146
+ :background => 'gold')
147
+ }.should.not.raise
148
+ end
149
+
150
+ it "doesn't work with incorrect input" do
151
+ lambda {
152
+ Color256.new(
153
+ :from => :readable,
154
+ :foreground => '#222222',
155
+ :background => [123, 11, 44])
156
+ }.should.raise(ArgumentError)
157
+ end
158
+
159
+ it "sets background and foreground properly" do
160
+ color = Color256.new(:from => :readable,
161
+ :foreground => 'dark_indigo',
162
+ :background => 'klein_blue')
163
+ color.foreground.should == 17
164
+ color.foreground(true).should == 'dark_indigo'
165
+ color.background.should == 32
166
+ color.background(true).should == 'klein_blue'
167
+ end
168
+
169
+ it "sets foreground properly" do
170
+ color = Color256.new(:from => :readable, :foreground => 'dark_indigo')
171
+ color.foreground.should == 17
172
+ color.foreground(true).should == 'dark_indigo'
173
+ color.background.should == false
174
+ color.background(true).should == false
175
+ end
176
+
177
+ it "sets background properly" do
178
+ color = Color256.new(:from => :readable, :background => 'klein_blue')
179
+ color.foreground.should == false
180
+ color.foreground(true).should == false
181
+ color.background.should == 32
182
+ color.background(true).should == 'klein_blue'
183
+ end
184
+ end
185
+
186
+ describe "hex" do
187
+ it "works" do
188
+ lambda {
189
+ Color256.new(
190
+ :from => :hex,
191
+ :foreground => '#afaf11',
192
+ :background => '#eaeaea')
193
+ }.should.not.raise
194
+ end
195
+
196
+ it "doesn't work with incorrect input" do
197
+ lambda {
198
+ Color256.new(
199
+ :from => :hex,
200
+ :foreground => '#222222',
201
+ :background => [123, 11, 44])
202
+ }.should.raise(TypeError)
203
+ end
204
+
205
+ it "sets background and foreground properly" do
206
+ color = Color256.new(:from => :hex,
207
+ :foreground => '#afaf11',
208
+ :background => '#eaeaea')
209
+ color.foreground.should == 142
210
+ color.foreground(true).should == 'old_gold'
211
+ color.background.should == 189
212
+ color.background(true).should == 'periwinkle'
213
+ end
214
+
215
+ it "sets foreground properly" do
216
+ color = Color256.new(:from => :hex, :foreground => '#afaf11')
217
+ color.foreground.should == 142
218
+ color.foreground(true).should == 'old_gold'
219
+ color.background.should == false
220
+ color.background(true).should == false
221
+ end
222
+
223
+ it "sets background properly" do
224
+ color = Color256.new(:from => :hex, :background => '#eaeaea')
225
+ color.foreground.should == false
226
+ color.foreground(true).should == false
227
+ color.background.should == 189
228
+ color.background(true).should == 'periwinkle'
229
+ end
230
+ end
231
+
232
+ describe "rgb" do
233
+ it "works" do
234
+ lambda {
235
+ Color256.new(
236
+ :from => :rgb,
237
+ :foreground => '31, 125, 88',
238
+ :background => [123, 11, 44])
239
+ }.should.not.raise(ArgumentError)
240
+ end
241
+
242
+ it "doesn't work with incorrect input" do
243
+ lambda {
244
+ Color256.new(
245
+ :from => :rgb,
246
+ :foreground => '#222222',
247
+ :background => [123, 11, 44])
248
+ }.should.raise(ArgumentError)
249
+ end
250
+
251
+ it "sets background and foreground properly" do
252
+ color = Color256.new(:from => :rgb,
253
+ :foreground => '31, 31, 101',
254
+ :background => '125, 101, 255')
255
+ color.foreground.should == 17
256
+ color.foreground(true).should == 'dark_indigo'
257
+ color.background.should == 99
258
+ color.background(true).should == 'heliotrope01'
259
+ end
260
+
261
+ it "sets foreground properly" do
262
+ color = Color256.new(:from => :rgb, :foreground => '31, 31, 101')
263
+ color.foreground.should == 17
264
+ color.foreground(true).should == 'dark_indigo'
265
+ color.background.should == false
266
+ color.background(true).should == false
267
+ end
268
+
269
+ it "sets background properly" do
270
+ color = Color256.new(:from => :rgb, :background => '125, 101, 255')
271
+ color.foreground.should == false
272
+ color.foreground(true).should == false
273
+ color.background.should == 99
274
+ color.background(true).should == 'heliotrope01'
275
+ end
276
+ end
277
+
278
+ describe "term" do
279
+ it "works" do
280
+ lambda {
281
+ Color256.new(
282
+ :from => :term,
283
+ :foreground => 31,
284
+ :background => 123)
285
+ }.should.not.raise(ArgumentError)
286
+ end
287
+
288
+ it "doesn't work with incorrect input" do
289
+ lambda {
290
+ Color256.new(
291
+ :from => :term,
292
+ :foreground => '#222222',
293
+ :background => 'gray05')
294
+ }.should.raise(TypeError)
295
+ end
296
+
297
+ it "sets background and foreground properly" do
298
+ color = Color256.new(:from => :term, :foreground => 4, :background => 84)
299
+ color.foreground.should == 4
300
+ color.foreground(true).should == 'navy_blue'
301
+ color.background.should == 84
302
+ color.background(true).should == 'spring_green03'
303
+ end
304
+
305
+ it "sets foreground properly" do
306
+ color = Color256.new(:from => :term, :foreground => 4)
307
+ color.foreground.should == 4
308
+ color.foreground(true).should == 'navy_blue'
309
+ color.background.should == false
310
+ color.background(true).should == false
311
+ end
312
+
313
+ it "sets background properly" do
314
+ color = Color256.new(:from => :term, :background => 84)
315
+ color.foreground.should == false
316
+ color.foreground(true).should == false
317
+ color.background.should == 84
318
+ color.background(true).should == 'spring_green03'
319
+ end
320
+ end
321
+ end
322
+
323
+ end