vedeu 0.4.17 → 0.4.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/docs/dsl.md +54 -0
  3. data/docs/views.md +25 -25
  4. data/examples/cursor_app.rb +1 -1
  5. data/examples/material_colours_app.rb +1 -1
  6. data/lib/vedeu/all.rb +1 -0
  7. data/lib/vedeu/bindings.rb +2 -15
  8. data/lib/vedeu/buffers/buffer.rb +30 -7
  9. data/lib/vedeu/buffers/display_buffer.rb +1 -1
  10. data/lib/vedeu/configuration/configuration.rb +1 -1
  11. data/lib/vedeu/cursor/refresh_cursor.rb +4 -0
  12. data/lib/vedeu/dsl/components/border.rb +6 -1
  13. data/lib/vedeu/geometry/all.rb +0 -1
  14. data/lib/vedeu/geometry/area.rb +0 -20
  15. data/lib/vedeu/geometry/coordinate.rb +0 -50
  16. data/lib/vedeu/geometry/geometry.rb +1 -5
  17. data/lib/vedeu/geometry/position.rb +9 -0
  18. data/lib/vedeu/geometry/position_index.rb +19 -14
  19. data/lib/vedeu/geometry/position_validator.rb +3 -0
  20. data/lib/vedeu/models/all.rb +0 -3
  21. data/lib/vedeu/models/interface.rb +2 -4
  22. data/lib/vedeu/null/all.rb +5 -0
  23. data/lib/vedeu/null/border.rb +79 -0
  24. data/lib/vedeu/null/buffer.rb +44 -0
  25. data/lib/vedeu/null/generic.rb +52 -0
  26. data/lib/vedeu/null/geometry.rb +70 -0
  27. data/lib/vedeu/null/interface.rb +23 -0
  28. data/lib/vedeu/output/all.rb +0 -1
  29. data/lib/vedeu/output/border.rb +9 -9
  30. data/lib/vedeu/output/clear.rb +2 -1
  31. data/lib/vedeu/output/output.rb +1 -1
  32. data/lib/vedeu/output/refresh.rb +1 -1
  33. data/lib/vedeu/output/renderers/all.rb +7 -7
  34. data/lib/vedeu/output/renderers/escape_sequence.rb +47 -0
  35. data/lib/vedeu/output/renderers/{file_renderer.rb → file.rb} +11 -6
  36. data/lib/vedeu/output/renderers/{html_renderer.rb → html.rb} +4 -4
  37. data/lib/vedeu/output/renderers/{json_renderer.rb → json.rb} +4 -4
  38. data/lib/vedeu/output/renderers/{null_renderer.rb → null.rb} +2 -2
  39. data/lib/vedeu/output/renderers/{terminal_renderer.rb → terminal.rb} +4 -4
  40. data/lib/vedeu/output/renderers/{text_renderer.rb → text.rb} +4 -4
  41. data/lib/vedeu/output/text.rb +2 -2
  42. data/lib/vedeu/output/virtual_terminal.rb +2 -2
  43. data/lib/vedeu/repositories/all.rb +2 -0
  44. data/lib/vedeu/repositories/repositories/borders.rb +4 -2
  45. data/lib/vedeu/repositories/repositories/buffers.rb +11 -9
  46. data/lib/vedeu/repositories/repositories/cursors.rb +2 -0
  47. data/lib/vedeu/repositories/repositories/events_repository.rb +2 -0
  48. data/lib/vedeu/repositories/repositories/geometries.rb +4 -2
  49. data/lib/vedeu/repositories/repositories/groups.rb +2 -0
  50. data/lib/vedeu/repositories/repositories/interfaces_repository.rb +4 -2
  51. data/lib/vedeu/repositories/repositories/keymaps.rb +2 -0
  52. data/lib/vedeu/repositories/repositories/menus.rb +2 -0
  53. data/test/lib/vedeu/cursor/cursor_test.rb +1 -1
  54. data/test/lib/vedeu/cursor/move_test.rb +21 -33
  55. data/test/lib/vedeu/cursor/refresh_cursor_test.rb +16 -1
  56. data/test/lib/vedeu/distributed/test_application_test.rb +1 -1
  57. data/test/lib/vedeu/dsl/components/border_test.rb +1 -1
  58. data/test/lib/vedeu/dsl/components/geometry_test.rb +5 -5
  59. data/test/lib/vedeu/dsl/components/menu_test.rb +1 -1
  60. data/test/lib/vedeu/dsl/composition_test.rb +1 -1
  61. data/test/lib/vedeu/dsl/group_test.rb +1 -1
  62. data/test/lib/vedeu/dsl/interface_test.rb +1 -1
  63. data/test/lib/vedeu/dsl/stream_test.rb +1 -1
  64. data/test/lib/vedeu/events/event_test.rb +8 -8
  65. data/test/lib/vedeu/events/trigger_test.rb +1 -1
  66. data/test/lib/vedeu/geometry/area_test.rb +4 -36
  67. data/test/lib/vedeu/geometry/canvas_test.rb +2 -2
  68. data/test/lib/vedeu/geometry/coordinate_test.rb +0 -56
  69. data/test/lib/vedeu/geometry/dimension_test.rb +1 -1
  70. data/test/lib/vedeu/geometry/geometry_test.rb +1 -1
  71. data/test/lib/vedeu/geometry/grid_test.rb +1 -1
  72. data/test/lib/vedeu/geometry/position_index_test.rb +21 -23
  73. data/test/lib/vedeu/geometry/position_validator_test.rb +121 -3
  74. data/test/lib/vedeu/input/input_test.rb +1 -1
  75. data/test/lib/vedeu/input/key_test.rb +1 -1
  76. data/test/lib/vedeu/input/keymap_test.rb +1 -1
  77. data/test/lib/vedeu/models/interface_test.rb +14 -0
  78. data/test/lib/vedeu/null/border_test.rb +76 -0
  79. data/test/lib/vedeu/null/generic_test.rb +69 -0
  80. data/test/lib/vedeu/null/geometry_test.rb +63 -0
  81. data/test/lib/vedeu/null/interface_test.rb +13 -0
  82. data/test/lib/vedeu/output/clear_test.rb +1 -1
  83. data/test/lib/vedeu/output/compressor_test.rb +1 -1
  84. data/test/lib/vedeu/output/html_char_test.rb +1 -1
  85. data/test/lib/vedeu/output/output_test.rb +1 -1
  86. data/test/lib/vedeu/output/refresh_test.rb +17 -5
  87. data/test/lib/vedeu/output/renderers/escape_sequence_renderer_test.rb +4 -4
  88. data/test/lib/vedeu/output/renderers/{file_renderer_test.rb → file_test.rb} +4 -4
  89. data/test/lib/vedeu/output/renderers/{html_renderer_test.rb → html_test.rb} +4 -4
  90. data/test/lib/vedeu/output/renderers/{json_renderer_test.rb → json_test.rb} +4 -4
  91. data/test/lib/vedeu/output/renderers/{null_renderer_test.rb → null_test.rb} +3 -3
  92. data/test/lib/vedeu/output/renderers/{terminal_renderer_test.rb → terminal_test.rb} +4 -4
  93. data/test/lib/vedeu/output/renderers/{text_renderer_test.rb → text_test.rb} +4 -4
  94. data/test/lib/vedeu/output/style_test.rb +1 -1
  95. data/test/lib/vedeu/output/translator_test.rb +1 -1
  96. data/test/lib/vedeu/output/viewport_test.rb +1 -1
  97. data/test/lib/vedeu/output/virtual_terminal_test.rb +3 -3
  98. data/test/lib/vedeu/repositories/collection_test.rb +2 -2
  99. data/test/lib/vedeu/repositories/collections/chars_test.rb +1 -1
  100. data/test/lib/vedeu/repositories/collections/events_test.rb +1 -1
  101. data/test/lib/vedeu/repositories/collections/interfaces_test.rb +1 -1
  102. data/test/lib/vedeu/repositories/collections/keys_test.rb +1 -1
  103. data/test/lib/vedeu/repositories/collections/lines_test.rb +1 -1
  104. data/test/lib/vedeu/repositories/collections/streams_test.rb +1 -1
  105. data/test/lib/vedeu/repositories/repositories/borders_test.rb +1 -1
  106. data/test/lib/vedeu/repositories/repositories/buffers_test.rb +11 -23
  107. data/test/lib/vedeu/repositories/repositories/colours_test.rb +1 -1
  108. data/test/lib/vedeu/repositories/repositories/geometries_test.rb +1 -1
  109. data/test/lib/vedeu/repositories/repository_test.rb +1 -1
  110. data/test/lib/vedeu/storage/associative_store_test.rb +1 -1
  111. data/test/lib/vedeu/storage/conveyor_store_test.rb +1 -1
  112. data/test/lib/vedeu/storage/fifo_store_test.rb +1 -1
  113. data/test/lib/vedeu/support/template_test.rb +1 -1
  114. data/test/lib/vedeu/support/trace_test.rb +1 -1
  115. data/test/lib/vedeu/support/visibility_test.rb +2 -2
  116. data/test/test_helper.rb +1 -1
  117. data/vedeu.gemspec +1 -1
  118. metadata +36 -33
  119. data/lib/vedeu/geometry/null_geometry.rb +0 -70
  120. data/lib/vedeu/models/null.rb +0 -48
  121. data/lib/vedeu/models/null_interface.rb +0 -20
  122. data/lib/vedeu/output/null_border.rb +0 -75
  123. data/lib/vedeu/output/renderers/escape_sequence_renderer.rb +0 -43
  124. data/test/lib/vedeu/geometry/null_geometry_test.rb +0 -59
  125. data/test/lib/vedeu/models/null_interface_test.rb +0 -9
  126. data/test/lib/vedeu/models/null_test.rb +0 -66
  127. data/test/lib/vedeu/output/null_border_test.rb +0 -72
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adae57ef3023290f75d36a2744e07ef707297278
4
- data.tar.gz: ae4a68bbb7eb2254a774a93bfc41eac41b9e57b2
3
+ metadata.gz: 9465a952ab6e8149c69de234c8e51c5e6f09a2a2
4
+ data.tar.gz: 6eb60784e45eea477870787e5a5ced902dc5f1c9
5
5
  SHA512:
6
- metadata.gz: 70f4525ba7779abc257a051e2c82952f36ec208a207f511d67c70a1eb7e5d8c0ff741c36fc54c887a7265580bfc042e18de418b537af661af332317980806ce6
7
- data.tar.gz: be52af102efe89af2e0b17419ce9bae9b815eb45516a72970f7f4efafe74614f8516912e2602fd2c066bdcdad3af1a823bc47cd8b5d32f0da0ea3f824326cf55
6
+ metadata.gz: 48866fecffced7581f359ed1fb6107aedfa746d1035dd0c26443920b158f090ab45199c0d4cdcb84c4cea5d9aefdcc3210895e9cb86bc6d53e033b71692f646d
7
+ data.tar.gz: 1774d54f66bf61ff8639891c5ec3572740f9ae8f8be1d7019b9a603315720f17ccf61f92b534fc2c78c4f1a8e80577221bf98e944745966d3753feefb59f0d39
data/docs/dsl.md ADDED
@@ -0,0 +1,54 @@
1
+ Coupled with the API (for interacting with the running client application), the
2
+ DSL provides the mechanism to configure aspects of your application whilst
3
+ using Vedeu.
4
+
5
+
6
+ ### Borders
7
+
8
+ Borders are defined by name for each of the client application's interfaces or
9
+ views. They can be enabled or disabled (which controls whether they are
10
+ rendered or not), they have their own colours and styles, and each aspect of
11
+ the border can be controlled. The RubyDoc contains information for
12
+ configuring borders.
13
+
14
+ ### Geometry
15
+
16
+ Geometry is defined by name and allows the configuration of the position and
17
+ size of an interface.
18
+
19
+ ### Groups
20
+
21
+ Interfaces can be configured to be part of a named group. Once an interface is a
22
+ member of group, the group can be affected by other controls. For example,
23
+ assuming the client application is a simple Git client, it may have a group
24
+ called 'commit'. The 'commit' group will contain the interfaces 'diff' (to show
25
+ the changes), 'staged' (to show which files are staged) and 'unstaged'. A
26
+ refresh of the 'commit' group would cause all interfaces belonging to the group
27
+ to refresh. Similarly, showing or hiding the group would of course, show or
28
+ hide the interfaces of that group.
29
+
30
+ ### Interfaces
31
+
32
+
33
+
34
+ ### Keymaps
35
+
36
+ There are two built in keymaps with Vedeu, 'system' (keys needed by Vedeu to
37
+ operate, e.g. 'q' for quit, to quit the client application), and 'global' which
38
+ holds keys which perform actions no matter which interface is currently
39
+ focussed.
40
+
41
+ You can define keymaps by name which matches a defined interface. When that
42
+ interface is in focus, keys pressed as part of this definition will affect
43
+ that interface. This allows you to form context driven behaviour for your
44
+ application.
45
+
46
+
47
+ ### Menus
48
+
49
+
50
+
51
+ ### Views
52
+
53
+
54
+
data/docs/views.md CHANGED
@@ -1,14 +1,14 @@
1
1
  ## Views with Vedeu
2
2
 
3
3
  There are two ways to construct views with Vedeu. You would like to draw the
4
- view to the screen immediately (immediate render) or you want to save a view to
5
- be drawn when you trigger a refresh event later (deferred view).
4
+ view to the screen immediately (immediate render) or you want to save a view to
5
+ be drawn when you trigger a refresh event later (deferred view).
6
6
 
7
7
  ** LINK Both of these approaches require that you have defined an interface (or
8
- 'visible area') first. You can find out how to define an interface with Vedeu
9
- here. The examples in 'Immediate Render' and 'Deferred View' use these interface
10
- definitions: (Note: if you use these examples, ensure your terminal is at least
11
- 70 characters in width and 5 lines in height.)
8
+ 'visible area') first. You can find out how to define an interface with Vedeu
9
+ here. The examples in 'Immediate Render' and 'Deferred View' use these
10
+ interface definitions: (Note: if you use these examples, ensure your terminal
11
+ is at least 70 characters in width and 5 lines in height.)
12
12
 
13
13
  ```ruby
14
14
  Vedeu.interface 'main' do
@@ -30,31 +30,31 @@ definitions: (Note: if you use these examples, ensure your terminal is at least
30
30
  ```
31
31
 
32
32
  Both of these approaches use a concept of Buffers in Vedeu. There are three
33
- buffers for any defined interface. These are imaginatively called: 'back',
34
- 'front' and 'previous'.
33
+ buffers for any defined interface. These are imaginatively called: 'back',
34
+ 'front' and 'previous'.
35
35
 
36
36
  The 'back' buffer is the content for an interface which will be shown next time
37
- a refresh event is fired globally or for that interface. So, 'back' becomes
38
- 'front'.
37
+ a refresh event is fired globally or for that interface. So, 'back' becomes
38
+ 'front'.
39
39
 
40
40
  The 'front' buffer is the content for an interface which is currently showing.
41
41
  When a refresh event is fired, again, globally or for that interface
42
- specifically, the content of this 'front' buffer is first copied to the
43
- 'previous' buffer, and then the current 'back' buffer overwrites this 'front'
44
- buffer.
42
+ specifically, the content of this 'front' buffer is first copied to the
43
+ 'previous' buffer, and then the current 'back' buffer overwrites this 'front'
44
+ buffer.
45
45
 
46
46
  The 'previous' buffer contains what was shown on the 'front' before the current
47
- 'front'.
47
+ 'front'.
48
48
 
49
49
  You can only write to either the 'front' (you want the content to be drawn
50
- immediately) or the 'back' (you would like the content to be drawn on the next
51
- refresh).
50
+ immediately (immediate render)) or the 'back' (you would like the content to be
51
+ drawn on the next refresh (deferred view)).
52
52
 
53
53
  ### Immediate Render
54
54
 
55
55
  The immediate render DSL for Vedeu is accessed via `Vedeu.renders`. When this
56
- approach is used, the content defined is written directly to the 'front'
57
- buffer(s) for the interface(s) concerned. Take a glance at the example below:
56
+ approach is used, the content defined is written directly to the 'front'
57
+ buffer(s) for the interface(s) concerned. Take a glance at the example below:
58
58
 
59
59
  ```ruby
60
60
  Vedeu.renders do
@@ -81,13 +81,13 @@ buffer(s) for the interface(s) concerned. Take a glance at the example below:
81
81
  ### Deferred View
82
82
 
83
83
  The deferred view DSL for Vedeu is accessed via `Vedeu.views`. This approach
84
- writes the content defined to the 'back' buffer(s) for the interface(s)
85
- concerned. It will become the front when your application triggers the refresh
86
- event for the interface(s).
84
+ writes the content defined to the 'back' buffer(s) for the interface(s)
85
+ concerned. It will become the front when your application triggers the refresh
86
+ event for the interface(s).
87
87
 
88
88
  As you can see by comparing the examples above to these below, the immediate
89
- render simply wraps what is already here in the deferred view. Again, more
90
- specific information is available in the Rubydoc.
89
+ render simply wraps what is already here in the deferred view. Again, more
90
+ specific information is available in the Rubydoc.
91
91
 
92
92
  ```ruby
93
93
  Vedeu.views do
@@ -151,8 +151,8 @@ renders/views
151
151
  #### Authors Notes
152
152
 
153
153
  The Rubydoc documentation has more specific information about the DSL methods
154
- demonstrated above: [RubyDoc](http://rubydoc.info/gems/vedeu).
154
+ demonstrated above: [RubyDoc](http://rubydoc.info/gems/vedeu).
155
155
 
156
156
  I've tried to write the DSL in a way which makes it read nice; believing that
157
- this will make it easier to use. I hope this is the case for you.
157
+ this will make it easier to use. I hope this is the case for you.
158
158
 
@@ -23,7 +23,7 @@ class VedeuCursorApp
23
23
 
24
24
  geometry do
25
25
  centred true
26
- height 20
26
+ height 10
27
27
  width 20
28
28
  end
29
29
  end
@@ -14,7 +14,7 @@ class VedeuMaterialColoursApp
14
14
  configure do
15
15
  # debug!
16
16
  log '/tmp/vedeu_material_colours_app.log'
17
- renderers Vedeu::FileRenderer
17
+ renderers Vedeu::Renderers::File
18
18
  end
19
19
 
20
20
  interface 'main_interface' do
data/lib/vedeu/all.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  require 'vedeu/debug'
5
5
  require 'vedeu/traps'
6
6
 
7
+ require 'vedeu/null/all'
7
8
  require 'vedeu/geometry/all'
8
9
  require 'vedeu/storage/all'
9
10
  require 'vedeu/repositories/all'
@@ -229,14 +229,7 @@ module Vedeu
229
229
  # Triggering the ':_hide_group_' event to which this named interface belongs
230
230
  # will also hide the interface.
231
231
  Vedeu.bind(:_hide_interface_) do |name|
232
- if name && Vedeu.interfaces.registered?(name)
233
- interface = Vedeu.interfaces.find(name)
234
-
235
- if interface.visible?
236
- interface = Vedeu::Visibility.hide(interface)
237
- Vedeu.buffers.clear(interface.name)
238
- end
239
- end
232
+ Vedeu.buffers.by_name(name).hide
240
233
  end
241
234
 
242
235
  # Will show the named interface. If the interface is currently invisible, it
@@ -245,13 +238,7 @@ module Vedeu
245
238
  # Triggering the ':_show_group_' event to which this named interface belongs
246
239
  # will also show the interface.
247
240
  Vedeu.bind(:_show_interface_) do |name|
248
- if name && Vedeu.interfaces.registered?(name)
249
- interface = Vedeu.interfaces.find(name)
250
-
251
- interface = Vedeu::Visibility.show(interface) unless interface.visible?
252
-
253
- Vedeu.buffers.render(interface.name)
254
- end
241
+ Vedeu.buffers.by_name(name).show
255
242
  end
256
243
 
257
244
  # Will toggle the visibility of the named interface. If the interface is
@@ -65,6 +65,23 @@ module Vedeu
65
65
  true
66
66
  end
67
67
 
68
+ # Returns the front buffer or, if that is empty, the interface cleared.
69
+ #
70
+ # @return [void]
71
+ def clear
72
+ Vedeu::Output.render(clear_buffer) unless clear_buffer.empty?
73
+
74
+ clear_buffer
75
+ end
76
+
77
+ # @return [void]
78
+ def hide
79
+ if visible?
80
+ Vedeu::Visibility.hide(interface)
81
+ clear
82
+ end
83
+ end
84
+
68
85
  # Return the content for this buffer.
69
86
  #
70
87
  # - If we have new content (i.e. content on 'back') to be shown, we first
@@ -84,13 +101,12 @@ module Vedeu
84
101
  end
85
102
  alias_method :content, :render
86
103
 
87
- # Returns the front buffer or, if that is empty, the interface cleared.
88
- #
89
104
  # @return [void]
90
- def clear
91
- Vedeu::Output.render(clear_buffer) unless clear_buffer.empty?
92
-
93
- clear_buffer
105
+ def show
106
+ unless visible?
107
+ Vedeu::Visibility.show(interface)
108
+ render
109
+ end
94
110
  end
95
111
 
96
112
  private
@@ -131,6 +147,8 @@ module Vedeu
131
147
  #
132
148
  # @return [Boolean]
133
149
  def swap
150
+ Vedeu.log(type: :output, message: "Buffer swapping: '#{name}'")
151
+
134
152
  @previous = front
135
153
  @front = back
136
154
  @back = nil
@@ -153,7 +171,7 @@ module Vedeu
153
171
 
154
172
  # @return [Vedeu::Interface]
155
173
  def interface
156
- @interface ||= Vedeu.interfaces.find(name)
174
+ @interface ||= Vedeu.interfaces.by_name(name)
157
175
  end
158
176
 
159
177
  # @return [Vedeu::Interface]
@@ -167,6 +185,11 @@ module Vedeu
167
185
  end
168
186
  end
169
187
 
188
+ # @see Vedeu::Interface#visible
189
+ def visible?
190
+ interface.visible?
191
+ end
192
+
170
193
  end # Buffer
171
194
 
172
195
  end # Vedeu
@@ -78,7 +78,7 @@ module Vedeu
78
78
  # @return [Interface]
79
79
  def store_group
80
80
  unless group.nil? || group.empty? || Vedeu.groups.registered?(group)
81
- Vedeu::Group.new(name, group).store
81
+ Vedeu::Group.new(members: name, name: group).store
82
82
  end
83
83
 
84
84
  self
@@ -270,7 +270,7 @@ module Vedeu
270
270
  interactive: true,
271
271
  log: '/tmp/vedeu.log',
272
272
  once: false,
273
- renderers: [Vedeu::TerminalRenderer],
273
+ renderers: [Vedeu::Renderers::Terminal],
274
274
  stdin: nil,
275
275
  stdout: nil,
276
276
  stderr: nil,
@@ -24,6 +24,10 @@ module Vedeu
24
24
  @name = name
25
25
  end
26
26
 
27
+ # Renders the cursor in the terminal. If the cursor's x or y offsets are
28
+ # greater or equal to the interface's width or height respectively, then
29
+ # the view is also refreshed, causing the content to be offset also.
30
+ #
27
31
  # @return [Array]
28
32
  def render
29
33
  Vedeu.log(type: :info, message: "Refreshing cursor: '#{name}'")
@@ -12,7 +12,12 @@ module Vedeu
12
12
  # drawn or not.
13
13
  #
14
14
  # @example
15
- # # Borders can be defined as part of a view definition...
15
+ # # Borders can be defined when defining your interface...
16
+ # Vedeu.interface 'my_interface' do
17
+ # border do
18
+ # # ...
19
+ #
20
+ # # ...or as part of a view definition...
16
21
  # Vedeu.renders do
17
22
  # view 'border_demo' do
18
23
  # border do
@@ -5,7 +5,6 @@ require_relative 'dimension'
5
5
  require_relative 'geometry'
6
6
  require_relative 'grid'
7
7
  require_relative 'index_position'
8
- require_relative 'null_geometry'
9
8
  require_relative 'position_index'
10
9
  require_relative 'position'
11
10
  require_relative 'position_validator'
@@ -148,26 +148,6 @@ module Vedeu
148
148
  x - offset
149
149
  end
150
150
 
151
- # @return [Vedeu::Position]
152
- def top_left
153
- Vedeu::Position[y, x]
154
- end
155
-
156
- # @return [Vedeu::Position]
157
- def bottom_left
158
- Vedeu::Position[yn, x]
159
- end
160
-
161
- # @return [Vedeu::Position]
162
- def top_right
163
- Vedeu::Position[y, xn]
164
- end
165
-
166
- # @return [Vedeu::Position]
167
- def bottom_right
168
- Vedeu::Position[yn, xn]
169
- end
170
-
171
151
  end # Area
172
152
 
173
153
  end # Vedeu
@@ -70,56 +70,6 @@ module Vedeu
70
70
  end
71
71
  end
72
72
 
73
- # Returns the index for a given y position.
74
- #
75
- # @example
76
- # # y_range = [7, 8, 9, 10]
77
- # # y = 8
78
- # y_index # => 1 # because (y_range[1] = 8)
79
- # y_index(10) # => 3
80
- # y_index(5) # => 0
81
- # y_index(15) # => 3
82
- #
83
- # @param position [Fixnum]
84
- # @return [Fixnum]
85
- def y_index(position = y)
86
- if height <= 0 || position <= y
87
- 0
88
-
89
- elsif position >= yn
90
- yn_index
91
-
92
- else
93
- y_range.index(position)
94
-
95
- end
96
- end
97
-
98
- # Returns the index for a given x position.
99
- #
100
- # @example
101
- # # x_range = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
102
- # # x = 8
103
- # x_index # => 4 # because (x_range[4] = 8)
104
- # x_index(11) # => 7
105
- # x_index(2) # => 0
106
- # x_index(15) # => 9
107
- #
108
- # @param position [Fixnum]
109
- # @return [Fixnum]
110
- def x_index(position = x)
111
- if width <= 0 || position <= x
112
- 0
113
-
114
- elsif position >= xn
115
- xn_index
116
-
117
- else
118
- x_range.index(position)
119
-
120
- end
121
- end
122
-
123
73
  # Returns the y coordinate for a given index.
124
74
  #
125
75
  # @example
@@ -46,11 +46,7 @@ module Vedeu
46
46
  :yn,
47
47
  :x,
48
48
  :height,
49
- :width,
50
- :top_left,
51
- :top_right,
52
- :bottom_left,
53
- :bottom_right
49
+ :width
54
50
 
55
51
  # @!attribute [rw] centred
56
52
  # @return [Boolean]
@@ -15,6 +15,8 @@ module Vedeu
15
15
  alias_method :first, :y
16
16
  alias_method :last, :x
17
17
 
18
+ # Convenience constructor for Vedeu::Position.
19
+ #
18
20
  # @param (see #initialize)
19
21
  def self.[](y, x)
20
22
  new(y, x)
@@ -52,6 +54,13 @@ module Vedeu
52
54
  end
53
55
  alias_method :==, :eql?
54
56
 
57
+ # Return a tuple containing the y and x coordinates.
58
+ #
59
+ # @return [Array<Fixnum>]
60
+ def to_a
61
+ [y, x]
62
+ end
63
+
55
64
  # Return the escape sequence required to position the cursor at a particular
56
65
  # point on the screen. When passed a block, will do the aforementioned,
57
66
  # call the block and then reposition to this location.
@@ -4,17 +4,8 @@ module Vedeu
4
4
  #
5
5
  class PositionIndex
6
6
 
7
- # @!attribute [r] y
8
- # @return [Fixnum]
9
- attr_reader :y
10
-
11
- # @!attribute [r] x
12
- # @return [Fixnum]
13
- attr_reader :x
14
-
15
- alias_method :first, :y
16
- alias_method :last, :x
17
-
7
+ # Convenience constructor for Vedeu::Position.
8
+ #
18
9
  # @param (see #initialize)
19
10
  def self.[](y, x)
20
11
  new(y, x).[]
@@ -26,11 +17,13 @@ module Vedeu
26
17
  # @param x [Fixnum]
27
18
  # @return [Vedeu::PositionIndex]
28
19
  def initialize(y, x)
29
- @y = ((y - 1) <= 1) ? 0 : (y - 1)
30
- @x = ((x - 1) <= 1) ? 0 : (x - 1)
20
+ @y = y
21
+ @x = x
31
22
  end
32
23
 
33
- # @return [Array]
24
+ # Returns a tuple containing the y and x coordinates.
25
+ #
26
+ # @return [Array<Fixnum>]
34
27
  def []
35
28
  [y, x]
36
29
  end
@@ -47,6 +40,18 @@ module Vedeu
47
40
  Vedeu::Position.new(y, x)
48
41
  end
49
42
 
43
+ # @return [Fixnum]
44
+ def x
45
+ @_x ||= ((@x - 1) <= 1) ? 0 : (@x - 1)
46
+ end
47
+ alias_method :last, :x
48
+
49
+ # @return [Fixnum]
50
+ def y
51
+ @_y ||= ((@y - 1) <= 1) ? 0 : (@y - 1)
52
+ end
53
+ alias_method :first, :y
54
+
50
55
  end # PositionIndex
51
56
 
52
57
  end # Vedeu
@@ -53,6 +53,9 @@ module Vedeu
53
53
  @y = y
54
54
  end
55
55
 
56
+ # Ensures the coordinates provided are within the terminal, interface and
57
+ # if applicable, bordered interface area.
58
+ #
56
59
  # @return [PositionValidator]
57
60
  def validate
58
61
  terminal_validation
@@ -1,8 +1,5 @@
1
1
  require 'vedeu/repositories/all'
2
2
 
3
- require_relative 'null'
4
- require_relative 'null_interface'
5
-
6
3
  require_relative 'cell'
7
4
  require_relative 'char'
8
5
  require_relative 'stream'
@@ -1,8 +1,6 @@
1
1
  require 'vedeu/models/all'
2
- require 'vedeu/output/null_border'
3
2
  require 'vedeu/output/presentation'
4
3
  require 'vedeu/buffers/display_buffer'
5
- require 'vedeu/buffers/buffer'
6
4
 
7
5
  module Vedeu
8
6
 
@@ -42,7 +40,7 @@ module Vedeu
42
40
  attr_accessor :parent
43
41
 
44
42
  # @!attribute [rw] visible
45
- # @return [String|Symbol]
43
+ # @return [Boolean] Whether the interface is visible.
46
44
  attr_accessor :visible
47
45
  alias_method :visible?, :visible
48
46
 
@@ -111,7 +109,7 @@ module Vedeu
111
109
  hide_cursor,
112
110
  Vedeu::Clear.new(self).render,
113
111
  Vedeu.borders.by_name(name).render,
114
- Vedeu::Viewport.new(self).render,
112
+ Vedeu::Viewport.render(self),
115
113
  show_cursor,
116
114
  ]
117
115
  end
@@ -0,0 +1,5 @@
1
+ require_relative 'border'
2
+ require_relative 'buffer'
3
+ require_relative 'generic'
4
+ require_relative 'geometry'
5
+ require_relative 'interface'
@@ -0,0 +1,79 @@
1
+ module Vedeu
2
+
3
+ module Null
4
+
5
+ # Provides a non-existent Vedeu::Border that acts like the real thing, but
6
+ # does nothing.
7
+ #
8
+ class Border
9
+
10
+ # @!attribute [r] name
11
+ # @return [String|NilClass]
12
+ attr_reader :name
13
+
14
+ # Returns a new instance of Vedeu::Null::Border.
15
+ #
16
+ # @param name [String|NilClass]
17
+ # @return [Vedeu::Null::Border]
18
+ def initialize(name = nil)
19
+ @name = name
20
+ end
21
+
22
+ # @return [Fixnum]
23
+ def bx
24
+ geometry.x
25
+ end
26
+ alias_method :x, :bx
27
+
28
+ # @return [Fixnum]
29
+ def bxn
30
+ geometry.xn
31
+ end
32
+ alias_method :xn, :bxn
33
+
34
+ # @return [Fixnum]
35
+ def by
36
+ geometry.y
37
+ end
38
+ alias_method :y, :by
39
+
40
+ # @return [Fixnum]
41
+ def byn
42
+ geometry.yn
43
+ end
44
+ alias_method :yn, :byn
45
+
46
+ # @return [FalseClass]
47
+ def enabled?
48
+ false
49
+ end
50
+
51
+ # @return [Fixnum]
52
+ def height
53
+ (by..byn).size
54
+ end
55
+
56
+ # @return [Array]
57
+ def render
58
+ []
59
+ end
60
+
61
+ # @return [Fixnum]
62
+ def width
63
+ (bx..bxn).size
64
+ end
65
+
66
+ private
67
+
68
+ # Returns the geometry for the interface.
69
+ #
70
+ # @return (see Vedeu::Geometries#by_name)
71
+ def geometry
72
+ @geometry ||= Vedeu.geometries.by_name(name)
73
+ end
74
+
75
+ end # Border
76
+
77
+ end # Null
78
+
79
+ end # Vedeu