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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2572d8a6656ea1dabfd4fc7ffb4fe69b661d7f1
4
- data.tar.gz: 5f682d6d0b7948c52014ce4ab11e390dff755c6c
3
+ metadata.gz: 95b04552ad105549ad207ff5111b8a524a3295e2
4
+ data.tar.gz: 501502ff4b2358f6bca2740343581d399512fdc3
5
5
  SHA512:
6
- metadata.gz: 75e150c79ba83513d5e55310479b76c5c2f4710786d274fd43959814a0659cdeee9385b0d74e86f2444c27a06a083d2e259c7f39ae567eb96d24e1be22c46b3a
7
- data.tar.gz: b19de309102aecf1b8ccb88a093b575ae201565de462a57119234c15e7d183581f9841d7e89634ae6d9f91f2a5c533b328c80f0e3096585a9ca52bb664486c44
6
+ metadata.gz: 53154cedb87837dce360e41dbfd01fc0a7081acb70294dd9ef09bc74618e76cc4937edc66f23607e467987346cc8f00933b1cf4252988b1f96ca747537dc8583
7
+ data.tar.gz: 9eaaceffc2eae74600586814a726ad512ed0d8f2381380978439cde334ceb393a86803a0810cb5faea4fab2f2742f8eff4ef222cf0cc500a694e74d54a339185
data/lib/vedeu/all.rb CHANGED
@@ -27,7 +27,6 @@ require 'vedeu/models/toggleable'
27
27
 
28
28
  require 'vedeu/repositories/collection'
29
29
  require 'vedeu/input/keys'
30
- require 'vedeu/events/event_collection'
31
30
  require 'vedeu/repositories/repositories'
32
31
 
33
32
  require 'vedeu/repositories/model'
@@ -52,13 +51,7 @@ require 'vedeu/geometry/geometries'
52
51
  require 'vedeu/geometry/grid'
53
52
  require 'vedeu/geometry/position'
54
53
 
55
- require 'vedeu/colours/colours'
56
- require 'vedeu/colours/backgrounds'
57
- require 'vedeu/colours/foregrounds'
58
- require 'vedeu/colours/colour_translator'
59
- require 'vedeu/colours/background'
60
- require 'vedeu/colours/foreground'
61
- require 'vedeu/colours/colour'
54
+ require 'vedeu/colours/all'
62
55
 
63
56
  require 'vedeu/buffers/buffer'
64
57
  require 'vedeu/buffers/buffers'
@@ -90,11 +83,7 @@ require 'vedeu/output/renderers/terminal'
90
83
  require 'vedeu/output/renderers/text'
91
84
  require 'vedeu/output/renderers'
92
85
 
93
- require 'vedeu/events/event_aliases'
94
- require 'vedeu/events/trigger'
95
- require 'vedeu/events/events'
96
- require 'vedeu/events/event'
97
-
86
+ require 'vedeu/events/all'
98
87
  require 'vedeu/models/views/all'
99
88
 
100
89
  require 'vedeu/models/cell'
data/lib/vedeu/api.rb CHANGED
@@ -110,22 +110,22 @@ module Vedeu
110
110
  # Vedeu.unbind(name)
111
111
  #
112
112
  # @!method bind
113
- # @see Vedeu::Event.bind
113
+ # @see Vedeu::Events::Event.bind
114
114
  # @!method bound?
115
- # @see Vedeu::Event.bound?
115
+ # @see Vedeu::Events::Event.bound?
116
116
  # @!method unbind
117
- # @see Vedeu::Event.unbind
118
- def_delegators Vedeu::Event, :bind, :bound?, :unbind
117
+ # @see Vedeu::Events::Event.unbind
118
+ def_delegators Vedeu::Events::Event, :bind, :bound?, :unbind
119
119
 
120
120
  # @example
121
121
  # Vedeu.bind_alias(alias_name, event_name)
122
122
  # Vedeu.unbind_alias(alias_name)
123
123
  #
124
124
  # @!method bind_alias
125
- # @see Vedeu::EventAliases.bind_alias
125
+ # @see Vedeu::Events::Aliases.bind_alias
126
126
  # @!method unbind_alias
127
- # @see Vedeu::EventAliases.unbind_alias
128
- def_delegators Vedeu::EventAliases, :bind_alias, :unbind_alias
127
+ # @see Vedeu::Events::Aliases.unbind_alias
128
+ def_delegators Vedeu::Events::Aliases, :bind_alias, :unbind_alias
129
129
 
130
130
  # @example
131
131
  # Vedeu.focus
@@ -205,8 +205,8 @@ module Vedeu
205
205
  # Vedeu.trigger(:name)
206
206
  #
207
207
  # @!method trigger
208
- # @see Vedeu::Trigger.trigger
209
- def_delegators Vedeu::Trigger, :trigger
208
+ # @see Vedeu::Events::Trigger.trigger
209
+ def_delegators Vedeu::Events::Trigger, :trigger
210
210
 
211
211
  # Exit the client application using Vedeu.
212
212
  #
@@ -27,10 +27,10 @@ module Vedeu
27
27
  end
28
28
  end
29
29
 
30
- # @raise [Vedeu::NotImplemented] Subclasses of this class must implement
31
- # this method.
30
+ # @raise [Vedeu::Error::NotImplemented] Subclasses of this class must
31
+ # implement this method.
32
32
  def render
33
- fail Vedeu::NotImplemented,
33
+ fail Vedeu::Error::NotImplemented,
34
34
  'The subclass of Vedeu::ApplicationView must implement the #render' \
35
35
  'method.'
36
36
  end
@@ -48,12 +48,10 @@ module Vedeu
48
48
  #
49
49
  # @param value [String]
50
50
  # @return [String]
51
- # :nocov:
52
51
  def template(value)
53
52
  @template = Vedeu::Configuration.base_path +
54
53
  "/app/views/templates/#{value}.erb"
55
54
  end
56
- # :nocov:
57
55
 
58
56
  end # ApplicationView
59
57
 
@@ -7,6 +7,10 @@ module Vedeu
7
7
  # directly, however the produced events are all public and are highly
8
8
  # recommended to be used.
9
9
  #
10
+ # Unbinding any of these events is likely to cause problems, so I would
11
+ # advise leaving them alone. A safe rule: when the name starts and ends with
12
+ # an underscore, it's probably used by Vedeu internally.
13
+ #
10
14
  module Bindings
11
15
 
12
16
  extend self
@@ -15,7 +19,7 @@ module Vedeu
15
19
  #
16
20
  # @return [TrueClass]
17
21
  def setup!
18
- Vedeu::Events.reset!
22
+ Vedeu::Events::Repository.reset!
19
23
 
20
24
  Vedeu::Bindings::Application.setup!
21
25
  Vedeu::Bindings::Document.setup!
@@ -5,11 +5,6 @@ module Vedeu
5
5
  # Creates system events which when called provide a variety of core
6
6
  # functions and behaviours. They are soft-namespaced using underscores.
7
7
  #
8
- # @note
9
- # Unbinding any of these events is likely to cause problems, so I would
10
- # advise leaving them alone. A safe rule: when the name starts with an
11
- # underscore, it's probably used by Vedeu internally.
12
- #
13
8
  # :nocov:
14
9
  module Focus
15
10
 
@@ -5,11 +5,6 @@ module Vedeu
5
5
  # Creates system events which when called provide a variety of core
6
6
  # functions and behaviours. They are soft-namespaced using underscores.
7
7
  #
8
- # @note
9
- # Unbinding any of these events is likely to cause problems, so I would
10
- # advise leaving them alone. A safe rule: when the name starts with an
11
- # underscore, it's probably used by Vedeu internally.
12
- #
13
8
  # :nocov:
14
9
  module Refresh
15
10
 
@@ -5,11 +5,6 @@ module Vedeu
5
5
  # Creates system events which when called provide a variety of core
6
6
  # functions and behaviours. They are soft-namespaced using underscores.
7
7
  #
8
- # @note
9
- # Unbinding any of these events is likely to cause problems, so I would
10
- # advise leaving them alone. A safe rule: when the name starts with an
11
- # underscore, it's probably used by Vedeu internally.
12
- #
13
8
  # :nocov:
14
9
  module System
15
10
 
@@ -169,7 +164,7 @@ module Vedeu
169
164
  #
170
165
  # @return [TrueClass]
171
166
  def mode_switch!
172
- Vedeu.bind(:_mode_switch_) { fail Vedeu::ModeSwitch }
167
+ Vedeu.bind(:_mode_switch_) { fail Vedeu::Error::ModeSwitch }
173
168
  end
174
169
 
175
170
  # When triggered will cause Vedeu to trigger the `:_clear_` and
@@ -0,0 +1,17 @@
1
+ module Vedeu
2
+
3
+ # Provides colour support to Vedeu.
4
+ #
5
+ module Colours
6
+
7
+ end # Colours
8
+
9
+ end # Vedeu
10
+
11
+ require 'vedeu/colours/repository'
12
+ require 'vedeu/colours/backgrounds'
13
+ require 'vedeu/colours/foregrounds'
14
+ require 'vedeu/colours/translator'
15
+ require 'vedeu/colours/background'
16
+ require 'vedeu/colours/foreground'
17
+ require 'vedeu/colours/colour'
@@ -1,32 +1,36 @@
1
1
  module Vedeu
2
2
 
3
- # The class represents one half (the other, can be found at
4
- # {Vedeu::Foreground}) of a terminal colour escape sequence.
5
- #
6
- class Background < Vedeu::ColourTranslator
7
-
8
- private
9
-
10
- # @return [String]
11
- def named_codes
12
- Vedeu::Esc.background_codes[colour]
13
- end
14
-
15
- # @return [String]
16
- def numbered_prefix
17
- "\e[48;5;"
18
- end
19
-
20
- # @return [Vedeu::Backgrounds]
21
- def repository
22
- Vedeu.background_colours
23
- end
24
-
25
- # @return [String]
26
- def rgb_prefix
27
- "\e[48;2;%s;%s;%sm"
28
- end
29
-
30
- end # Background
3
+ module Colours
4
+
5
+ # The class represents one half (the other, can be found at
6
+ # {Vedeu::Colours::Foreground}) of a terminal colour escape sequence.
7
+ #
8
+ class Background < Vedeu::Colours::Translator
9
+
10
+ private
11
+
12
+ # @return [String]
13
+ def named_codes
14
+ Vedeu::Esc.background_codes[colour]
15
+ end
16
+
17
+ # @return [String]
18
+ def numbered_prefix
19
+ "\e[48;5;"
20
+ end
21
+
22
+ # @return [Vedeu::Colours::Backgrounds]
23
+ def repository
24
+ Vedeu.background_colours
25
+ end
26
+
27
+ # @return [String]
28
+ def rgb_prefix
29
+ "\e[48;2;%s;%s;%sm"
30
+ end
31
+
32
+ end # Background
33
+
34
+ end # Colours
31
35
 
32
36
  end # Vedeu
@@ -1,15 +1,19 @@
1
1
  module Vedeu
2
2
 
3
- # Store background colour escape sequences by HTML/CSS code.
4
- #
5
- class Backgrounds < Colours
3
+ module Colours
6
4
 
7
- # @return [Vedeu::Backgrounds]
8
- # @see Vedeu::Repository
9
- def self.background_colours
10
- @background_colours ||= new
11
- end
5
+ # Store background colour escape sequences by HTML/CSS code.
6
+ #
7
+ class Backgrounds < Vedeu::Colours::Repository
12
8
 
13
- end # Backgrounds
9
+ # @return [Vedeu::Colours::Backgrounds]
10
+ # @see Vedeu::Repository
11
+ def self.background_colours
12
+ @background_colours ||= new
13
+ end
14
+
15
+ end # Backgrounds
16
+
17
+ end # Colours
14
18
 
15
19
  end # Vedeu
@@ -1,113 +1,117 @@
1
1
  module Vedeu
2
2
 
3
- # Provides a container for terminal escape sequences controlling the
4
- # foreground and background colours of a character or collection of
5
- # characters.
6
- #
7
- # Vedeu uses HTML/CSS style notation (i.e. '#aadd00'), they can be used at the
8
- # stream level, the line level or for the whole interface. Terminals generally
9
- # support either 8, 16 or 256 colours, with few supporting full 24-bit colour
10
- # (see notes below).
11
- #
12
- # Vedeu attempts to detect the colour depth using the `$TERM` environment
13
- # variable.
14
- #
15
- # To set your `$TERM` variable to allow 256 colour support:
16
- #
17
- # ```bash
18
- # echo "export TERM=xterm-256color" >> ~/.bashrc
19
- # ```
20
- #
21
- # Notes:
22
- # Terminals which support the 24-bit colour mode include (but are not limited
23
- # to): iTerm2 (OSX), Gnome Terminal (Linux).
24
- #
25
- # Setting your `$TERM` environment variable as above gets you up to 256
26
- # colours, but when you then add the `colour_mode 16_777_216` configuration to
27
- # your client application, it's really a hit and miss affair. iTerm2 renders
28
- # all the colours correctly as does Gnome Terminal. Terminator (Linux) goes
29
- # crazy though and defaults to 16 colours despite the `$TERM` setting. This
30
- # area needs more work in Vedeu.
31
- #
32
- # @todo Fix colours in all terminals. (GL: 2015-04-13)
33
- #
34
- class Colour
35
-
36
- # @!attribute [r] background
37
- # @return [Vedeu::Background]
38
- attr_reader :background
39
-
40
- # @!attribute [r] foreground
41
- # @return [Vedeu::Foreground]
42
- attr_reader :foreground
43
-
44
- # @param value [Vedeu::Colour|Hash<Symbol => void>]
45
- # @return [Object]
46
- def self.coerce(value)
47
- return value if value.is_a?(self)
48
- return new unless value.is_a?(Hash)
49
-
50
- if value[:colour] && value[:colour].is_a?(self)
51
- value[:colour]
52
-
53
- elsif value[:colour] && value[:colour].is_a?(Hash)
54
- new(value[:colour])
55
-
56
- elsif value[:background] || value[:foreground]
57
- new(value)
58
-
59
- else
60
- new
3
+ module Colours
61
4
 
62
- end
63
- end
64
-
65
- # Returns a new instance of Vedeu::Colour.
5
+ # Provides a container for terminal escape sequences controlling the
6
+ # foreground and background colours of a character or collection of
7
+ # characters.
66
8
  #
67
- # @param attributes [Hash]
68
- # @option attributes background [String]
69
- # @option attributes foreground [String]
70
- # @return [Vedeu::Colour]
71
- def initialize(attributes = {})
72
- @background = Vedeu::Background.coerce(attributes[:background])
73
- @foreground = Vedeu::Foreground.coerce(attributes[:foreground])
74
- end
75
-
76
- # Converts the value into a Vedeu::Background.
9
+ # Vedeu uses HTML/CSS style notation (i.e. '#aadd00'), they can be used at
10
+ # the stream level, the line level or for the whole interface. Terminals
11
+ # generally support either 8, 16 or 256 colours, with few supporting full
12
+ # 24-bit colour (see notes below).
77
13
  #
78
- # @param value [String]
79
- # @return [String]
80
- def background=(value)
81
- @background = Vedeu::Background.coerce(value)
82
- end
83
-
84
- # An object is equal when its values are the same.
14
+ # Vedeu attempts to detect the colour depth using the `$TERM` environment
15
+ # variable.
16
+ #
17
+ # To set your `$TERM` variable to allow 256 colour support:
85
18
  #
86
- # @param other [Vedeu::Views::Char]
87
- # @return [Boolean]
88
- def eql?(other)
89
- self.class == other.class && background == other.background &&
90
- foreground == other.foreground
91
- end
92
- alias_method :==, :eql?
93
-
94
- # Converts the value into a Vedeu::Foreground.
19
+ # ```bash
20
+ # echo "export TERM=xterm-256color" >> ~/.bashrc
21
+ # ```
95
22
  #
96
- # @param value [String]
97
- # @return [String]
98
- def foreground=(value)
99
- @foreground = Vedeu::Foreground.coerce(value)
100
- end
101
-
102
- # Returns both or either of the converted attributes into a single escape
103
- # sequence.
23
+ # Notes:
24
+ # Terminals which support the 24-bit colour mode include (but are not
25
+ # limited to): iTerm2 (OSX), Gnome Terminal (Linux).
104
26
  #
105
- # @return [String]
106
- def to_s
107
- foreground.to_s + background.to_s
108
- end
109
- alias_method :to_str, :to_s
27
+ # Setting your `$TERM` environment variable as above gets you up to 256
28
+ # colours, but when you then add the `colour_mode 16_777_216` configuration
29
+ # to your client application, it's really a hit and miss affair. iTerm2
30
+ # renders all the colours correctly as does Gnome Terminal. Terminator
31
+ # (Linux) goes crazy though and defaults to 16 colours despite the `$TERM`
32
+ # setting. This area needs more work in Vedeu.
33
+ #
34
+ # @todo Fix colours in all terminals. (GL: 2015-04-13)
35
+ #
36
+ class Colour
37
+
38
+ # @!attribute [r] background
39
+ # @return [Vedeu::Colours::Background]
40
+ attr_reader :background
41
+
42
+ # @!attribute [r] foreground
43
+ # @return [Vedeu::Colours::Foreground]
44
+ attr_reader :foreground
45
+
46
+ # @param value [Vedeu::Colours::Colour|Hash<Symbol => void>]
47
+ # @return [Object]
48
+ def self.coerce(value)
49
+ return value if value.is_a?(self)
50
+ return new unless value.is_a?(Hash)
51
+
52
+ if value[:colour] && value[:colour].is_a?(self)
53
+ value[:colour]
54
+
55
+ elsif value[:colour] && value[:colour].is_a?(Hash)
56
+ new(value[:colour])
57
+
58
+ elsif value[:background] || value[:foreground]
59
+ new(value)
60
+
61
+ else
62
+ new
63
+
64
+ end
65
+ end
66
+
67
+ # Returns a new instance of Vedeu::Colours::Colour.
68
+ #
69
+ # @param attributes [Hash]
70
+ # @option attributes background [String]
71
+ # @option attributes foreground [String]
72
+ # @return [Vedeu::Colours::Colour]
73
+ def initialize(attributes = {})
74
+ @background = Vedeu::Colours::Background.coerce(attributes[:background])
75
+ @foreground = Vedeu::Colours::Foreground.coerce(attributes[:foreground])
76
+ end
77
+
78
+ # Converts the value into a Vedeu::Colours::Background.
79
+ #
80
+ # @param value [String]
81
+ # @return [String]
82
+ def background=(value)
83
+ @background = Vedeu::Colours::Background.coerce(value)
84
+ end
85
+
86
+ # An object is equal when its values are the same.
87
+ #
88
+ # @param other [Vedeu::Views::Char]
89
+ # @return [Boolean]
90
+ def eql?(other)
91
+ self.class == other.class && background == other.background &&
92
+ foreground == other.foreground
93
+ end
94
+ alias_method :==, :eql?
95
+
96
+ # Converts the value into a Vedeu::Colours::Foreground.
97
+ #
98
+ # @param value [String]
99
+ # @return [String]
100
+ def foreground=(value)
101
+ @foreground = Vedeu::Colours::Foreground.coerce(value)
102
+ end
103
+
104
+ # Returns both or either of the converted attributes into a single escape
105
+ # sequence.
106
+ #
107
+ # @return [String]
108
+ def to_s
109
+ foreground.to_s + background.to_s
110
+ end
111
+ alias_method :to_str, :to_s
112
+
113
+ end # Colour
110
114
 
111
- end # Colour
115
+ end # Colours
112
116
 
113
117
  end # Vedeu