pry-theme 0.1.3 → 0.2.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 (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,431 @@
1
+ module PryTheme
2
+ class Color
3
+
4
+ # Stores all possible colours for foregrounds and backgrounds, for 256, 16
5
+ # and 8 colour palettes.
6
+ @@colors = {
7
+ :foreground => {
8
+ 256 => {
9
+ 'black' => [0, 16],
10
+ 'maroon' => 1,
11
+ 'toad_in_love' => 2,
12
+ 'olive' => 3,
13
+ 'navy_blue' => 4,
14
+ 'violet_eggplant' => 5,
15
+ 'teal' => 6,
16
+ 'silver' => 7,
17
+ 'gray' => [8, 244],
18
+ 'red' => [9, 196],
19
+ 'green' => [10, 46],
20
+ 'yellow' => [11, 226],
21
+ 'blue' => [12, 21],
22
+ 'magenta' => [13, 201],
23
+ 'cyan' => [14, 51],
24
+ 'white' => [15, 231],
25
+ 'dark_indigo' => 17,
26
+ 'ultramarine01' => 18,
27
+ 'ultramarine02' => 19,
28
+ 'persian_blue01' => 20,
29
+ 'dark_spring_green' => 22,
30
+ 'dark_turquoise' => 23,
31
+ 'cerulean_grey01' => 24,
32
+ 'denim01' => 25,
33
+ 'royal_blue01' => 26,
34
+ 'royal_blue02' => 27,
35
+ 'toad_in_love01' => 28,
36
+ 'sea_green01' => 29,
37
+ 'teal01' => 30,
38
+ 'cerulean_grey02' => 31,
39
+ 'klein_blue' => 32,
40
+ 'azure01' => 33,
41
+ 'vert_de_pomme01' => 34,
42
+ 'jade01' => 35,
43
+ 'jade02' => 36,
44
+ 'robin_egg_blue01' => 37,
45
+ 'bondi_blue' => 38,
46
+ 'light_blue01' => 39,
47
+ 'vert_de_pomme02' => 40,
48
+ 'malachite01' => 41,
49
+ 'emerald01' => 42,
50
+ 'turquoise' => 43,
51
+ 'robin_egg_blue02' => 44,
52
+ 'electric01' => 45,
53
+ 'spring_green01' => 47,
54
+ 'spring_green02' => 48,
55
+ 'mint_green01' => 49,
56
+ 'aquamarine01' => 50,
57
+ 'flea_belly' => 52,
58
+ 'plum' => 53,
59
+ 'indigo' => 54,
60
+ 'purple01' => 55,
61
+ 'violet01' => 56,
62
+ 'persian_blue02' => 57,
63
+ 'khaki01' => 58,
64
+ 'wet_asphalt01' => 59,
65
+ 'seroburomalinovyj01' => 60,
66
+ 'denim02' => 61,
67
+ 'royal_blue03' => 62,
68
+ 'royal_blue04' => 63,
69
+ 'olive_drab' => 64,
70
+ 'fern_green' => 65,
71
+ 'slate_gray' => 66,
72
+ 'steel_blue' => 67,
73
+ 'cornflower_blue01' => 68,
74
+ 'azure02' => 69,
75
+ 'grass01' => 70,
76
+ 'emerald02' => 71,
77
+ 'sea_green02' => 72,
78
+ 'robin_egg_blue03' => 73,
79
+ 'bluish01' => 74,
80
+ 'light_blue02' => 75,
81
+ 'vert_de_pomme03' => 76,
82
+ 'pale_green01' => 77,
83
+ 'emerald03' => 78,
84
+ 'aquamarine02' => 79,
85
+ 'robin_egg_blue04' => 80,
86
+ 'sky01' => 81,
87
+ 'bright_green' => 82,
88
+ 'malachite02' => 83,
89
+ 'spring_green03' => 84,
90
+ 'chartreuse01' => 85,
91
+ 'aquamarine03' => 86,
92
+ 'cyan01' => 87,
93
+ 'maroon01' => 88,
94
+ 'eggplant01' => 89,
95
+ 'violet_eggplant01' => 90,
96
+ 'purple02' => 91,
97
+ 'violet02' => 92,
98
+ 'violet03' => 93,
99
+ 'khaki02' => 94,
100
+ 'pale_mauve01' => 95,
101
+ 'seroburomalinovyj02' => 96,
102
+ 'amethyst01' => 97,
103
+ 'amethyst02' => 98,
104
+ 'heliotrope01' => 99,
105
+ 'olive01' => 100,
106
+ 'dark_tan' => 101,
107
+ 'gray01' => [102, 243],
108
+ 'bluish02' => 103,
109
+ 'cornflower_blue02' => 104,
110
+ 'royal_blue05' => 105,
111
+ 'grass02' => 106,
112
+ 'asparagus' => 107,
113
+ 'swamp_green01' => 108,
114
+ 'light_grey01' => 109,
115
+ 'bluish03' => 110,
116
+ 'cornflower_blue03' => 111,
117
+ 'green_yellow01' => 112,
118
+ 'pale_green02' => 113,
119
+ 'emerald04' => 114,
120
+ 'celadon' => 115,
121
+ 'pale_blue01' => 116,
122
+ 'sky02' => 117,
123
+ 'viridian' => 118,
124
+ 'vert_de_pomme04' => 119,
125
+ 'mint_green02' => 120,
126
+ 'chartreuse02' => 121,
127
+ 'aquamarine04' => 122,
128
+ 'electric02' => 123,
129
+ 'bismarck_furious' => 124,
130
+ 'eggplant02' => 125,
131
+ 'red_violet01' => 126,
132
+ 'violet_eggplant02' => 127,
133
+ 'bright_violet' => [128, 164],
134
+ 'violet04' => 129,
135
+ 'ochre' => 130,
136
+ 'pale_mauve02' => 131,
137
+ 'pale_red_violet01' => 132,
138
+ 'orchid01' => 133,
139
+ 'amethyst03' => 134,
140
+ 'heliotrope02' => 135,
141
+ 'dark_goldenrod' => 136,
142
+ 'pale_brown' => 137,
143
+ 'mountbatten_pink' => 138,
144
+ 'lilac01' => 139,
145
+ 'wisteria01' => 140,
146
+ 'amethyst04' => 141,
147
+ 'old_gold' => 142,
148
+ 'brass01' => 143,
149
+ 'swamp_green02' => 144,
150
+ 'light_grey02' => 145,
151
+ 'niagara' => 146,
152
+ 'wisteria02' => 147,
153
+ 'lime01' => 148,
154
+ 'pistachio01' => 149,
155
+ 'moss_green' => 150,
156
+ 'dark_tea_green' => 151,
157
+ 'pale_blue02' => 152,
158
+ 'pale_cornflower_blue' => 153,
159
+ 'green_yellow02' => 154,
160
+ 'green_yellow03' => 155,
161
+ 'pistachio02' => 156,
162
+ 'chartreuse03' => 157,
163
+ 'aquamarine05' => 158,
164
+ 'pale_blue03' => 159,
165
+ 'titian' => 160,
166
+ 'cerise01' => 161,
167
+ 'red_violet02' => 162,
168
+ 'hot_pink01' => 163,
169
+ 'magenta01' => 165,
170
+ 'tenne' => 166,
171
+ 'chestnut01' => 167,
172
+ 'pale_red_violet02' => 168,
173
+ 'orchid02' => 169,
174
+ 'orchid03' => 170,
175
+ 'heliotrope03' => 171,
176
+ 'siena' => 172,
177
+ 'dark_salmon' => 173,
178
+ 'puce01' => 174,
179
+ 'puce2' => 175,
180
+ 'violaceous01' => 176,
181
+ 'violaceous02' => 177,
182
+ 'dark_pear' => 178,
183
+ 'brass02' => 179,
184
+ 'tan' => 180,
185
+ 'pale_chestnut' => 181,
186
+ 'lilac02' => 182,
187
+ 'wisteria03' => 183,
188
+ 'childs_surprise' => 184,
189
+ 'vert_de_peche' => 185,
190
+ 'flax' => 186,
191
+ 'gray_tea_green' => 187,
192
+ 'abdel_kerims_beard01' => 188,
193
+ 'periwinkle' => 189,
194
+ 'lime02' => 190,
195
+ 'pistachio03' => 191,
196
+ 'pistachio04' => 192,
197
+ 'tea_green01' => 193,
198
+ 'tea_green02' => 194,
199
+ 'pang' => 195,
200
+ 'crimson' => 197,
201
+ 'cerise02' => 198,
202
+ 'hot_pink02' => 199,
203
+ 'hot_pink03' => 200,
204
+ 'international_orange' => 202,
205
+ 'alizarin' => 203,
206
+ 'dark_pink01' => 204,
207
+ 'dark_pink02' => 205,
208
+ 'shocked_star' => 206,
209
+ 'fuchsia' => 207,
210
+ 'tangerine' => 208,
211
+ 'salmon' => 209,
212
+ 'chestnut02' => 210,
213
+ 'pale_red_violet03' => 211,
214
+ 'pale_magenta' => 212,
215
+ 'violaceous03' => 213,
216
+ 'orange' => 214,
217
+ 'pink_orange' => 215,
218
+ 'saumon' => 216,
219
+ 'pink01' => 217,
220
+ 'pink02' => 218,
221
+ 'violaceous04' => 219,
222
+ 'gold' => 220,
223
+ 'mustard01' => 221,
224
+ 'mustard02' => 222,
225
+ 'dark_peach' => 223,
226
+ 'pale_pink' => 224,
227
+ 'thistle' => 225,
228
+ 'corn01' => 227,
229
+ 'corn02' => 228,
230
+ 'perhydor' => 229,
231
+ 'lemon_cream' => 230,
232
+ 'black01' => 232,
233
+ 'black02' => 233,
234
+ 'black03' => 234,
235
+ 'bistre' => 235,
236
+ 'anthracite' => 236,
237
+ 'wet_asphalt02' => 237,
238
+ 'wet_asphalt03' => 238,
239
+ 'wet_asphalt04' => 239,
240
+ 'wet_asphalt05' => 240,
241
+ 'wet_asphalt06' => 241,
242
+ 'wet_asphalt07' => 242,
243
+ 'gray02' => 245,
244
+ 'gray03' => 246,
245
+ 'gray04' => 247,
246
+ 'gray05' => 248,
247
+ 'light_grey03' => 249,
248
+ 'light_grey04' => 250,
249
+ 'silver01' => 251,
250
+ 'abdel_kerims_beard02' => 252,
251
+ 'abdel_kerims_beard03' => 253,
252
+ 'abdel_kerims_beard04' => 254,
253
+ 'seashell' => 255
254
+ },
255
+ 16 => {
256
+ 'black' => 30,
257
+ 'red' => 31,
258
+ 'green' => 32,
259
+ 'yellow' => 33,
260
+ 'blue' => 34,
261
+ 'magenta' => 35,
262
+ 'cyan' => 36,
263
+ 'white' => 37,
264
+ 'bright_black' => [30, 1],
265
+ 'bright_red' => [31, 1],
266
+ 'bright_green' => [32, 1],
267
+ 'bright_yellow' => [33, 1],
268
+ 'bright_blue' => [34, 1],
269
+ 'bright_magenta' => [35, 1],
270
+ 'bright_cyan' => [36, 1],
271
+ 'bright_white' => [37, 1],
272
+ },
273
+ 8 => {
274
+ 'black' => 30,
275
+ 'red' => 31,
276
+ 'green' => 32,
277
+ 'yellow' => 33,
278
+ 'blue' => 34,
279
+ 'magenta' => 35,
280
+ 'cyan' => 36,
281
+ 'white' => 37,
282
+ }
283
+ },
284
+ :background => {
285
+ 16 => {
286
+ 'black' => 40,
287
+ 'red' => 41,
288
+ 'green' => 42,
289
+ 'yellow' => 43,
290
+ 'blue' => 44,
291
+ 'magenta' => 45,
292
+ 'cyan' => 46,
293
+ 'white' => 47,
294
+ 'bright_black' => 40,
295
+ 'bright_red' => 41,
296
+ 'bright_green' => 42,
297
+ 'bright_yellow' => 43,
298
+ 'bright_blue' => 44,
299
+ 'bright_magenta' => 45,
300
+ 'bright_cyan' => 46,
301
+ 'bright_white' => 47,
302
+ },
303
+ }
304
+ }
305
+ @@colors[:background][256] = @@colors[:foreground][256]
306
+ @@colors[:background][8] = @@colors[:background][16]
307
+
308
+ # The default colour options Hash.
309
+ OPTS = {
310
+ :from => :readable,
311
+ :foreground => false,
312
+ :background => false,
313
+ :bold => false,
314
+ :italic => false,
315
+ :underline => false,
316
+ }
317
+
318
+ attr_reader :color_model
319
+
320
+ # @return []
321
+ attr_reader :options
322
+
323
+ def initialize(color_model, options = {})
324
+ @options = OPTS.merge(options)
325
+ @color_model = color_model
326
+ set_layers
327
+ end
328
+
329
+ def foreground(readable = false)
330
+ @readable_fg = find_color(:foreground)
331
+ readable ? @readable_fg : layer_color(colors[@readable_fg])
332
+ end
333
+
334
+ def background(readable = false)
335
+ @readable_bg = find_color(:background)
336
+ readable ? @readable_bg : layer_color(colors(:background)[@readable_bg])
337
+ end
338
+
339
+ def to_ansi
340
+ fg, bg = !!foreground, !!background
341
+ create_ansi_sequence(fg, bg)
342
+ end
343
+
344
+ private
345
+
346
+ def set_layers
347
+ foreground
348
+ background
349
+ end
350
+
351
+ def create_ansi_sequence(fg, bg, default_seq)
352
+ (if fg && bg
353
+ [[build_fg_sequence], [build_effects_sequence], [build_bg_sequence]].flatten
354
+ elsif fg && !bg
355
+ [[build_fg_sequence], [build_effects_sequence]].flatten
356
+ elsif !fg && bg
357
+ [[build_bg_sequence], [build_effects_sequence]].flatten
358
+ else
359
+ build_effects_sequence.tap { |sequence|
360
+ sequence << default_seq if sequence.empty?
361
+ }
362
+ end).join(';')
363
+ end
364
+
365
+ def build_fg_sequence
366
+ [foreground]
367
+ end
368
+
369
+ def build_effects_sequence
370
+ [bold, italic, underline].delete_if { |e| e == false }
371
+ end
372
+
373
+ def build_bg_sequence
374
+ [background]
375
+ end
376
+
377
+ def layer_color(layer)
378
+ if layer
379
+ layer.is_a?(Array) ? build_layer(layer) : layer
380
+ else
381
+ false
382
+ end
383
+ end
384
+
385
+ def build_layer(layer)
386
+ layer.first
387
+ end
388
+
389
+ def find_color(layer)
390
+ case (color_id = cast_color(layer))
391
+ when String
392
+ return color_id if colors.has_key?(color_id)
393
+ when Fixnum
394
+ color_id = find_from_fixnum(color_id)
395
+ return color_id if color_id
396
+ when false
397
+ return color_id
398
+ end
399
+
400
+ raise ArgumentError, %|invalid #{ layer.to_s } value "#{ color_id }"|
401
+ end
402
+
403
+ def cast_color(layer)
404
+ return false unless options[layer]
405
+
406
+ case options[:from]
407
+ when :readable
408
+ options[layer]
409
+ when :hex
410
+ HEX.new(options[layer]).to_term(color_model).to_i
411
+ when :rgb
412
+ RGB.new(options[layer]).to_term(color_model).to_i
413
+ when :term
414
+ TERM.new(options[layer], color_model).to_i
415
+ end
416
+ end
417
+
418
+ def colors(layer = :foreground)
419
+ @@colors[layer][color_model]
420
+ end
421
+
422
+ def sorted_colors
423
+ colors.sort_by { |k, v| v.is_a?(Array) ? v.first + 10 : v }
424
+ end
425
+
426
+ end
427
+ end
428
+
429
+ Dir[File.expand_path('../colors/*.rb', __FILE__)].each do |file|
430
+ require file
431
+ end
@@ -0,0 +1,39 @@
1
+ module PryTheme
2
+ class ColorTable
3
+
4
+ class << self
5
+ def t256
6
+ ColorTable.new(256).table
7
+ end
8
+
9
+ def t16
10
+ ColorTable.new(16).table
11
+ end
12
+
13
+ def t8
14
+ ColorTable.new(8).table
15
+ end
16
+
17
+ def build_color_string(color, fg = nil)
18
+ "\e[7;%sm%s\e[0m:\e[%sm%s\e[0m" %
19
+ [color.to_ansi, fg || color.foreground,
20
+ color.to_ansi, color.foreground(true)]
21
+ end
22
+ end
23
+
24
+ def initialize(color_model)
25
+ @color_model = color_model
26
+ end
27
+
28
+ def table
29
+ colors = []
30
+ 0.upto(@color_model - 1) { |i|
31
+ color = PryTheme.const_get(:"Color#@color_model").new(
32
+ :from => :term, :foreground => i)
33
+ colors << self.class.build_color_string(color, i)
34
+ }
35
+ Pry::Helpers.tablify_or_one_line("Color model #@color_model", colors)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ module PryTheme
2
+ class Color16 < Color
3
+
4
+ def initialize(options = {})
5
+ super(16, options)
6
+ end
7
+
8
+ private
9
+
10
+ def create_ansi_sequence(fg, bg)
11
+ super(fg, bg, '39;49')
12
+ end
13
+
14
+ def build_fg_sequence
15
+ [foreground]
16
+ end
17
+
18
+ def build_bg_sequence
19
+ [background]
20
+ end
21
+
22
+ def build_effects_sequence
23
+ []
24
+ end
25
+
26
+ def find_from_fixnum(color_id)
27
+ sorted_colors.each_with_index.to_a.rassoc(color_id).first.first
28
+ end
29
+
30
+ def build_layer(layer)
31
+ layer.join(';')
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,30 @@
1
+ module PryTheme
2
+ class Color256 < PryTheme::Color
3
+
4
+ include Formattable
5
+
6
+ def initialize(options = {})
7
+ super(256, options)
8
+ end
9
+
10
+ private
11
+
12
+ def create_ansi_sequence(fg, bg)
13
+ super(fg, bg, '0')
14
+ end
15
+
16
+ def build_fg_sequence
17
+ ['38', '5', foreground]
18
+ end
19
+
20
+ def build_bg_sequence
21
+ ['48', '5', background]
22
+ end
23
+
24
+ def find_from_fixnum(color_id)
25
+ pair = colors.find { |*term| term.first.flatten.include?(color_id) }
26
+ pair.first if pair
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ module PryTheme
2
+ class Color8 < Color
3
+
4
+ def initialize(options = {})
5
+ super(8, options)
6
+ end
7
+
8
+ private
9
+
10
+ def create_ansi_sequence(fg, bg)
11
+ super(fg, bg, '39;49')
12
+ end
13
+
14
+ def build_fg_sequence
15
+ [foreground]
16
+ end
17
+
18
+ def build_bg_sequence
19
+ [background]
20
+ end
21
+
22
+ def find_from_fixnum(color_id)
23
+ sorted_colors.each_with_index.to_a.rassoc(color_id).first.first
24
+ end
25
+
26
+ def build_effects_sequence
27
+ []
28
+ end
29
+
30
+ end
31
+ end