vedeu 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/all.rb +2 -13
  3. data/lib/vedeu/api.rb +9 -9
  4. data/lib/vedeu/application/application_view.rb +3 -5
  5. data/lib/vedeu/bindings/bindings.rb +5 -1
  6. data/lib/vedeu/bindings/focus.rb +0 -5
  7. data/lib/vedeu/bindings/refresh.rb +0 -5
  8. data/lib/vedeu/bindings/system.rb +1 -6
  9. data/lib/vedeu/colours/all.rb +17 -0
  10. data/lib/vedeu/colours/background.rb +32 -28
  11. data/lib/vedeu/colours/backgrounds.rb +13 -9
  12. data/lib/vedeu/colours/colour.rb +106 -102
  13. data/lib/vedeu/colours/foreground.rb +32 -28
  14. data/lib/vedeu/colours/foregrounds.rb +13 -9
  15. data/lib/vedeu/colours/repository.rb +70 -0
  16. data/lib/vedeu/colours/translator.rb +267 -0
  17. data/lib/vedeu/configuration/api.rb +10 -7
  18. data/lib/vedeu/configuration/configuration.rb +2 -1
  19. data/lib/vedeu/dsl/border.rb +15 -2
  20. data/lib/vedeu/dsl/composition.rb +6 -4
  21. data/lib/vedeu/dsl/geometry.rb +14 -7
  22. data/lib/vedeu/dsl/group.rb +2 -2
  23. data/lib/vedeu/dsl/interface.rb +5 -3
  24. data/lib/vedeu/dsl/keymap.rb +9 -7
  25. data/lib/vedeu/dsl/line.rb +7 -4
  26. data/lib/vedeu/dsl/menu.rb +3 -0
  27. data/lib/vedeu/dsl/presentation.rb +20 -10
  28. data/lib/vedeu/dsl/shared.rb +4 -4
  29. data/lib/vedeu/dsl/stream.rb +2 -2
  30. data/lib/vedeu/dsl/text.rb +11 -5
  31. data/lib/vedeu/dsl/use.rb +2 -2
  32. data/lib/vedeu/dsl/view.rb +8 -6
  33. data/lib/vedeu/events/aliases.rb +91 -0
  34. data/lib/vedeu/events/all.rb +15 -0
  35. data/lib/vedeu/events/collection.rb +13 -0
  36. data/lib/vedeu/events/event.rb +244 -239
  37. data/lib/vedeu/events/repository.rb +30 -0
  38. data/lib/vedeu/events/trigger.rb +68 -64
  39. data/lib/vedeu/exceptions.rb +65 -54
  40. data/lib/vedeu/geometry/coordinate.rb +3 -1
  41. data/lib/vedeu/geometry/grid.rb +2 -4
  42. data/lib/vedeu/input/editor/all.rb +2 -1
  43. data/lib/vedeu/input/editor/{virtual_cursor.rb → cursor.rb} +10 -10
  44. data/lib/vedeu/input/editor/document.rb +7 -7
  45. data/lib/vedeu/input/editor/insert.rb +70 -0
  46. data/lib/vedeu/input/editor/line.rb +4 -16
  47. data/lib/vedeu/input/editor/lines.rb +2 -16
  48. data/lib/vedeu/input/input_translator.rb +2 -2
  49. data/lib/vedeu/input/key.rb +2 -2
  50. data/lib/vedeu/internal_api.rb +6 -6
  51. data/lib/vedeu/log/lockless_log_device.rb +0 -74
  52. data/lib/vedeu/models/focus.rb +3 -3
  53. data/lib/vedeu/models/interface.rb +3 -3
  54. data/lib/vedeu/models/menu.rb +2 -2
  55. data/lib/vedeu/models/views/char.rb +1 -1
  56. data/lib/vedeu/models/views/composition.rb +1 -1
  57. data/lib/vedeu/models/views/line.rb +1 -1
  58. data/lib/vedeu/models/views/stream.rb +1 -1
  59. data/lib/vedeu/models/views/view.rb +6 -7
  60. data/lib/vedeu/output/presentation/colour.rb +23 -21
  61. data/lib/vedeu/output/renderers/renderer_options.rb +2 -4
  62. data/lib/vedeu/output/text.rb +1 -1
  63. data/lib/vedeu/output/wordwrap.rb +18 -7
  64. data/lib/vedeu/plugins/plugin.rb +2 -2
  65. data/lib/vedeu/refresh/refresh_buffer.rb +3 -3
  66. data/lib/vedeu/refresh/refresh_group.rb +3 -3
  67. data/lib/vedeu/repositories/repository.rb +7 -6
  68. data/lib/vedeu/runtime/application.rb +1 -1
  69. data/lib/vedeu/runtime/main_loop.rb +3 -3
  70. data/lib/vedeu/runtime/router.rb +14 -11
  71. data/lib/vedeu/templating/helpers.rb +5 -5
  72. data/lib/vedeu/templating/template.rb +4 -4
  73. data/lib/vedeu/templating/view_template.rb +1 -1
  74. data/lib/vedeu/terminal/terminal.rb +2 -2
  75. data/lib/vedeu/version.rb +1 -1
  76. data/test/lib/vedeu/application/application_view_test.rb +1 -1
  77. data/test/lib/vedeu/colours/background_test.rb +93 -89
  78. data/test/lib/vedeu/colours/backgrounds_test.rb +11 -7
  79. data/test/lib/vedeu/colours/colour_test.rb +155 -151
  80. data/test/lib/vedeu/colours/foreground_test.rb +93 -89
  81. data/test/lib/vedeu/colours/foregrounds_test.rb +11 -7
  82. data/test/lib/vedeu/colours/repository_test.rb +97 -0
  83. data/test/lib/vedeu/colours/translator_test.rb +173 -0
  84. data/test/lib/vedeu/configuration/api_test.rb +4 -4
  85. data/test/lib/vedeu/dsl/border_test.rb +12 -0
  86. data/test/lib/vedeu/dsl/composition_test.rb +3 -3
  87. data/test/lib/vedeu/dsl/geometry_test.rb +11 -0
  88. data/test/lib/vedeu/dsl/group_test.rb +2 -2
  89. data/test/lib/vedeu/dsl/interface_test.rb +4 -4
  90. data/test/lib/vedeu/dsl/keymap_test.rb +8 -4
  91. data/test/lib/vedeu/dsl/line_test.rb +6 -3
  92. data/test/lib/vedeu/dsl/menu_test.rb +6 -0
  93. data/test/lib/vedeu/dsl/presentation_test.rb +16 -3
  94. data/test/lib/vedeu/dsl/stream_test.rb +1 -1
  95. data/test/lib/vedeu/dsl/text_test.rb +7 -0
  96. data/test/lib/vedeu/dsl/view_test.rb +3 -3
  97. data/test/lib/vedeu/events/aliases_test.rb +144 -0
  98. data/test/lib/vedeu/events/collection_test.rb +22 -0
  99. data/test/lib/vedeu/events/event_test.rb +84 -80
  100. data/test/lib/vedeu/events/repository_test.rb +28 -0
  101. data/test/lib/vedeu/events/trigger_test.rb +41 -37
  102. data/test/lib/vedeu/geometry/grid_test.rb +4 -4
  103. data/test/lib/vedeu/input/editor/{virtual_cursor_test.rb → cursor_test.rb} +3 -3
  104. data/test/lib/vedeu/input/editor/insert_test.rb +36 -0
  105. data/test/lib/vedeu/input/key_test.rb +1 -1
  106. data/test/lib/vedeu/models/cell_test.rb +1 -1
  107. data/test/lib/vedeu/models/focus_test.rb +4 -2
  108. data/test/lib/vedeu/models/menu_test.rb +1 -1
  109. data/test/lib/vedeu/models/views/char_test.rb +8 -4
  110. data/test/lib/vedeu/models/views/line_test.rb +4 -4
  111. data/test/lib/vedeu/models/views/stream_test.rb +3 -3
  112. data/test/lib/vedeu/models/views/view_test.rb +1 -1
  113. data/test/lib/vedeu/output/html_char_test.rb +4 -2
  114. data/test/lib/vedeu/output/presentation/colour_test.rb +5 -5
  115. data/test/lib/vedeu/output/presentation_test.rb +4 -4
  116. data/test/lib/vedeu/output/renderers/json_test.rb +4 -2
  117. data/test/lib/vedeu/plugins/plugin_test.rb +1 -1
  118. data/test/lib/vedeu/refresh/refresh_buffer_test.rb +1 -1
  119. data/test/lib/vedeu/refresh/refresh_group_test.rb +1 -1
  120. data/test/lib/vedeu/repositories/repository_test.rb +2 -2
  121. data/test/lib/vedeu/runtime/router_test.rb +6 -6
  122. data/test/lib/vedeu/templating/decoder_test.rb +2 -3
  123. data/test/lib/vedeu/templating/encoder_test.rb +2 -3
  124. data/test/lib/vedeu/templating/helpers_test.rb +6 -6
  125. data/test/lib/vedeu/templating/template_test.rb +2 -2
  126. data/test/lib/vedeu/templating/view_template_test.rb +13 -7
  127. data/test/lib/vedeu/terminal/terminal_test.rb +3 -3
  128. metadata +24 -19
  129. data/lib/vedeu/colours/colour_translator.rb +0 -260
  130. data/lib/vedeu/colours/colours.rb +0 -66
  131. data/lib/vedeu/events/event_aliases.rb +0 -87
  132. data/lib/vedeu/events/event_collection.rb +0 -9
  133. data/lib/vedeu/events/events.rb +0 -26
  134. data/test/lib/vedeu/colours/colour_translator_test.rb +0 -169
  135. data/test/lib/vedeu/colours/colours_test.rb +0 -93
  136. data/test/lib/vedeu/events/event_aliases_test.rb +0 -140
  137. data/test/lib/vedeu/events/event_collection_test.rb +0 -18
  138. data/test/lib/vedeu/events/events_test.rb +0 -24
@@ -14,7 +14,9 @@ module Vedeu
14
14
 
15
15
  describe '.open' do
16
16
  context 'when a block was not given' do
17
- it { proc { Vedeu::Terminal.open }.must_raise(Vedeu::InvalidSyntax) }
17
+ it {
18
+ proc { Vedeu::Terminal.open }.must_raise(Vedeu::Error::InvalidSyntax)
19
+ }
18
20
  end
19
21
 
20
22
  it 'opens a new terminal console in raw mode' do
@@ -93,8 +95,6 @@ module Vedeu
93
95
  end
94
96
 
95
97
  describe '.resize' do
96
- before { Vedeu.interfaces.reset }
97
-
98
98
  subject { described.resize }
99
99
 
100
100
  it { subject.must_be_instance_of(TrueClass) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
@@ -283,13 +283,14 @@ files:
283
283
  - lib/vedeu/buffers/buffers.rb
284
284
  - lib/vedeu/buffers/virtual_buffer.rb
285
285
  - lib/vedeu/buffers/virtual_buffers.rb
286
+ - lib/vedeu/colours/all.rb
286
287
  - lib/vedeu/colours/background.rb
287
288
  - lib/vedeu/colours/backgrounds.rb
288
289
  - lib/vedeu/colours/colour.rb
289
- - lib/vedeu/colours/colour_translator.rb
290
- - lib/vedeu/colours/colours.rb
291
290
  - lib/vedeu/colours/foreground.rb
292
291
  - lib/vedeu/colours/foregrounds.rb
292
+ - lib/vedeu/colours/repository.rb
293
+ - lib/vedeu/colours/translator.rb
293
294
  - lib/vedeu/common.rb
294
295
  - lib/vedeu/configuration/api.rb
295
296
  - lib/vedeu/configuration/cli.rb
@@ -331,10 +332,11 @@ files:
331
332
  - lib/vedeu/esc/borders.rb
332
333
  - lib/vedeu/esc/colours.rb
333
334
  - lib/vedeu/esc/esc.rb
335
+ - lib/vedeu/events/aliases.rb
336
+ - lib/vedeu/events/all.rb
337
+ - lib/vedeu/events/collection.rb
334
338
  - lib/vedeu/events/event.rb
335
- - lib/vedeu/events/event_aliases.rb
336
- - lib/vedeu/events/event_collection.rb
337
- - lib/vedeu/events/events.rb
339
+ - lib/vedeu/events/repository.rb
338
340
  - lib/vedeu/events/trigger.rb
339
341
  - lib/vedeu/exceptions.rb
340
342
  - lib/vedeu/geometry/area.rb
@@ -347,12 +349,13 @@ files:
347
349
  - lib/vedeu/input/editor/all.rb
348
350
  - lib/vedeu/input/editor/capture.rb
349
351
  - lib/vedeu/input/editor/cropper.rb
352
+ - lib/vedeu/input/editor/cursor.rb
350
353
  - lib/vedeu/input/editor/document.rb
351
354
  - lib/vedeu/input/editor/documents.rb
352
355
  - lib/vedeu/input/editor/editor.rb
356
+ - lib/vedeu/input/editor/insert.rb
353
357
  - lib/vedeu/input/editor/line.rb
354
358
  - lib/vedeu/input/editor/lines.rb
355
- - lib/vedeu/input/editor/virtual_cursor.rb
356
359
  - lib/vedeu/input/input.rb
357
360
  - lib/vedeu/input/input_translator.rb
358
361
  - lib/vedeu/input/key.rb
@@ -473,10 +476,10 @@ files:
473
476
  - test/lib/vedeu/colours/background_test.rb
474
477
  - test/lib/vedeu/colours/backgrounds_test.rb
475
478
  - test/lib/vedeu/colours/colour_test.rb
476
- - test/lib/vedeu/colours/colour_translator_test.rb
477
- - test/lib/vedeu/colours/colours_test.rb
478
479
  - test/lib/vedeu/colours/foreground_test.rb
479
480
  - test/lib/vedeu/colours/foregrounds_test.rb
481
+ - test/lib/vedeu/colours/repository_test.rb
482
+ - test/lib/vedeu/colours/translator_test.rb
480
483
  - test/lib/vedeu/common_test.rb
481
484
  - test/lib/vedeu/configuration/api_test.rb
482
485
  - test/lib/vedeu/configuration/cli_test.rb
@@ -509,10 +512,10 @@ files:
509
512
  - test/lib/vedeu/esc/borders_test.rb
510
513
  - test/lib/vedeu/esc/colours_test.rb
511
514
  - test/lib/vedeu/esc/esc_test.rb
512
- - test/lib/vedeu/events/event_aliases_test.rb
513
- - test/lib/vedeu/events/event_collection_test.rb
515
+ - test/lib/vedeu/events/aliases_test.rb
516
+ - test/lib/vedeu/events/collection_test.rb
514
517
  - test/lib/vedeu/events/event_test.rb
515
- - test/lib/vedeu/events/events_test.rb
518
+ - test/lib/vedeu/events/repository_test.rb
516
519
  - test/lib/vedeu/events/trigger_test.rb
517
520
  - test/lib/vedeu/exceptions_test.rb
518
521
  - test/lib/vedeu/geometry/area_test.rb
@@ -524,12 +527,13 @@ files:
524
527
  - test/lib/vedeu/geometry/position_test.rb
525
528
  - test/lib/vedeu/input/editor/capture_test.rb
526
529
  - test/lib/vedeu/input/editor/cropper_test.rb
530
+ - test/lib/vedeu/input/editor/cursor_test.rb
527
531
  - test/lib/vedeu/input/editor/document_test.rb
528
532
  - test/lib/vedeu/input/editor/documents_test.rb
529
533
  - test/lib/vedeu/input/editor/editor_test.rb
534
+ - test/lib/vedeu/input/editor/insert_test.rb
530
535
  - test/lib/vedeu/input/editor/line_test.rb
531
536
  - test/lib/vedeu/input/editor/lines_test.rb
532
- - test/lib/vedeu/input/editor/virtual_cursor_test.rb
533
537
  - test/lib/vedeu/input/input_test.rb
534
538
  - test/lib/vedeu/input/input_translator_test.rb
535
539
  - test/lib/vedeu/input/key_test.rb
@@ -678,10 +682,10 @@ test_files:
678
682
  - test/lib/vedeu/colours/background_test.rb
679
683
  - test/lib/vedeu/colours/backgrounds_test.rb
680
684
  - test/lib/vedeu/colours/colour_test.rb
681
- - test/lib/vedeu/colours/colour_translator_test.rb
682
- - test/lib/vedeu/colours/colours_test.rb
683
685
  - test/lib/vedeu/colours/foreground_test.rb
684
686
  - test/lib/vedeu/colours/foregrounds_test.rb
687
+ - test/lib/vedeu/colours/repository_test.rb
688
+ - test/lib/vedeu/colours/translator_test.rb
685
689
  - test/lib/vedeu/common_test.rb
686
690
  - test/lib/vedeu/configuration/api_test.rb
687
691
  - test/lib/vedeu/configuration/cli_test.rb
@@ -714,10 +718,10 @@ test_files:
714
718
  - test/lib/vedeu/esc/borders_test.rb
715
719
  - test/lib/vedeu/esc/colours_test.rb
716
720
  - test/lib/vedeu/esc/esc_test.rb
717
- - test/lib/vedeu/events/event_aliases_test.rb
718
- - test/lib/vedeu/events/event_collection_test.rb
721
+ - test/lib/vedeu/events/aliases_test.rb
722
+ - test/lib/vedeu/events/collection_test.rb
719
723
  - test/lib/vedeu/events/event_test.rb
720
- - test/lib/vedeu/events/events_test.rb
724
+ - test/lib/vedeu/events/repository_test.rb
721
725
  - test/lib/vedeu/events/trigger_test.rb
722
726
  - test/lib/vedeu/exceptions_test.rb
723
727
  - test/lib/vedeu/geometry/area_test.rb
@@ -729,12 +733,13 @@ test_files:
729
733
  - test/lib/vedeu/geometry/position_test.rb
730
734
  - test/lib/vedeu/input/editor/capture_test.rb
731
735
  - test/lib/vedeu/input/editor/cropper_test.rb
736
+ - test/lib/vedeu/input/editor/cursor_test.rb
732
737
  - test/lib/vedeu/input/editor/document_test.rb
733
738
  - test/lib/vedeu/input/editor/documents_test.rb
734
739
  - test/lib/vedeu/input/editor/editor_test.rb
740
+ - test/lib/vedeu/input/editor/insert_test.rb
735
741
  - test/lib/vedeu/input/editor/line_test.rb
736
742
  - test/lib/vedeu/input/editor/lines_test.rb
737
- - test/lib/vedeu/input/editor/virtual_cursor_test.rb
738
743
  - test/lib/vedeu/input/input_test.rb
739
744
  - test/lib/vedeu/input/input_translator_test.rb
740
745
  - test/lib/vedeu/input/key_test.rb
@@ -1,260 +0,0 @@
1
- module Vedeu
2
-
3
- # Convert a CSS/HTML colour string into a terminal escape sequence.
4
- #
5
- # If provided with an empty value or a string it cannot convert, it will
6
- # return an empty string.
7
- #
8
- # When provided with a named colour, uses the terminal's value for that
9
- # colour. If a theme is being used with the terminal, which overrides the
10
- # defaults, then the theme's colour will be used. The recognised names are:
11
- # :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, :default.
12
- #
13
- # When a number between 0 and 255 is provided, Vedeu will use the terminal
14
- # colour corresponding with that colour.
15
- #
16
- # Finally, when provided a CSS/HTML colour string e.g. '#ff0000', Vedeu will
17
- # translate that to the 8-bit escape sequence or when you have a capable
18
- # terminal and the `TERM=xterm-truecolor` environment variable set,
19
- # a 24-bit representation.
20
- #
21
- # @todo More documentation required (create a fancy chart!)
22
- #
23
- class ColourTranslator
24
-
25
- # @!attribute [r] colour
26
- # @return [String]
27
- attr_reader :colour
28
- alias_method :value, :colour
29
-
30
- # Produces new objects of the correct class from the value, ignores objects
31
- # that have already been coerced.
32
- #
33
- # @param value [Object|NilClass]
34
- # @return [Object]
35
- def self.coerce(value)
36
- if value.is_a?(self)
37
- value
38
-
39
- else
40
- new(value)
41
-
42
- end
43
- end
44
-
45
- # Return a new instance of Vedeu::ColourTranslator.
46
- #
47
- # @param colour [Fixnum|String|Symbol]
48
- # @return [Vedeu::ColourTranslator]
49
- def initialize(colour = '')
50
- @colour = colour || ''
51
- end
52
-
53
- # @return [Boolean]
54
- def empty?
55
- colour.nil? || colour.to_s.empty?
56
- end
57
-
58
- # An object is equal when its values are the same.
59
- #
60
- # @param other [Vedeu::Views::Char]
61
- # @return [Boolean]
62
- def eql?(other)
63
- self.class == other.class && colour == other.colour
64
- end
65
- alias_method :==, :eql?
66
-
67
- # @return [String]
68
- # @see Vedeu::ColourTranslator
69
- def escape_sequence
70
- if empty?
71
- ''
72
-
73
- elsif registered?(colour)
74
- retrieve(colour)
75
-
76
- elsif rgb?
77
- rgb
78
-
79
- elsif numbered?
80
- numbered
81
-
82
- elsif named?
83
- named
84
-
85
- else
86
- ''
87
-
88
- end
89
- end
90
- alias_method :to_s, :escape_sequence
91
- alias_method :to_str, :escape_sequence
92
-
93
- # @return [String]
94
- def to_html
95
- return colour if rgb?
96
-
97
- ''
98
- end
99
-
100
- private
101
-
102
- # Retrieves the escape sequence for the HTML/CSS colour code.
103
- #
104
- # @param colour [String]
105
- # @return [String]
106
- def retrieve(colour)
107
- repository.retrieve(colour)
108
- end
109
-
110
- # Registers a HTML/CSS colour code and escape sequence to reduce processing.
111
- #
112
- # @param colour [String] A HTML/CSS colour code.
113
- # @param escape_sequence [String] The HTML/CSS colour code as an escape
114
- # sequence.
115
- # @return [String]
116
- def register(colour, escape_sequence)
117
- repository.register(colour, escape_sequence)
118
- end
119
-
120
- # Returns a boolean indicating the HTML/CSS colour code has been registered.
121
- #
122
- # @param colour [String]
123
- # @return [Boolean]
124
- def registered?(colour)
125
- repository.registered?(colour)
126
- end
127
-
128
- # @return [Boolean]
129
- def named?
130
- colour.is_a?(Symbol) && valid_name?
131
- end
132
-
133
- # Returns an escape sequence for a named background colour.
134
- #
135
- # @note
136
- # Valid names can be found at {Vedeu::Esc#codes}
137
- #
138
- # @return [String]
139
- def named
140
- "\e[#{named_codes}m"
141
- end
142
-
143
- # Returns a boolean indicating whether the colour provided is a valid named
144
- # colour.
145
- #
146
- # @return [Boolean]
147
- def valid_name?
148
- Vedeu::Esc.codes.keys.include?(colour)
149
- end
150
-
151
- # Returns a boolean indicating whether the colour provided is a terminal
152
- # numbered colour.
153
- #
154
- # @return [Boolean]
155
- def numbered?
156
- colour.is_a?(Fixnum) && valid_range?
157
- end
158
-
159
- # Returns an escape sequence.
160
- #
161
- # @return [String]
162
- def numbered
163
- "#{numbered_prefix}#{css_to_numbered}m"
164
- end
165
-
166
- # Returns a boolean indicated whether the colour is a valid HTML/CSS colour.
167
- #
168
- # @return [Boolean]
169
- def rgb?
170
- return true if colour =~ /^#([A-Fa-f0-9]{6})$/
171
-
172
- false
173
- end
174
-
175
- # Returns an escape sequence.
176
- #
177
- # @return [String]
178
- def rgb
179
- if Vedeu::Configuration.colour_mode == 16_777_216
180
- register(colour, format(rgb_prefix, *css_to_rgb))
181
-
182
- else
183
- numbered
184
-
185
- end
186
- end
187
-
188
- # Returns a boolean indicating whether the numbered colour is within the
189
- # range of valid terminal numbered colours.
190
- #
191
- # @return [Boolean]
192
- def valid_range?
193
- colour >= 0 && colour <= 255
194
- end
195
-
196
- # Returns a collection of converted HTML/CSS octets as their decimal
197
- # equivalents.
198
- #
199
- # @example
200
- # colour = '#aadd55'
201
- # css_to_rgb # => [170, 221, 85]
202
- #
203
- # @return [Array]
204
- def css_to_rgb
205
- [
206
- colour[1..2].to_i(16),
207
- colour[3..4].to_i(16),
208
- colour[5..6].to_i(16),
209
- ]
210
- end
211
-
212
- # @return [Fixnum]
213
- def css_to_numbered
214
- if rgb?
215
- [16, red, green, blue].inject(:+)
216
-
217
- elsif numbered?
218
- colour
219
-
220
- end
221
- end
222
-
223
- # Takes the red component of {#css_to_rgb} and converts to the correct value
224
- # for setting the terminal red value.
225
- #
226
- # @return [Fixnum]
227
- def red
228
- (css_to_rgb[0] / 51) * 36
229
- end
230
-
231
- # Takes the green component of {#css_to_rgb} and converts to the correct
232
- # value for setting the terminal green value.
233
- #
234
- # @return [Fixnum]
235
- def green
236
- (css_to_rgb[1] / 51) * 6
237
- end
238
-
239
- # Takes the blue component of {#css_to_rgb} and converts to the correct
240
- # value for setting the terminal blue value.
241
- #
242
- # @return [Fixnum]
243
- def blue
244
- (css_to_rgb[2] / 51) * 1
245
- end
246
-
247
- # @raise [Vedeu::NotImplemented] Subclasses of this class must implement
248
- # this method.
249
- # @return [Vedeu::NotImplemented]
250
- def not_implemented
251
- fail Vedeu::NotImplemented, 'Subclasses implement this.'
252
- end
253
- alias_method :named_codes, :not_implemented
254
- alias_method :numbered_prefix, :not_implemented
255
- alias_method :repository, :not_implemented
256
- alias_method :rgb_prefix, :not_implemented
257
-
258
- end # ColourTranslator
259
-
260
- end # Vedeu
@@ -1,66 +0,0 @@
1
- module Vedeu
2
-
3
- # Allows the storing of HTML/CSS colours and their respective escape
4
- # sequences.
5
- #
6
- class Colours
7
-
8
- # @!attribute [r] storage
9
- # @return [Hash<String => String>]
10
- attr_reader :storage
11
-
12
- # Returns a new instance of Vedeu::Colours.
13
- #
14
- # @return [Vedeu::Colours]
15
- def initialize
16
- @storage = {}
17
- end
18
-
19
- # Registers a colour with respective escape sequence.
20
- #
21
- # @return [String]
22
- def register(colour, escape_sequence)
23
- storage.store(colour, escape_sequence)
24
- end
25
-
26
- # Returns a boolean indicating whether the colour has been registered.
27
- #
28
- # @param colour [String]
29
- # @return [Boolean]
30
- def registered?(colour)
31
- return false unless colour
32
-
33
- storage.key?(colour)
34
- end
35
-
36
- # Removes all stored colours.
37
- #
38
- # @return [Hash]
39
- def reset!
40
- storage.clear
41
- end
42
-
43
- # Retrieves the escape sequence of a registered colour.
44
- #
45
- # @return [String]
46
- def retrieve(colour)
47
- storage.fetch(colour, '')
48
- end
49
-
50
- # Retrieves the escape sequence of a registered colour, or registers the
51
- # colour with its respective escape sequence.
52
- #
53
- # @return [String]
54
- def retrieve_or_register(colour, escape_sequence)
55
- if registered?(colour)
56
- retrieve(colour)
57
-
58
- else
59
- register(colour, escape_sequence)
60
-
61
- end
62
- end
63
-
64
- end # Colours
65
-
66
- end # Vedeu