vedeu 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/api.rb +3 -1
  3. data/lib/vedeu/application.rb +1 -1
  4. data/lib/vedeu/bindings.rb +68 -101
  5. data/lib/vedeu/cursor/cursor.rb +1 -1
  6. data/lib/vedeu/cursor/move_cursor.rb +77 -1
  7. data/lib/vedeu/cursor/toggle_cursor.rb +2 -0
  8. data/lib/vedeu/distributed/all.rb +7 -0
  9. data/lib/vedeu/distributed/client.rb +23 -11
  10. data/lib/vedeu/distributed/server.rb +8 -0
  11. data/lib/vedeu/distributed/subprocess.rb +0 -24
  12. data/lib/vedeu/distributed/uri.rb +1 -8
  13. data/lib/vedeu/dsl/all.rb +3 -0
  14. data/lib/vedeu/dsl/components/all.rb +4 -4
  15. data/lib/vedeu/dsl/components/geometry.rb +2 -0
  16. data/lib/vedeu/dsl/components/keymap.rb +14 -3
  17. data/lib/vedeu/dsl/group.rb +69 -0
  18. data/lib/vedeu/dsl/interface.rb +9 -8
  19. data/lib/vedeu/dsl/shared/text.rb +3 -1
  20. data/lib/vedeu/events/event.rb +2 -2
  21. data/lib/vedeu/input/keymap.rb +1 -1
  22. data/lib/vedeu/models/geometry.rb +1 -1
  23. data/lib/vedeu/models/group.rb +24 -10
  24. data/lib/vedeu/models/view/lines.rb +1 -0
  25. data/lib/vedeu/output/all.rb +6 -1
  26. data/lib/vedeu/output/border.rb +1 -1
  27. data/lib/vedeu/{support → output}/esc.rb +0 -0
  28. data/lib/vedeu/output/foreground.rb +1 -1
  29. data/lib/vedeu/output/html_char.rb +2 -0
  30. data/lib/vedeu/output/html_renderer.rb +6 -0
  31. data/lib/vedeu/output/output.rb +21 -0
  32. data/lib/vedeu/{support → output}/refresh.rb +1 -1
  33. data/lib/vedeu/output/renderer.rb +3 -0
  34. data/lib/vedeu/{support → output}/text.rb +0 -0
  35. data/lib/vedeu/output/virtual_terminal.rb +2 -0
  36. data/lib/vedeu/support/all.rb +0 -7
  37. data/lib/vedeu/support/coercions.rb +7 -4
  38. data/lib/vedeu/support/terminal.rb +1 -1
  39. data/lib/vedeu/support/trace.rb +1 -1
  40. data/lib/vedeu/support/visible.rb +1 -1
  41. data/test/lib/vedeu/cursor/move_cursor_test.rb +60 -1
  42. data/test/lib/vedeu/distributed/client_test.rb +21 -2
  43. data/test/lib/vedeu/dsl/group_test.rb +52 -0
  44. data/test/lib/vedeu/models/group_test.rb +11 -4
  45. data/test/lib/vedeu/{support → output}/esc_test.rb +0 -0
  46. data/test/lib/vedeu/{support → output}/refresh_test.rb +0 -0
  47. data/test/lib/vedeu/{support → output}/text_test.rb +0 -0
  48. data/test/test_helper.rb +2 -0
  49. data/vedeu.gemspec +2 -1
  50. metadata +28 -24
  51. data/lib/vedeu/output/writer.rb +0 -44
  52. data/lib/vedeu/support/console.rb +0 -90
  53. data/lib/vedeu/support/node.rb +0 -51
  54. data/lib/vedeu/support/read.rb +0 -66
  55. data/lib/vedeu/support/write.rb +0 -86
  56. data/test/lib/vedeu/output/writer_test.rb +0 -32
  57. data/test/lib/vedeu/support/console_test.rb +0 -138
  58. data/test/lib/vedeu/support/read_test.rb +0 -86
  59. data/test/lib/vedeu/support/write_test.rb +0 -158
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f37a301576d737c906c07425d431588426023bbe
4
- data.tar.gz: a8ed33815c9a7343b85470d6f88130495e7d93be
3
+ metadata.gz: ce46fbb0f483168f5c1817fc857b4f1134afdc48
4
+ data.tar.gz: fe7eeaa6731a12dc572479b89f88de211cdf0c05
5
5
  SHA512:
6
- metadata.gz: 1b2a87c244d2b5e3e2bd6d39f8eb6f72184065794e9897fa5bd39c0af08b2ac9add00ed93538d5685f9188c450994fa2b60d96f95ff7564cdf8dad8693a9edcf
7
- data.tar.gz: 680a31c67bb5f046b09f52e8709e2ee8fa5a9e5f4cc63fc387d67608cab30ba364419c1beb0db343f753af216b34593934326e3549c9da6899718d0b07777fe9
6
+ metadata.gz: d996c0a1dc1ddb48cc050343ac91ee2d8ecba8035d833796d4a1fb0c07cc5cce75c265a12bd8b3c6c22de2e3b477805b602e20dcb8e4cc98112bf7e5cf31731c
7
+ data.tar.gz: 0d42cd88c6680854c1cd322762182d90f0dff970230db9064f709b382c36089a1c01cd406e24a74b9db6262055723eb37bd0cff64d06b4e5fe72cc923f39b23d
data/lib/vedeu/api.rb CHANGED
@@ -3,9 +3,10 @@ require 'vedeu/support/terminal'
3
3
  require 'vedeu/events/all'
4
4
  require 'vedeu/models/all'
5
5
  require 'vedeu/input/all'
6
- require 'vedeu/dsl/components/border'
6
+ require 'vedeu/dsl/components/all'
7
7
  require 'vedeu/dsl/composition'
8
8
  require 'vedeu/dsl/shared/all'
9
+ require 'vedeu/dsl/group'
9
10
  require 'vedeu/dsl/view'
10
11
 
11
12
  module Vedeu
@@ -38,6 +39,7 @@ module Vedeu
38
39
  def_delegators Vedeu::DSL::Border, :border
39
40
  def_delegators Vedeu::DSL::Geometry, :geometry
40
41
  def_delegators Vedeu::DSL::Keymap, :keymap
42
+ def_delegators Vedeu::DSL::Group, :group
41
43
  def_delegators Vedeu::DSL::Use, :use
42
44
  def_delegators Vedeu::DSL::View, :interface, :renders, :views
43
45
 
@@ -59,7 +59,7 @@ module Vedeu
59
59
  runner { main_sequence }
60
60
  end
61
61
 
62
- Vedeu.trigger(:_drb_stop_, 'via Vedeu::Application#start')
62
+ Vedeu.trigger(:_drb_stop_)
63
63
 
64
64
  output
65
65
  end
@@ -14,18 +14,11 @@ module Vedeu
14
14
  #
15
15
  module Bindings
16
16
 
17
- # Clears the whole terminal space.
18
- Vedeu.bind(:_clear_) do
19
- Vedeu::Terminal.virtual.clear if Vedeu::Configuration.drb?
20
-
21
- Vedeu::Terminal.clear
22
- end
23
-
24
17
  # Vedeu triggers this event when `:_exit_` is triggered. You can hook into
25
18
  # this to perform a special action before the application terminates. Saving
26
19
  # the user's work, session or preferences might be popular here.
27
20
  Vedeu.bind(:_cleanup_) do
28
- Vedeu.trigger(:_drb_stop_, 'via :cleanup')
21
+ Vedeu.trigger(:_drb_stop_)
29
22
  Vedeu.trigger(:cleanup)
30
23
  end
31
24
 
@@ -34,51 +27,40 @@ module Vedeu
34
27
  Vedeu.trigger(:_keypress_, data)
35
28
  end
36
29
 
37
- Vedeu.bind(:_drb_retrieve_output_) do
30
+ Vedeu.bind(:_drb_retrieve_output_) do
38
31
  Vedeu.log(type: :drb, message: 'Retrieving output')
39
32
  Vedeu::VirtualBuffer.retrieve
40
33
  end
41
34
 
42
- Vedeu.bind(:_drb_store_output_) do |data|
35
+ Vedeu.bind(:_drb_store_output_) do |data|
43
36
  Vedeu.log(type: :drb, message: 'Storing output')
44
37
  Vedeu::VirtualBuffer.store(Vedeu::Terminal.virtual.output(data))
45
38
  end
46
39
 
47
- Vedeu.bind(:_drb_restart_) do
48
- Vedeu.log(type: :drb, message: 'Attempting to restart')
49
- Vedeu::Distributed::Server.restart
50
- end
51
-
52
- Vedeu.bind(:_drb_start_) do
53
- Vedeu.log(type: :drb, message: 'Attempting to start')
54
- Vedeu::Distributed::Server.start
55
- end
56
-
57
- Vedeu.bind(:_drb_status_) do
58
- Vedeu.log(type: :drb, message: 'Fetching status')
59
- Vedeu::Distributed::Server.status
60
- end
61
-
62
- Vedeu.bind(:_drb_stop_) do |message|
63
- Vedeu.log(type: :drb, message: "Attempting to stop (#{message})")
64
- Vedeu::Distributed::Server.stop
65
- end
40
+ Vedeu.bind(:_drb_restart_) { Vedeu::Distributed::Server.restart }
41
+ Vedeu.bind(:_drb_start_) { Vedeu::Distributed::Server.start }
42
+ Vedeu.bind(:_drb_status_) { Vedeu::Distributed::Server.status }
43
+ Vedeu.bind(:_drb_stop_) { Vedeu::Distributed::Server.stop }
66
44
 
67
45
  # When triggered, Vedeu will trigger a `:cleanup` event which you can define
68
46
  # (to save files, etc) and attempt to exit.
69
- Vedeu.bind(:_exit_) { Vedeu::Application.stop }
47
+ Vedeu.bind(:_exit_) { Vedeu::Application.stop }
70
48
 
71
49
  # Vedeu triggers this event when it is ready to enter the main loop. Client
72
50
  # applications can listen for this event and perform some action(s), like
73
51
  # render the first screen, interface or make a sound. When Vedeu triggers
74
52
  # this event, the :_refresh_ event is also triggered automatically.
75
- Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
53
+ Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
76
54
 
77
- # Triggering this event will cause the triggering of the `:key` event; which
55
+ # Will cause the triggering of the `:key` event; which
78
56
  # you should define to 'do things'. If the `escape` key is pressed, then
79
57
  # `key` is triggered with the argument `:escape`, also an internal event
80
58
  # `_mode_switch_` is triggered.
81
- Vedeu.bind(:_keypress_) { |key| Vedeu.keypress(key) }
59
+ Vedeu.bind(:_keypress_) do |key|
60
+ Vedeu.trigger(:key, key)
61
+
62
+ Vedeu.keypress(key)
63
+ end
82
64
 
83
65
  # When triggered with a message will cause Vedeu to log the message if
84
66
  # logging is enabled in the configuration.
@@ -96,79 +78,35 @@ module Vedeu
96
78
 
97
79
  # Hide the cursor of the named interface or interface currently in focus.
98
80
  Vedeu.bind(:_cursor_hide_) do |name|
99
- named = if name
100
- Vedeu.cursors.by_name(name)
101
-
102
- else
103
- Vedeu.cursor
104
-
105
- end
81
+ named = name ? Vedeu.cursors.by_name(name) : Vedeu.cursor
106
82
 
107
83
  ToggleCursor.hide(named)
108
84
  end
109
85
 
110
86
  # Show the cursor of the named interface or interface currently in focus.
111
87
  Vedeu.bind(:_cursor_show_) do |name|
112
- named = if name
113
- Vedeu.cursors.by_name(name)
114
-
115
- else
116
- Vedeu.cursor
117
-
118
- end
88
+ named = name ? Vedeu.cursors.by_name(name) : Vedeu.cursor
119
89
 
120
90
  ToggleCursor.show(named)
121
91
  end
122
92
 
123
- # Move the cursor down one character in the interface currently in focus.
124
- # Will not exceed the border or boundary of the interface.
125
- Vedeu.bind(:_cursor_down_) do
126
- interface = Vedeu.interfaces.current
93
+ # @see {Vedeu::MoveCursor}
94
+ Vedeu.bind(:_cursor_down_) { |name| MoveCursor.by_name(:down, name) }
127
95
 
128
- MoveCursor.down(Vedeu.cursor, interface)
96
+ # @see {Vedeu::MoveCursor}
97
+ Vedeu.bind(:_cursor_left_) { |name| MoveCursor.by_name(:left, name) }
129
98
 
130
- Refresh.by_focus
131
- end
99
+ # @see {Vedeu::MoveCursor}
100
+ Vedeu.bind(:_cursor_right_) { |name| MoveCursor.by_name(:right, name) }
132
101
 
133
- # Move the cursor left one character in the interface currently in focus.
134
- # Will not exceed the border or boundary of the interface.
135
- Vedeu.bind(:_cursor_left_) do
136
- interface = Vedeu.interfaces.current
102
+ # @see {Vedeu::MoveCursor}
103
+ Vedeu.bind(:_cursor_up_) { |name| MoveCursor.by_name(:up, name) }
137
104
 
138
- MoveCursor.left(Vedeu.cursor, interface)
139
-
140
- Refresh.by_focus
141
- end
105
+ # @see {Vedeu::MoveCursor}
106
+ Vedeu.bind(:_cursor_origin_) { |name| MoveCursor.by_name(:origin, name) }
142
107
 
143
- # Move the cursor right one character in the interface currently in focus.
144
- # Will not exceed the border or boundary of the interface.
145
- Vedeu.bind(:_cursor_right_) do
146
- interface = Vedeu.interfaces.current
147
-
148
- MoveCursor.right(Vedeu.cursor, interface)
149
-
150
- Refresh.by_focus
151
- end
152
-
153
- # Move the cursor up one character in the interface currently in focus.
154
- # Will not exceed the border or boundary of the interface.
155
- Vedeu.bind(:_cursor_up_) do
156
- interface = Vedeu.interfaces.current
157
-
158
- MoveCursor.up(Vedeu.cursor, interface)
159
-
160
- Refresh.by_focus
161
- end
162
-
163
- # Moves the cursor to the top left position of the interface currently in
164
- # focus; respecting a border if present.
165
- Vedeu.bind(:_cursor_origin_) do
166
- interface = Vedeu.interfaces.current
167
-
168
- MoveCursor.origin(Vedeu.cursor, interface)
169
-
170
- Refresh.by_focus
171
- end
108
+ # @see {Vedeu::MoveCursor}
109
+ Vedeu.bind(:_cursor_reset_) { |name| Vedeu.trigger(:_cursor_origin_, name) }
172
110
 
173
111
  # When triggered with an interface name will focus that interface and
174
112
  # restore the cursor position and visibility.
@@ -219,22 +157,51 @@ module Vedeu
219
157
  # starting at the current item to the last item.
220
158
  Vedeu.bind(:_menu_view_) { |name| Vedeu.menus.find(name).view }
221
159
 
222
- # Triggering this event will cause all interfaces to refresh, or the named
223
- # interface if one is given.
224
- Vedeu.bind(:_refresh_) do |name|
225
- if name
226
- Vedeu::Refresh.by_name(name)
160
+ # Clears the whole terminal space, or the named interface area to be cleared
161
+ # if given.
162
+ Vedeu.bind(:_clear_) do |name|
163
+ if name && Vedeu.interfaces.registered?(name)
164
+ Vedeu::Output.clear(Vedeu.interfaces.find(name))
227
165
 
228
166
  else
229
- Vedeu::Refresh.all
167
+ Vedeu::Terminal.virtual.clear if Vedeu::Configuration.drb?
168
+
169
+ Vedeu::Terminal.clear
170
+ end
171
+ end
230
172
 
173
+ # Clears the spaces occupied by the interfaces belonging to the named group.
174
+ Vedeu.bind(:_clear_group_) do |name|
175
+ Vedeu.groups.find(name).members.each do |group_name|
176
+ Vedeu.trigger(:_clear_, group_name)
231
177
  end
232
178
  end
233
179
 
234
- # Triggering this event will cause all interfaces in the named group to
235
- # refresh.
236
- Vedeu.bind(:_refresh_group_) do |name|
237
- Vedeu::Refresh.by_group(name)
180
+ # Will cause all interfaces to refresh, or the named interface if given.
181
+ Vedeu.bind(:_refresh_) do |name|
182
+ name ? Vedeu::Refresh.by_name(name) : Vedeu::Refresh.all
183
+ end
184
+
185
+ # Will cause all interfaces in the named group to refresh.
186
+ Vedeu.bind(:_refresh_group_) { |name| Vedeu::Refresh.by_group(name) }
187
+
188
+ # Will clear the terminal and then show all of the interfaces belonging to
189
+ # the named group.
190
+ Vedeu.bind(:_show_group_) do |name|
191
+ Vedeu.trigger(:_clear_)
192
+
193
+ Vedeu.trigger(:_refresh_group_, name)
194
+ end
195
+
196
+ # Will hide all of the interfaces belonging to the named group. Useful for
197
+ # hiding part of that which is currently displaying in the terminal.
198
+ #
199
+ # @note
200
+ # This may be rarely used, since the action of showing a group using
201
+ # `Vedeu.trigger(:_show_group_, group_name)` will effectively clear the
202
+ # terminal and show the new group.
203
+ Vedeu.bind(:_hide_group_) do |name|
204
+ Vedeu.trigger(:_clear_group_, name)
238
205
  end
239
206
 
240
207
  end # Bindings
@@ -18,7 +18,7 @@ module Vedeu
18
18
 
19
19
  attr_reader :attributes, :name, :ox, :oy, :state, :x, :y
20
20
 
21
- # Provides a new instance of Cursor.
21
+ # Returns a new instance of Cursor.
22
22
  #
23
23
  # @param attributes [Hash]
24
24
  # @option attributes name [String] The name of the interface this cursor
@@ -4,7 +4,34 @@ require 'vedeu/geometry/position_validator'
4
4
 
5
5
  module Vedeu
6
6
 
7
- # Adjusts the position of the cursor.
7
+ # Adjusts the position of the cursor. To use this class, call the appropriate
8
+ # event:
9
+ #
10
+ # @example
11
+ # Vedeu.trigger(:_cursor_down_)
12
+ #
13
+ # Vedeu.trigger(:_cursor_left_) # When a name is not given, the cursor in
14
+ # # the interface which is currently in focus
15
+ # # should move to the left.
16
+ #
17
+ # Vedeu.trigger(:_cursor_left_, 'my_interface')
18
+ # # When a name is given, the cursor instance
19
+ # # belonging to this interface moves to the
20
+ # # left.
21
+ #
22
+ # Vedeu.trigger(:_cursor_right_)
23
+ # Vedeu.trigger(:_cursor_up_)
24
+ #
25
+ # Vedeu.trigger(:_cursor_origin_) # /or/
26
+ # Vedeu.trigger(:_cursor_origin_, 'my_interface')
27
+ # # Moves the cursor to the top left of the
28
+ # # named or current interface in focus.
29
+ #
30
+ # @note
31
+ # The cursor may not be visible, but it will still move if requested.
32
+ # The cursor will not exceed the border or boundary of the interface.
33
+ # The cursor will move freely within the bounds of the interface,
34
+ # irrespective of content.
8
35
  #
9
36
  class MoveCursor
10
37
 
@@ -19,6 +46,8 @@ module Vedeu
19
46
  :height,
20
47
  :width
21
48
 
49
+ # Returns an instance of MoveCursor.
50
+ #
22
51
  # @param cursor [Cursor]
23
52
  # @param interface [Interface]
24
53
  # @param dy [Fixnum] Move up (-1), or down (1), or no action (0).
@@ -31,8 +60,37 @@ module Vedeu
31
60
  @interface = interface
32
61
  end
33
62
 
63
+ # Move the named cursor, or that which is currently in focus in the
64
+ # specified direction.
65
+ #
66
+ # @param direction [Symbol] The direction of travel. Directions include:
67
+ # (:down, :left, :right, :up, :origin). When ':origin' the cursor is moved
68
+ # to the top left of the interface.
69
+ # @param name [String|NilClass] The name of the interface/cursor to be
70
+ # moved; when not given, the interface currently in focus determines which
71
+ # cursor instance to move.
72
+ # @return [Cursor]
73
+ def self.by_name(direction, name = nil)
74
+ if name
75
+ cursor = Vedeu.cursors.by_name(name)
76
+ interface = Vedeu.interfaces.find(name)
77
+ new_cursor = MoveCursor.send(direction, cursor, interface)
78
+ Refresh.by_name(name)
79
+
80
+ else
81
+ cursor = Vedeu.cursor
82
+ interface = Vedeu.interfaces.current
83
+ new_cursor = MoveCursor.send(direction, cursor, interface)
84
+ Refresh.by_focus
85
+
86
+ end
87
+ new_cursor
88
+ end
89
+
34
90
  # Moves the cursor down by one row.
35
91
  #
92
+ # @param cursor [Cursor]
93
+ # @param interface [Interface]
36
94
  # @return [Cursor]
37
95
  def self.down(cursor, interface)
38
96
  new(cursor, interface, 1, 0).move
@@ -40,6 +98,8 @@ module Vedeu
40
98
 
41
99
  # Moves the cursor left by one column.
42
100
  #
101
+ # @param cursor [Cursor]
102
+ # @param interface [Interface]
43
103
  # @return [Cursor]
44
104
  def self.left(cursor, interface)
45
105
  return cursor unless cursor.ox > 0
@@ -49,6 +109,8 @@ module Vedeu
49
109
 
50
110
  # Moves the cursor right by one column.
51
111
  #
112
+ # @param cursor [Cursor]
113
+ # @param interface [Interface]
52
114
  # @return [Cursor]
53
115
  def self.right(cursor, interface)
54
116
  new(cursor, interface, 0, 1).move
@@ -56,6 +118,8 @@ module Vedeu
56
118
 
57
119
  # Moves the cursor up by one row.
58
120
  #
121
+ # @param cursor [Cursor]
122
+ # @param interface [Interface]
59
123
  # @return [Cursor]
60
124
  def self.up(cursor, interface)
61
125
  return cursor unless cursor.oy > 0
@@ -65,6 +129,8 @@ module Vedeu
65
129
 
66
130
  # Moves the cursor to the top left coordinate of the interface.
67
131
  #
132
+ # @param cursor [Cursor]
133
+ # @param interface [Interface]
68
134
  # @return [Cursor]
69
135
  def self.origin(cursor, interface)
70
136
  new(cursor, interface, (0 - cursor.y), (0 - cursor.x)).move
@@ -98,6 +164,9 @@ module Vedeu
98
164
  coordinate.y_position(oy))
99
165
  end
100
166
 
167
+ # Apply the direction amount to the cursor offset. If the offset is less
168
+ # than 0, correct to 0.
169
+ #
101
170
  # @return [Fixnum]
102
171
  def ox
103
172
  ox = cursor.ox + dx
@@ -105,6 +174,9 @@ module Vedeu
105
174
  ox
106
175
  end
107
176
 
177
+ # Apply the direction amount to the cursor offset. If the offset is less
178
+ # than 0, correct to 0.
179
+ #
108
180
  # @return [Fixnum]
109
181
  def oy
110
182
  oy = cursor.oy + dy
@@ -120,6 +192,8 @@ module Vedeu
120
192
  top)
121
193
  end
122
194
 
195
+ # Return the height of the interface, minus any borders.
196
+ #
123
197
  # @return [Fixnum]
124
198
  def bordered_height
125
199
  return border.height if border?
@@ -127,6 +201,8 @@ module Vedeu
127
201
  height
128
202
  end
129
203
 
204
+ # Return the width of the interface, minus any borders.
205
+ #
130
206
  # @return [Fixnum]
131
207
  def bordered_width
132
208
  return border.width if border?
@@ -4,6 +4,8 @@ module Vedeu
4
4
  #
5
5
  class ToggleCursor
6
6
 
7
+ # Returns an instance of ToggleCursor.
8
+ #
7
9
  # @param cursor [Cursor]
8
10
  # @return [ToggleCursor]
9
11
  def initialize(cursor)