vedeu 0.4.43 → 0.4.44

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/bin/vedeu +19 -0
  4. data/lib/vedeu.rb +0 -34
  5. data/lib/vedeu/all.rb +4 -1
  6. data/lib/vedeu/application/application_view.rb +9 -9
  7. data/lib/vedeu/application/controller.rb +6 -5
  8. data/lib/vedeu/application/helper.rb +3 -16
  9. data/lib/vedeu/application/view.rb +3 -16
  10. data/lib/vedeu/bindings/all.rb +5 -0
  11. data/lib/vedeu/bindings/bindings.rb +115 -0
  12. data/lib/vedeu/bindings/drb.rb +45 -0
  13. data/lib/vedeu/bindings/menus.rb +53 -0
  14. data/lib/vedeu/bindings/movement.rb +76 -0
  15. data/lib/vedeu/bindings/visibility.rb +53 -0
  16. data/lib/vedeu/buffers/buffer.rb +2 -0
  17. data/lib/vedeu/cli/generator/templates/application/app/controllers/name.erb +2 -2
  18. data/lib/vedeu/cli/generator/templates/application/app/helpers/name.erb +2 -0
  19. data/lib/vedeu/cli/generator/templates/application/config/configuration.erb +3 -0
  20. data/lib/vedeu/cli/generator/view.rb +0 -5
  21. data/lib/vedeu/cli/main.rb +12 -0
  22. data/lib/vedeu/cursor/reposition.rb +4 -4
  23. data/lib/vedeu/dsl/interface.rb +0 -27
  24. data/lib/vedeu/exceptions.rb +65 -0
  25. data/lib/vedeu/geometry/geometry.rb +2 -2
  26. data/lib/vedeu/geometry/grid.rb +2 -2
  27. data/lib/vedeu/input/input.rb +34 -28
  28. data/lib/vedeu/null/geometry.rb +2 -2
  29. data/lib/vedeu/output/colour.rb +0 -2
  30. data/lib/vedeu/output/esc.rb +7 -1
  31. data/lib/vedeu/output/render_border.rb +5 -0
  32. data/lib/vedeu/output/renderers/json.rb +7 -2
  33. data/lib/vedeu/support/terminal.rb +1 -1
  34. data/lib/vedeu/version.rb +1 -1
  35. data/test/lib/vedeu/application/controller_test.rb +0 -4
  36. data/test/lib/vedeu/application/helper_test.rb +0 -8
  37. data/test/lib/vedeu/application/view_test.rb +0 -8
  38. data/test/lib/vedeu/bindings/bindings_test.rb +43 -0
  39. data/test/lib/vedeu/bindings/drb_test.rb +23 -0
  40. data/test/lib/vedeu/bindings/menus_test.rb +26 -0
  41. data/test/lib/vedeu/bindings/movement_test.rb +28 -0
  42. data/test/lib/vedeu/bindings/visibility_test.rb +27 -0
  43. data/test/lib/vedeu/buffers/buffer_test.rb +73 -38
  44. data/test/lib/vedeu/cli/main_test.rb +47 -0
  45. data/test/lib/vedeu/dsl/interface_test.rb +4 -7
  46. data/test/lib/vedeu/exceptions_test.rb +5 -0
  47. data/test/lib/vedeu/input/input_test.rb +9 -0
  48. data/test/lib/vedeu/output/esc_test.rb +4 -1
  49. metadata +21 -5
  50. data/lib/vedeu/bindings.rb +0 -275
  51. data/test/lib/vedeu/bindings_test.rb +0 -88
@@ -5,6 +5,53 @@ module Vedeu
5
5
  module CLI
6
6
 
7
7
  describe Main do
8
+
9
+ let(:described) { Vedeu::CLI::Main }
10
+ let(:instance) { described.new }
11
+
12
+ describe '#new' do
13
+ let(:_name) { 'app_name' }
14
+
15
+ before do
16
+ instance.stubs(:say)
17
+ Vedeu::Generator::Application.stubs(:generate).returns('')
18
+ end
19
+
20
+ subject { instance.new(_name) }
21
+
22
+ it {
23
+ Vedeu::Generator::Application.expects(:generate).with(_name)
24
+ subject
25
+ }
26
+ end
27
+
28
+ describe '#view' do
29
+ let(:_name) { 'view_name' }
30
+
31
+ before do
32
+ instance.stubs(:say)
33
+ Vedeu::Generator::View.stubs(:generate).returns('')
34
+ end
35
+
36
+ subject { instance.view(_name) }
37
+
38
+ it {
39
+ Vedeu::Generator::View.expects(:generate).with(_name)
40
+ subject
41
+ }
42
+ end
43
+
44
+ describe '#version' do
45
+ before { instance.stubs(:say) }
46
+
47
+ subject { instance.version }
48
+
49
+ it {
50
+ instance.expects(:say).with("vedeu #{Vedeu::VERSION}")
51
+ subject
52
+ }
53
+ end
54
+
8
55
  end # Main
9
56
 
10
57
  end # CLI
@@ -25,6 +25,8 @@ module Vedeu
25
25
  end
26
26
 
27
27
  describe '#border' do
28
+ after { Vedeu.borders.reset }
29
+
28
30
  subject {
29
31
  instance.border do
30
32
  # ...
@@ -59,18 +61,13 @@ module Vedeu
59
61
  end
60
62
 
61
63
  describe '#border!' do
64
+ after { Vedeu.borders.reset }
65
+
62
66
  subject { instance.border! }
63
67
 
64
68
  it { subject.must_be_instance_of(Vedeu::Border) }
65
69
  end
66
70
 
67
- describe '#button' do
68
- let(:label) { 'No' }
69
- let(:_value) { false }
70
-
71
- subject { instance.button(label, _value) }
72
- end
73
-
74
71
  describe '#cursor' do
75
72
  let(:_value) {}
76
73
 
@@ -0,0 +1,5 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ end
@@ -55,6 +55,15 @@ module Vedeu
55
55
  Vedeu.expects(:trigger).with(:_keypress_, :up)
56
56
  subject
57
57
  end
58
+
59
+ context 'when the key is an F key' do
60
+ let(:keypress) { "\e[17~" }
61
+
62
+ it 'triggers an event with the keypress' do
63
+ Vedeu.expects(:trigger).with(:_keypress_, :f6)
64
+ subject
65
+ end
66
+ end
58
67
  end
59
68
  end
60
69
  end
@@ -6,6 +6,8 @@ module Vedeu
6
6
 
7
7
  let(:described) { Vedeu::Esc }
8
8
 
9
+ before { Vedeu::Terminal.stubs(:size).returns([80, 25]) }
10
+
9
11
  describe 'alias methods' do
10
12
  it { described.must_respond_to(:foreground_codes) }
11
13
  end
@@ -116,7 +118,8 @@ module Vedeu
116
118
  end
117
119
 
118
120
  it 'returns an escape sequence when the style is screen_exit' do
119
- described.string('screen_exit').must_equal("\e[?25h\e[39m\e[49m\e[0m")
121
+ described.string('screen_exit')
122
+ .must_equal("\e[?25h\e[39m\e[49m\e[0m\e[80;25H\n")
120
123
  end
121
124
 
122
125
  it 'returns an escape sequence when the style is negative' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.43
4
+ version: 0.4.44
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-05 00:00:00.000000000 Z
11
+ date: 2015-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -312,7 +312,12 @@ files:
312
312
  - lib/vedeu/application/controller.rb
313
313
  - lib/vedeu/application/helper.rb
314
314
  - lib/vedeu/application/view.rb
315
- - lib/vedeu/bindings.rb
315
+ - lib/vedeu/bindings/all.rb
316
+ - lib/vedeu/bindings/bindings.rb
317
+ - lib/vedeu/bindings/drb.rb
318
+ - lib/vedeu/bindings/menus.rb
319
+ - lib/vedeu/bindings/movement.rb
320
+ - lib/vedeu/bindings/visibility.rb
316
321
  - lib/vedeu/bootstrap.rb
317
322
  - lib/vedeu/buffers/all.rb
318
323
  - lib/vedeu/buffers/buffer.rb
@@ -382,6 +387,7 @@ files:
382
387
  - lib/vedeu/events/all.rb
383
388
  - lib/vedeu/events/event.rb
384
389
  - lib/vedeu/events/trigger.rb
390
+ - lib/vedeu/exceptions.rb
385
391
  - lib/vedeu/geometry/all.rb
386
392
  - lib/vedeu/geometry/area.rb
387
393
  - lib/vedeu/geometry/coordinate.rb
@@ -495,7 +501,11 @@ files:
495
501
  - test/lib/vedeu/application/helper_test.rb
496
502
  - test/lib/vedeu/application/view_test.rb
497
503
  - test/lib/vedeu/application_test.rb
498
- - test/lib/vedeu/bindings_test.rb
504
+ - test/lib/vedeu/bindings/bindings_test.rb
505
+ - test/lib/vedeu/bindings/drb_test.rb
506
+ - test/lib/vedeu/bindings/menus_test.rb
507
+ - test/lib/vedeu/bindings/movement_test.rb
508
+ - test/lib/vedeu/bindings/visibility_test.rb
499
509
  - test/lib/vedeu/bootstrap_test.rb
500
510
  - test/lib/vedeu/buffers/buffer_test.rb
501
511
  - test/lib/vedeu/buffers/display_buffer_test.rb
@@ -530,6 +540,7 @@ files:
530
540
  - test/lib/vedeu/dsl/view_test.rb
531
541
  - test/lib/vedeu/events/event_test.rb
532
542
  - test/lib/vedeu/events/trigger_test.rb
543
+ - test/lib/vedeu/exceptions_test.rb
533
544
  - test/lib/vedeu/geometry/area_test.rb
534
545
  - test/lib/vedeu/geometry/coordinate_test.rb
535
546
  - test/lib/vedeu/geometry/dimension_test.rb
@@ -660,7 +671,11 @@ test_files:
660
671
  - test/lib/vedeu/application/helper_test.rb
661
672
  - test/lib/vedeu/application/view_test.rb
662
673
  - test/lib/vedeu/application_test.rb
663
- - test/lib/vedeu/bindings_test.rb
674
+ - test/lib/vedeu/bindings/bindings_test.rb
675
+ - test/lib/vedeu/bindings/drb_test.rb
676
+ - test/lib/vedeu/bindings/menus_test.rb
677
+ - test/lib/vedeu/bindings/movement_test.rb
678
+ - test/lib/vedeu/bindings/visibility_test.rb
664
679
  - test/lib/vedeu/bootstrap_test.rb
665
680
  - test/lib/vedeu/buffers/buffer_test.rb
666
681
  - test/lib/vedeu/buffers/display_buffer_test.rb
@@ -695,6 +710,7 @@ test_files:
695
710
  - test/lib/vedeu/dsl/view_test.rb
696
711
  - test/lib/vedeu/events/event_test.rb
697
712
  - test/lib/vedeu/events/trigger_test.rb
713
+ - test/lib/vedeu/exceptions_test.rb
698
714
  - test/lib/vedeu/geometry/area_test.rb
699
715
  - test/lib/vedeu/geometry/coordinate_test.rb
700
716
  - test/lib/vedeu/geometry/dimension_test.rb
@@ -1,275 +0,0 @@
1
- module Vedeu
2
-
3
- # Creates system events which when called provide a variety of core functions
4
- # and behaviours. They are soft-namespaced using underscores.
5
- #
6
- # @note
7
- # Unbinding any of these events is likely to cause problems, so I would
8
- # advise leaving them alone. A safe rule: if the name starts with an
9
- # underscore, it's probably used by Vedeu internally.
10
- #
11
- # :nocov:
12
- #
13
- # @api public
14
- module Bindings
15
-
16
- # Triggering this event will send input to the running application as long
17
- # as it has the DRb server running.
18
- Vedeu.bind(:_drb_input_) do |data, type|
19
- Vedeu.log(type: :drb, message: "Sending input (#{type})")
20
-
21
- case type
22
- when :command then Vedeu.trigger(:_command_, data)
23
- else Vedeu.trigger(:_keypress_, data)
24
- end
25
- end
26
-
27
- Vedeu.bind(:_drb_retrieve_output_) { Vedeu::VirtualBuffer.retrieve }
28
-
29
- # Triggering this event with 'data' will push data into the running
30
- # application's virtual buffer.
31
- Vedeu.bind(:_drb_store_output_) do |data|
32
- Vedeu::VirtualBuffer.store(Vedeu::Terminal.virtual.output(data))
33
- end
34
-
35
- # Use the DRb server to request the client application to restart.
36
- Vedeu.bind(:_drb_restart_) { Vedeu::Distributed::Server.restart }
37
-
38
- # Use the DRb server to request the client application to start.
39
- Vedeu.bind(:_drb_start_) { Vedeu::Distributed::Server.start }
40
-
41
- # Use the DRb server to request the status of the client application.
42
- Vedeu.bind(:_drb_status_) { Vedeu::Distributed::Server.status }
43
-
44
- # Use the DRb server to request the client application to stop.
45
- Vedeu.bind(:_drb_stop_) { Vedeu::Distributed::Server.stop }
46
-
47
- # Vedeu triggers this event when `:_exit_` is triggered. You can hook into
48
- # this to perform a special action before the application terminates. Saving
49
- # the user's work, session or preferences might be popular here.
50
- Vedeu.bind(:_cleanup_) do
51
- Vedeu.trigger(:_drb_stop_)
52
- Vedeu.trigger(:cleanup)
53
- end
54
-
55
- # When triggered, Vedeu will trigger a `:cleanup` event which you can define
56
- # (to save files, etc) and attempt to exit.
57
- Vedeu.bind(:_exit_) { Vedeu::Application.stop }
58
-
59
- # Vedeu triggers this event when it is ready to enter the main loop. Client
60
- # applications can listen for this event and perform some action(s), like
61
- # render the first screen, interface or make a sound. When Vedeu triggers
62
- # this event, the :_refresh_ event is also triggered automatically.
63
- Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
64
-
65
- # Will cause the triggering of the `:key` event; which
66
- # you should define to 'do things'. If the `escape` key is pressed, then
67
- # `key` is triggered with the argument `:escape`, also an internal event
68
- # `_mode_switch_` is triggered.
69
- Vedeu.bind(:_keypress_) { |key| Vedeu.keypress(key) }
70
-
71
- # Will cause the triggering of the `:command` event; which you should define
72
- # to 'do things'.
73
- Vedeu.bind(:_command_) { |command| Vedeu.trigger(:command, command) }
74
-
75
- # When triggered with a message will cause Vedeu to log the message if
76
- # logging is enabled in the configuration.
77
- Vedeu.bind(:_log_) { |msg| Vedeu.log(type: :debug, message: msg) }
78
-
79
- # When triggered (after the user presses `escape`), Vedeu switches from a
80
- # "raw mode" terminal to a "cooked mode" terminal. The idea here being that
81
- # the raw mode is for single keypress actions, whilst cooked mode allows the
82
- # user to enter more elaborate commands- such as commands with arguments.
83
- Vedeu.bind(:_mode_switch_) { fail ModeSwitch }
84
-
85
- # When triggered will cause Vedeu to trigger the `:_clear_` and `:_refresh_`
86
- # events. Please see those events for their behaviour.
87
- Vedeu.bind(:_resize_, delay: 0.15) { Vedeu.resize }
88
-
89
- # @see {Vedeu::Move}
90
- Vedeu.bind(:_cursor_down_) do |name|
91
- Vedeu::Move.by_name(Vedeu::Cursor, :down, name)
92
- end
93
-
94
- # @see {Vedeu::Move}
95
- Vedeu.bind(:_cursor_left_) do |name|
96
- Vedeu::Move.by_name(Vedeu::Cursor, :left, name)
97
- end
98
-
99
- # @see {Vedeu::Move}
100
- Vedeu.bind(:_cursor_right_) do |name|
101
- Vedeu::Move.by_name(Vedeu::Cursor, :right, name)
102
- end
103
-
104
- # @see {Vedeu::Move}
105
- Vedeu.bind(:_cursor_up_) do |name|
106
- Vedeu::Move.by_name(Vedeu::Cursor, :up, name)
107
- end
108
-
109
- # @see {Vedeu::Move}
110
- Vedeu.bind(:_geometry_down_) do |name|
111
- Vedeu::Move.by_name(Vedeu::Geometry, :down, name)
112
- end
113
-
114
- # @see {Vedeu::Move}
115
- Vedeu.bind(:_geometry_left_) do |name|
116
- Vedeu::Move.by_name(Vedeu::Geometry, :left, name)
117
- end
118
-
119
- # @see {Vedeu::Move}
120
- Vedeu.bind(:_geometry_right_) do |name|
121
- Vedeu::Move.by_name(Vedeu::Geometry, :right, name)
122
- end
123
-
124
- # @see {Vedeu::Move}
125
- Vedeu.bind(:_geometry_up_) do |name|
126
- Vedeu::Move.by_name(Vedeu::Geometry, :up, name)
127
- end
128
-
129
- # @see {Vedeu::Move}
130
- Vedeu.bind(:_cursor_origin_) do |name|
131
- Vedeu::Move.by_name(Vedeu::Cursor, :origin, name)
132
- end
133
-
134
- # When triggered will return the current position of the cursor.
135
- Vedeu.bind(:_cursor_position_) do |name|
136
- Vedeu.cursors.by_name(name).position
137
- end
138
-
139
- # Move the cursor to a relative position inside the interface.
140
- #
141
- # @todo
142
- # - The content of the interface needs to be a consideration.
143
- # - If the screen size changes, what should happen to the cursor.
144
- # - How do we represent cursors which are deliberately positioned outside
145
- # of the viewable area?
146
- #
147
- Vedeu.bind(:_cursor_reposition_) do |name, y, x|
148
- Vedeu::Reposition.to(Vedeu::Cursor, name, y, x)
149
- end
150
-
151
- # @see {Vedeu::Move}
152
- Vedeu.bind(:_cursor_reset_) { |name| Vedeu.trigger(:_cursor_origin_, name) }
153
-
154
- # When triggered with an interface name will focus that interface and
155
- # restore the cursor position and visibility.
156
- Vedeu.bind(:_focus_by_name_) { |name| Vedeu.focus_by_name(name) }
157
-
158
- # When triggered will focus the next interface and restore the cursor
159
- # position and visibility.
160
- Vedeu.bind(:_focus_next_) { Vedeu.focus_next }
161
-
162
- # When triggered will focus the previous interface and restore the cursor
163
- # position and visibility.
164
- Vedeu.bind(:_focus_prev_) { Vedeu.focus_previous }
165
-
166
- # Requires target menu name as argument. Makes the last menu item the
167
- # current menu item.
168
- Vedeu.bind(:_menu_bottom_) { |name| Vedeu.menus.find(name).bottom_item }
169
-
170
- # Requires target menu name as argument. Returns the current menu item.
171
- Vedeu.bind(:_menu_current_) { |name| Vedeu.menus.find(name).current_item }
172
-
173
- # Requires target menu name as argument. Deselects all menu items.
174
- Vedeu.bind(:_menu_deselect_) { |name| Vedeu.menus.find(name).deselect_item }
175
-
176
- # Requires target menu name as argument. Returns all the menu items with
177
- # respective `current` or `selected` boolean indicators.
178
- Vedeu.bind(:_menu_items_) { |name| Vedeu.menus.find(name).items }
179
-
180
- # Requires target menu name as argument. Makes the next menu item the
181
- # current menu item, until it reaches the last item.
182
- Vedeu.bind(:_menu_next_) { |name| Vedeu.menus.find(name).next_item }
183
-
184
- # Requires target menu name as argument. Makes the previous menu item the
185
- # current menu item, until it reaches the first item.
186
- Vedeu.bind(:_menu_prev_) { |name| Vedeu.menus.find(name).prev_item }
187
-
188
- # Requires target menu name as argument. Returns the selected menu item.
189
- Vedeu.bind(:_menu_selected_) { |name| Vedeu.menus.find(name).selected_item }
190
-
191
- # Requires target menu name as argument. Makes the current menu item also
192
- # the selected menu item.
193
- Vedeu.bind(:_menu_select_) { |name| Vedeu.menus.find(name).select_item }
194
-
195
- # Requires target menu name as argument. Makes the first menu item the
196
- # current menu item.
197
- Vedeu.bind(:_menu_top_) { |name| Vedeu.menus.find(name).top_item }
198
-
199
- # Requires target menu name as argument. Returns a subset of the menu items;
200
- # starting at the current item to the last item.
201
- Vedeu.bind(:_menu_view_) { |name| Vedeu.menus.find(name).view }
202
-
203
- # Clears the whole terminal space, or the named interface area to be cleared
204
- # if given.
205
- Vedeu.bind(:_clear_) { |name| Vedeu::Clear.by_name(name) }
206
-
207
- # Will cause all interfaces to refresh, or the named interface if given.
208
- #
209
- # @note
210
- # Hidden interfaces will be still refreshed in memory but not shown.
211
- Vedeu.bind(:_refresh_) do |name|
212
- name ? Vedeu::Refresh.by_name(name) : Vedeu::Refresh.all
213
- end
214
-
215
- # Will cause the named cursor to refresh, or the cursor of the interface
216
- # which is currently in focus.
217
- Vedeu.bind(:_refresh_cursor_) { |name| Vedeu::RefreshCursor.render(name) }
218
-
219
- # Will cause all interfaces in the named group to refresh.
220
- Vedeu.bind(:_refresh_group_) { |name| Vedeu::Refresh.by_group(name) }
221
-
222
- # Clears the spaces occupied by the interfaces belonging to the named group.
223
- Vedeu.bind(:_clear_group_) { |name| Vedeu::Clear.by_group(name) }
224
-
225
- # Hide the cursor of the named interface or interface currently in focus.
226
- Vedeu.bind(:_hide_cursor_) do |name|
227
- Vedeu::Visibility.for_cursor(name).hide
228
- end
229
- Vedeu.bind(:_cursor_hide_) { |name| Vedeu.trigger(:_hide_cursor_, name) }
230
-
231
- # Will hide all of the interfaces belonging to the named group. Useful for
232
- # hiding part of that which is currently displaying in the terminal.
233
- #
234
- # @note
235
- # This may be rarely used, since the action of showing a group using
236
- # `Vedeu.trigger(:_show_group_, group_name)` will effectively clear the
237
- # terminal and show the new group.}
238
- Vedeu.bind(:_hide_group_) { |name| Vedeu.trigger(:_clear_group_, name) }
239
-
240
- # @see Vedeu::Buffer#hide
241
- Vedeu.bind(:_hide_interface_) { |name| Vedeu.buffers.by_name(name).hide }
242
-
243
- # Show the cursor of the named interface or interface currently in focus.
244
- Vedeu.bind(:_show_cursor_) do |name|
245
- Vedeu::Visibility.for_cursor(name).show
246
- end
247
- Vedeu.bind(:_cursor_show_) { |name| Vedeu.trigger(:_show_cursor_, name) }
248
-
249
- # Will clear the terminal and then show all of the interfaces belonging to
250
- # the named group.
251
- Vedeu.bind(:_show_group_) do |name|
252
- Vedeu.trigger(:_clear_)
253
- Vedeu.trigger(:_refresh_group_, name)
254
- end
255
-
256
- # @see Vedeu::Buffer#show
257
- Vedeu.bind(:_show_interface_) { |name| Vedeu.buffers.by_name(name).show }
258
-
259
- # @see Vedeu::Buffer#toggle
260
- Vedeu.bind(:_toggle_interface_) do |name|
261
- Vedeu.buffers.by_name(name).toggle
262
- end
263
-
264
- # @see Vedeu::Geometry#maximise
265
- Vedeu.bind(:_maximise_) { |name| Vedeu.geometries.by_name(name).maximise }
266
-
267
- # @see Vedeu::Geometry#unmaximise
268
- Vedeu.bind(:_unmaximise_) do |name|
269
- Vedeu.geometries.by_name(name).unmaximise
270
- end
271
-
272
- end # Bindings
273
- # :nocov:
274
-
275
- end # Vedeu