vedeu 0.1.19 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/api.md +9 -5
- data/docs/events.md +64 -17
- data/lib/vedeu.rb +5 -0
- data/lib/vedeu/api/api.rb +36 -12
- data/lib/vedeu/api/menu.rb +111 -0
- data/lib/vedeu/launcher.rb +1 -0
- data/lib/vedeu/models/attributes/colour_translator.rb +1 -0
- data/lib/vedeu/models/colour.rb +1 -0
- data/lib/vedeu/models/composition.rb +1 -0
- data/lib/vedeu/models/geometry.rb +11 -1
- data/lib/vedeu/output/clear.rb +1 -0
- data/lib/vedeu/output/compositor.rb +1 -0
- data/lib/vedeu/output/render.rb +1 -0
- data/lib/vedeu/repositories/events.rb +10 -1
- data/lib/vedeu/repositories/interfaces.rb +3 -1
- data/lib/vedeu/repositories/menus.rb +111 -0
- data/lib/vedeu/support/cursor.rb +17 -1
- data/lib/vedeu/support/event.rb +10 -1
- data/lib/vedeu/support/grid.rb +1 -0
- data/lib/vedeu/support/menu.rb +11 -22
- data/test/lib/vedeu/api/api_test.rb +28 -12
- data/test/lib/vedeu/api/defined_test.rb +4 -4
- data/test/lib/vedeu/api/menu_test.rb +68 -0
- data/test/lib/vedeu/repositories/groups_test.rb +37 -19
- data/test/lib/vedeu/repositories/interfaces_test.rb +79 -0
- data/test/lib/vedeu/repositories/menus_test.rb +244 -0
- data/test/lib/vedeu/support/menu_test.rb +0 -6
- data/test/test_helper.rb +0 -29
- data/vedeu.gemspec +3 -3
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa08f6802848478327fb38d44b28b19ffbb78d75
|
4
|
+
data.tar.gz: 8e30625c919e7d3c678c7301c707904e5ac70328
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50aaa91ab6b23ce968ab31fa9100959c8a05f21d9accffd2f3444a53474fa16c6b30527aa4aca79e4ce35fd5dece0799ed101b6e5c9ad171bddc44734ad94bb7
|
7
|
+
data.tar.gz: 7dafc1f4a3f8fa836e05f665ef005c30550632bce5e92eb1ba69abe435e48b159b94268448c7465392816692e625e48f5b129bb573eedc86564eeef64c58af07
|
data/docs/api.md
CHANGED
@@ -14,7 +14,7 @@ Doing it this way will mean you can use any API method without the `Vedeu.` pref
|
|
14
14
|
```ruby
|
15
15
|
class SomeClassInYourApplication
|
16
16
|
include Vedeu
|
17
|
-
|
17
|
+
|
18
18
|
...
|
19
19
|
```
|
20
20
|
|
@@ -26,11 +26,11 @@ Doing it this way means you need to use the `Vedeu.` prefix.
|
|
26
26
|
```ruby
|
27
27
|
class OtherClassInYourApplication
|
28
28
|
...
|
29
|
-
|
29
|
+
|
30
30
|
def some_method
|
31
|
-
Vedeu.some_api_method
|
31
|
+
Vedeu.some_api_method
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
...
|
35
35
|
```
|
36
36
|
|
@@ -46,6 +46,7 @@ height
|
|
46
46
|
interface
|
47
47
|
keypress
|
48
48
|
log
|
49
|
+
menu
|
49
50
|
resize
|
50
51
|
trigger
|
51
52
|
unevent
|
@@ -69,6 +70,9 @@ width
|
|
69
70
|
height
|
70
71
|
centred
|
71
72
|
|
73
|
+
items
|
74
|
+
name
|
75
|
+
|
72
76
|
stream
|
73
77
|
text
|
74
78
|
foreground
|
@@ -76,4 +80,4 @@ background
|
|
76
80
|
|
77
81
|
align
|
78
82
|
text
|
79
|
-
width
|
83
|
+
width
|
data/docs/events.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
## Vedeu Events
|
2
2
|
|
3
3
|
Vedeu provides an event mechanism to facilitate the functionality of your
|
4
|
-
application. The events are either Vedeu defined, ie. system events or
|
4
|
+
application. The events are either Vedeu defined, ie. system events or
|
5
5
|
user defined, ie. user events.
|
6
6
|
|
7
7
|
Events described in this document assume that you have included Vedeu in your
|
@@ -14,64 +14,111 @@ class:
|
|
14
14
|
...
|
15
15
|
```
|
16
16
|
|
17
|
-
|
17
|
+
## System Events
|
18
18
|
|
19
19
|
System events generally control the internal state of Vedeu with respects to
|
20
20
|
your application. They are soft-namespaced using underscores.
|
21
21
|
|
22
|
-
|
22
|
+
### `:_cleanup_`
|
23
23
|
|
24
24
|
This event is fired by Vedeu when `:_exit_` is triggered. You can hook into this to perform a special action before the application terminates. Saving the user's work, session or preferences might be popular here.
|
25
25
|
|
26
|
-
|
26
|
+
### `:_clear_`
|
27
27
|
|
28
28
|
Clears the whole terminal space.
|
29
29
|
|
30
|
-
|
30
|
+
### `:_exit_`
|
31
31
|
|
32
32
|
When triggered, Vedeu will trigger a `:_cleanup_` event which you can define (to save files, etc) and attempt to exit.
|
33
33
|
|
34
|
-
|
34
|
+
### `:_focus_by_name_`
|
35
35
|
|
36
36
|
When triggered with an interface name will focus that interface.
|
37
37
|
|
38
|
-
|
38
|
+
### `:_focus_next_`
|
39
39
|
|
40
|
-
When triggered will focus the next interface.
|
40
|
+
When triggered will focus the next interface.
|
41
41
|
|
42
|
-
|
42
|
+
### `:_focus_prev_`
|
43
43
|
|
44
44
|
When triggered will focus the previous interface.
|
45
45
|
|
46
|
-
|
46
|
+
### `:_initialize_`
|
47
47
|
|
48
48
|
Special event which Vedeu triggers when it is ready to enter the main loop. Client applications can listen for this event and perform some action(s), like render the first screen, interface or make a sound.
|
49
49
|
|
50
|
-
|
50
|
+
### `:_keypress_`
|
51
51
|
|
52
52
|
Triggering this event will cause the triggering of the `:key` event; which you should define to 'do things'. If the `escape` key is pressed, then `key` is triggered with the argument `:escape`, also an internal event `_mode_switch_` is triggered.
|
53
53
|
|
54
|
-
|
54
|
+
### `:_log_`
|
55
55
|
|
56
56
|
When triggered with a message will cause Vedeu to log the message if logging is enabled in the configuration.
|
57
57
|
|
58
|
-
|
58
|
+
### `:_menu_current_`
|
59
|
+
|
60
|
+
Requires target menu name as argument. Returns the current menu item.
|
61
|
+
|
62
|
+
### `:_menu_selected_`
|
63
|
+
|
64
|
+
Requires target menu name as argument. Returns the selected menu item.
|
65
|
+
|
66
|
+
### `:_menu_next_`
|
67
|
+
|
68
|
+
Requires target menu name as argument. Makes the next menu item the current menu
|
69
|
+
item, until it reaches the last item.
|
70
|
+
|
71
|
+
### `:_menu_prev_`
|
72
|
+
|
73
|
+
Requires target menu name as argument. Makes the previous menu item the current
|
74
|
+
menu item, until it reaches the first item.
|
75
|
+
|
76
|
+
### `:_menu_top_`
|
77
|
+
|
78
|
+
Requires target menu name as argument. Makes the first menu item the current
|
79
|
+
menu item.
|
80
|
+
|
81
|
+
### `:_menu_bottom_`
|
82
|
+
|
83
|
+
Requires target menu name as argument. Makes the last menu item the current menu
|
84
|
+
item.
|
85
|
+
|
86
|
+
### `:_menu_select_`
|
87
|
+
|
88
|
+
Requires target menu name as argument. Makes the current menu item also the
|
89
|
+
selected menu item.
|
90
|
+
|
91
|
+
### `:_menu_deselect_`
|
92
|
+
|
93
|
+
Requires target menu name as argument. Deselects all menu items.
|
94
|
+
|
95
|
+
### `:_menu_items_`
|
96
|
+
|
97
|
+
Requires target menu name as argument. Returns all the menu items with
|
98
|
+
respective `current` or `selected` boolean indicators.
|
99
|
+
|
100
|
+
### `:_menu_view_`
|
101
|
+
|
102
|
+
Requires target menu name as argument. Returns a subset of the menu items;
|
103
|
+
starting at the current item to the last item.
|
104
|
+
|
105
|
+
### `:_mode_switch_`
|
59
106
|
|
60
107
|
When triggered (after the user presses `escape`), Vedeu switches from a "raw mode" terminal to a "cooked mode" terminal. The idea here being that the raw mode is for single keypress actions, whilst cooked mode allows the user to enter more elaborate commands- such as commands with arguments.
|
61
108
|
|
62
|
-
|
109
|
+
### `:_refresh_`
|
63
110
|
|
64
111
|
Triggering this event will cause all interfaces to refresh.
|
65
112
|
|
66
|
-
|
113
|
+
### `:_refresh_group_(group_name)_`
|
67
114
|
|
68
115
|
Will refresh all interfaces belonging to this group. E.g. `_refresh_group_home_` will refresh all interfaces with the group of `home`.
|
69
116
|
|
70
|
-
|
117
|
+
### `:_refresh_(interface_name)_`
|
71
118
|
|
72
119
|
Will refresh the interface with this name. E.g. `_refresh_widget_` will refresh the interface `widget`.
|
73
120
|
|
74
|
-
|
121
|
+
### `:_resize_`
|
75
122
|
|
76
123
|
When triggered will cause Vedeu to trigger the `:_clear_` and `:_refresh_`
|
77
124
|
events. Please see those events for their behaviour.
|
data/lib/vedeu.rb
CHANGED
@@ -19,6 +19,9 @@ module Vedeu
|
|
19
19
|
# encounters a problem.
|
20
20
|
InvalidSyntax = Class.new(StandardError)
|
21
21
|
|
22
|
+
# Raised when a menu cannot be found by name.
|
23
|
+
MenuNotFound = Class.new(StandardError)
|
24
|
+
|
22
25
|
# Raised intentionally when the client application wishes to switch between
|
23
26
|
# cooked and raw (or vice versa) terminal modes. Vedeu is hard-wired to use
|
24
27
|
# the `Escape` key to trigger this change for the time being.
|
@@ -90,8 +93,10 @@ require 'vedeu/api/composition'
|
|
90
93
|
require 'vedeu/api/helpers'
|
91
94
|
require 'vedeu/api/interface'
|
92
95
|
require 'vedeu/api/line'
|
96
|
+
require 'vedeu/api/menu'
|
93
97
|
require 'vedeu/api/stream'
|
94
98
|
|
99
|
+
require 'vedeu/repositories/menus'
|
95
100
|
require 'vedeu/repositories/interfaces'
|
96
101
|
require 'vedeu/repositories/groups'
|
97
102
|
require 'vedeu/repositories/focus'
|
data/lib/vedeu/api/api.rb
CHANGED
@@ -158,6 +158,29 @@ module Vedeu
|
|
158
158
|
Vedeu::Log.logger.debug(message) if Configuration.debug? || force
|
159
159
|
end
|
160
160
|
|
161
|
+
# Register a menu by name which will display output from a event or
|
162
|
+
# command. This provides the means for you to define your application's
|
163
|
+
# views without their content.
|
164
|
+
#
|
165
|
+
# @api public
|
166
|
+
# @param name [String] The name of the menu. Used to reference the
|
167
|
+
# menu throughout your application's execution lifetime.
|
168
|
+
# @param block [Proc] A set of attributes which define the features of the
|
169
|
+
# menu. TODO: More help.
|
170
|
+
#
|
171
|
+
# @example
|
172
|
+
# Vedeu.menu 'my_interface' do
|
173
|
+
# ...
|
174
|
+
#
|
175
|
+
# Vedeu.menu do
|
176
|
+
# name 'menus_must_have_a_name'
|
177
|
+
# ...
|
178
|
+
#
|
179
|
+
# @return [API::Menu]
|
180
|
+
def menu(name = '', &block)
|
181
|
+
API::Menu.define({ name: name }, &block)
|
182
|
+
end
|
183
|
+
|
161
184
|
# When the terminal emit the 'SIGWINCH' signal, Vedeu can intercept this
|
162
185
|
# and attempt to redraw the current interface with varying degrees of
|
163
186
|
# success. Can also be used to simulate a terminal resize.
|
@@ -172,7 +195,8 @@ module Vedeu
|
|
172
195
|
end
|
173
196
|
# :nocov:
|
174
197
|
|
175
|
-
# Trigger a registered or system event by name with arguments.
|
198
|
+
# Trigger a registered or system event by name with arguments. If the
|
199
|
+
# event stored returns a value, that is returned.
|
176
200
|
#
|
177
201
|
# @api public
|
178
202
|
# @param name [Symbol] The name of the event you wish to trigger.
|
@@ -182,11 +206,21 @@ module Vedeu
|
|
182
206
|
# @example
|
183
207
|
# Vedeu.trigger(:my_event, :oxidize, 'nitrogen')
|
184
208
|
#
|
185
|
-
# @return [Array]
|
209
|
+
# @return [Array|undefined]
|
186
210
|
def trigger(name, *args)
|
187
211
|
Vedeu.events.trigger(name, *args)
|
188
212
|
end
|
189
213
|
|
214
|
+
# Unregisters the event by name, effectively deleting the associated events
|
215
|
+
# bound with it also.
|
216
|
+
#
|
217
|
+
# @api public
|
218
|
+
# @param name [Symbol]
|
219
|
+
# @return [Hash]
|
220
|
+
def unevent(name)
|
221
|
+
Vedeu.events.unevent(name)
|
222
|
+
end
|
223
|
+
|
190
224
|
# Use attributes of another interface whilst defining one. TODO: More help.
|
191
225
|
#
|
192
226
|
# @api public
|
@@ -261,16 +295,6 @@ module Vedeu
|
|
261
295
|
Terminal.width
|
262
296
|
end
|
263
297
|
|
264
|
-
# Unregisters the event by name, effectively deleting the associated events
|
265
|
-
# bound with it also.
|
266
|
-
#
|
267
|
-
# @api public
|
268
|
-
# @param name [Symbol]
|
269
|
-
# @return [Hash]
|
270
|
-
def unevent(name)
|
271
|
-
Vedeu.events.unevent(name)
|
272
|
-
end
|
273
|
-
|
274
298
|
end
|
275
299
|
|
276
300
|
extend API
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module Vedeu
|
2
|
+
module API
|
3
|
+
|
4
|
+
# Provides the mechanism to create menus within client applications and use
|
5
|
+
# events to drive them.
|
6
|
+
class Menu
|
7
|
+
|
8
|
+
include Common
|
9
|
+
|
10
|
+
attr_reader :attributes
|
11
|
+
|
12
|
+
# @param attributes [Hash]
|
13
|
+
# @param block [Proc]
|
14
|
+
# @return [API::Menu]
|
15
|
+
def self.define(attributes = {}, &block)
|
16
|
+
new(attributes).define(&block)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Return a new instance of Menu.
|
20
|
+
#
|
21
|
+
# @param attributes [Hash]
|
22
|
+
# @return [API::Menu]
|
23
|
+
def initialize(attributes = {})
|
24
|
+
@attributes = defaults.merge!(attributes)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param block [Proc]
|
28
|
+
# @return [API::Menu]
|
29
|
+
def define(&block)
|
30
|
+
fail InvalidSyntax, '`menu` requires a block.' unless block_given?
|
31
|
+
|
32
|
+
@self_before_instance_eval = eval('self', block.binding)
|
33
|
+
|
34
|
+
instance_eval(&block)
|
35
|
+
|
36
|
+
validate_attributes!
|
37
|
+
|
38
|
+
Vedeu::Menus.add(attributes)
|
39
|
+
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
# Define the items for the menu. Most powerful when used with one of your
|
44
|
+
# model classes.
|
45
|
+
#
|
46
|
+
# In the 'my_playlist' example below, your `Track` model may return a
|
47
|
+
# collection of tracks to populate the menu.
|
48
|
+
#
|
49
|
+
# @api public
|
50
|
+
# @param collection [Array]
|
51
|
+
#
|
52
|
+
# @example
|
53
|
+
# menu 'my_menu' do
|
54
|
+
# items [:item_1, :item_2, :item_3]
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
# menu 'my_playlist' do
|
58
|
+
# items Track.all_my_favourites
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# @return [Vedeu::Menu]
|
62
|
+
def items(collection = [])
|
63
|
+
attributes[:items] = Vedeu::Menu.new(collection)
|
64
|
+
end
|
65
|
+
|
66
|
+
# The name of the menu. Used to reference the menu throughout your
|
67
|
+
# application's execution lifetime.
|
68
|
+
#
|
69
|
+
# @api public
|
70
|
+
# @param value [String]
|
71
|
+
#
|
72
|
+
# @example
|
73
|
+
# menu do
|
74
|
+
# name 'my_menu'
|
75
|
+
# ...
|
76
|
+
#
|
77
|
+
# @return [String]
|
78
|
+
def name(value)
|
79
|
+
attributes[:name] = value
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
# The default values for a new instance of Menu.
|
85
|
+
#
|
86
|
+
# @api private
|
87
|
+
# @return [Hash]
|
88
|
+
def defaults
|
89
|
+
{
|
90
|
+
name: '',
|
91
|
+
items: []
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
# @api private
|
96
|
+
# @return [TrueClass|FalseClass]
|
97
|
+
def validate_attributes!
|
98
|
+
unless defined_value?(attributes[:name])
|
99
|
+
fail InvalidSyntax, 'Menus must have a `name`.'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# @api private
|
104
|
+
# @return []
|
105
|
+
def method_missing(method, *args, &block)
|
106
|
+
@self_before_instance_eval.send(method, *args, &block)
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/vedeu/launcher.rb
CHANGED
data/lib/vedeu/models/colour.rb
CHANGED
@@ -6,7 +6,17 @@ module Vedeu
|
|
6
6
|
# @api private
|
7
7
|
class Geometry
|
8
8
|
|
9
|
-
|
9
|
+
# @return [Hash]
|
10
|
+
attr_reader :attributes
|
11
|
+
|
12
|
+
# @return [TrueClass|FalseClass]
|
13
|
+
attr_reader :centred
|
14
|
+
|
15
|
+
# @return [Fixnum]
|
16
|
+
attr_reader :height
|
17
|
+
|
18
|
+
# @return [Fixnum]
|
19
|
+
attr_reader :width
|
10
20
|
|
11
21
|
# Returns a new instance of Geometry.
|
12
22
|
#
|