vedeu 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -9
  3. data/docs/api.md +70 -42
  4. data/elements.txt +118 -0
  5. data/lib/vedeu.rb +14 -4
  6. data/lib/vedeu/api/api.rb +67 -24
  7. data/lib/vedeu/api/composition.rb +19 -0
  8. data/lib/vedeu/api/defined.rb +7 -0
  9. data/lib/vedeu/api/interface.rb +103 -75
  10. data/lib/vedeu/api/keymap.rb +62 -0
  11. data/lib/vedeu/api/menu.rb +3 -1
  12. data/lib/vedeu/configuration.rb +24 -6
  13. data/lib/vedeu/models/attributes/coercions.rb +18 -26
  14. data/lib/vedeu/models/attributes/colour_translator.rb +7 -7
  15. data/lib/vedeu/models/attributes/presentation.rb +12 -1
  16. data/lib/vedeu/models/geometry.rb +5 -1
  17. data/lib/vedeu/models/interface.rb +6 -47
  18. data/lib/vedeu/models/keymap.rb +66 -0
  19. data/lib/vedeu/models/line.rb +3 -1
  20. data/lib/vedeu/models/stream.rb +10 -1
  21. data/lib/vedeu/models/style.rb +10 -1
  22. data/lib/vedeu/output/compositor.rb +3 -0
  23. data/lib/vedeu/output/refresh.rb +16 -74
  24. data/lib/vedeu/output/render.rb +44 -17
  25. data/lib/vedeu/output/view.rb +3 -0
  26. data/lib/vedeu/repositories/buffers.rb +32 -42
  27. data/lib/vedeu/repositories/events.rb +8 -11
  28. data/lib/vedeu/repositories/focus.rb +15 -13
  29. data/lib/vedeu/repositories/groups.rb +20 -2
  30. data/lib/vedeu/repositories/interfaces.rb +22 -2
  31. data/lib/vedeu/repositories/keymap_validator.rb +104 -0
  32. data/lib/vedeu/repositories/keymaps.rb +239 -0
  33. data/lib/vedeu/repositories/menus.rb +12 -3
  34. data/lib/vedeu/support/common.rb +2 -2
  35. data/lib/vedeu/support/cursor.rb +3 -0
  36. data/lib/vedeu/support/event.rb +48 -7
  37. data/lib/vedeu/support/grid.rb +1 -1
  38. data/lib/vedeu/support/registrar.rb +66 -0
  39. data/lib/vedeu/support/trace.rb +71 -12
  40. data/test/lib/vedeu/api/api_test.rb +27 -9
  41. data/test/lib/vedeu/api/composition_test.rb +10 -0
  42. data/test/lib/vedeu/api/defined_test.rb +14 -0
  43. data/test/lib/vedeu/api/interface_test.rb +86 -85
  44. data/test/lib/vedeu/api/keymap_test.rb +61 -0
  45. data/test/lib/vedeu/configuration_test.rb +12 -0
  46. data/test/lib/vedeu/models/attributes/coercions_test.rb +3 -4
  47. data/test/lib/vedeu/models/interface_test.rb +0 -43
  48. data/test/lib/vedeu/models/keymap_test.rb +19 -0
  49. data/test/lib/vedeu/models/style_test.rb +10 -0
  50. data/test/lib/vedeu/output/refresh_test.rb +0 -12
  51. data/test/lib/vedeu/output/render_test.rb +51 -0
  52. data/test/lib/vedeu/repositories/buffers_test.rb +39 -12
  53. data/test/lib/vedeu/repositories/events_test.rb +6 -0
  54. data/test/lib/vedeu/repositories/focus_test.rb +12 -0
  55. data/test/lib/vedeu/repositories/keymap_validator_test.rb +81 -0
  56. data/test/lib/vedeu/repositories/keymaps_test.rb +254 -0
  57. data/test/lib/vedeu/support/common_test.rb +26 -0
  58. data/test/lib/vedeu/support/registrar_test.rb +68 -0
  59. data/vedeu.gemspec +1 -1
  60. metadata +18 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa08f6802848478327fb38d44b28b19ffbb78d75
4
- data.tar.gz: 8e30625c919e7d3c678c7301c707904e5ac70328
3
+ metadata.gz: dec7d96b1f14de41e305192ec084b5f16ea39779
4
+ data.tar.gz: afd4cc9b1eea2d7eb9c781abbdf71feab39514ed
5
5
  SHA512:
6
- metadata.gz: 50aaa91ab6b23ce968ab31fa9100959c8a05f21d9accffd2f3444a53474fa16c6b30527aa4aca79e4ce35fd5dece0799ed101b6e5c9ad171bddc44734ad94bb7
7
- data.tar.gz: 7dafc1f4a3f8fa836e05f665ef005c30550632bce5e92eb1ba69abe435e48b159b94268448c7465392816692e625e48f5b129bb573eedc86564eeef64c58af07
6
+ metadata.gz: c008ae703f26a202bb20b3c0909dc1779a4d30606365f96342637e5c3715018fa75d16ddf12f7087599a99aa24785830ca55683b286246e77e2ad444101f2fbe
7
+ data.tar.gz: f587307ac3e309e74b018770048f90dae43cae84b8805f041df8d29c0231c42191d5d92337a5625ceb11c71fc24aca8cb072170227bc7cde177082f299d42833
data/README.md CHANGED
@@ -56,15 +56,9 @@ class MyApp
56
56
  # ...
57
57
  end
58
58
 
59
- event :key do |key|
60
- case key
61
- when 'a' then puts "Apple"
62
- when 'b' then puts "Banana"
63
- # ...
64
- when :f1 then trigger(:some_event)
65
- when :f2 then
66
- trigger(:other_event, { args: here }, [:or, :here], :etc)
67
- end
59
+ keys do
60
+ key('a') { trigger(':apple') }
61
+ key('b') { trigger(':banana') }
68
62
  end
69
63
  end
70
64
  ```
data/docs/api.md CHANGED
@@ -39,45 +39,73 @@ class OtherClassInYourApplication
39
39
 
40
40
  ### API DSL methods
41
41
 
42
- defined
43
- event
44
- events
45
- height
46
- interface
47
- keypress
48
- log
49
- menu
50
- resize
51
- trigger
52
- unevent
53
- use
54
- view
55
- views
56
- width
57
-
58
- colour
59
- style
60
-
61
- line
62
- use
63
- cursor
64
- delay
65
- group
66
- name
67
- x
68
- y
69
- width
70
- height
71
- centred
72
-
73
- items
74
- name
75
-
76
- stream
77
- text
78
- foreground
79
- background
80
-
81
- align
82
- text
83
- width
42
+ #### Events
43
+
44
+ - event
45
+ - trigger
46
+ - unevent
47
+
48
+
49
+ #### Input
50
+
51
+ - keypress
52
+ - keys
53
+ - key
54
+ - interface
55
+
56
+
57
+ #### Interfaces
58
+
59
+ - interface
60
+ - centred
61
+ - colour
62
+ - cursor
63
+ - delay
64
+ - group
65
+ - height
66
+ - name
67
+ - style
68
+ - use
69
+ - width
70
+ - x
71
+ - y
72
+
73
+
74
+ #### Views
75
+
76
+ - render
77
+ - views
78
+ - view
79
+ - view
80
+ - colour
81
+ - line
82
+ - background
83
+ - colour
84
+ - foreground
85
+ - stream
86
+ - align
87
+ - colour
88
+ - style
89
+ - text
90
+ - width
91
+ - style
92
+ - name
93
+ - style
94
+ - use
95
+
96
+
97
+ #### Menus
98
+
99
+ - menu
100
+ - items
101
+ - name
102
+
103
+
104
+ #### Miscellany
105
+
106
+ - defined
107
+ - height
108
+ - log
109
+ - resize
110
+ - width
111
+
data/elements.txt ADDED
@@ -0,0 +1,118 @@
1
+ holmium
2
+ neon
3
+ mercury
4
+ protactinium
5
+ - calcium
6
+ - fermium
7
+ - nitrogen
8
+ - palladium
9
+ - silicon
10
+ - oxygen
11
+ - americium
12
+ - bismuth
13
+ ununpentium
14
+ - chlorine
15
+ neptunium
16
+ plutonium
17
+ - carbon
18
+ - zinc
19
+ polonium
20
+ roentgenium
21
+ darmstadtium
22
+ mendelevium
23
+ copernicium
24
+ molybdenum
25
+ aluminium
26
+ iridium
27
+ lanthanum
28
+ neodymium
29
+ ruthenium
30
+ bohrium
31
+ thorium
32
+ indium
33
+ uranium
34
+ strontium
35
+ rubidium
36
+ helium
37
+ berkelium
38
+ gallium
39
+ thallium
40
+ livermorium
41
+ lithium
42
+ fluorine
43
+ chromium
44
+ europium
45
+ selenium
46
+ - cadmium
47
+ xenon
48
+ hassium
49
+ tantalum
50
+ radium
51
+ scandium
52
+ yttrium
53
+ potassium
54
+ promethium
55
+ astatine
56
+ niobium
57
+ seaborgium
58
+ cerium
59
+ lead
60
+ caesium
61
+ gold
62
+ phosphorus
63
+ antimony
64
+ sodium
65
+ rhodium
66
+ magnesium
67
+ hafnium
68
+ rhenium
69
+ cobalt
70
+ francium
71
+ ununtrium
72
+ rutherfordium
73
+ manganese
74
+ lutetium
75
+ thulium
76
+ samarium
77
+ ytterbium
78
+ argon
79
+ technetium
80
+ actinium
81
+ iron
82
+ sulfur
83
+ tungsten
84
+ tin
85
+ hydrogen
86
+ - vanadium
87
+ germanium
88
+ platinum
89
+ - meitnerium
90
+ erbium
91
+ flerovium
92
+ tellurium
93
+ zirconium
94
+ iodine
95
+ titanium
96
+ einsteinium
97
+ dysprosium
98
+ copper
99
+ silver
100
+ arsenic
101
+ dubnium
102
+ nobelium
103
+ radon
104
+ gadolinium
105
+ terbium
106
+ boron
107
+ ununoctium
108
+ nickel
109
+ ununseptium
110
+ bromine
111
+ krypton
112
+ lawrencium
113
+ beryllium
114
+ osmium
115
+ praseodymium
116
+ barium
117
+ curium
118
+ californium
data/lib/vedeu.rb CHANGED
@@ -1,8 +1,5 @@
1
- #
2
- #
3
1
  # Vedeu is a GUI framework for terminal/console applications written in Ruby.
4
2
  #
5
- #
6
3
  module Vedeu
7
4
 
8
5
  # Raised when Vedeu attempts to access a named buffer that does not exist.
@@ -19,9 +16,16 @@ module Vedeu
19
16
  # encounters a problem.
20
17
  InvalidSyntax = Class.new(StandardError)
21
18
 
19
+ # Raised when attempting to assign a key which is already in use.
20
+ KeyInUse = Class.new(StandardError)
21
+
22
22
  # Raised when a menu cannot be found by name.
23
23
  MenuNotFound = Class.new(StandardError)
24
24
 
25
+ # Raised when the attributes argument to {Vedeu::Registrar} does not contain
26
+ # a required key or the value to that key is nil or empty.
27
+ MissingRequired = Class.new(StandardError)
28
+
25
29
  # Raised intentionally when the client application wishes to switch between
26
30
  # cooked and raw (or vice versa) terminal modes. Vedeu is hard-wired to use
27
31
  # the `Escape` key to trigger this change for the time being.
@@ -61,10 +65,10 @@ require 'logger'
61
65
  require 'optparse'
62
66
  require 'set'
63
67
 
68
+ require 'vedeu/configuration'
64
69
  require 'vedeu/support/common'
65
70
  require 'vedeu/support/log'
66
71
  require 'vedeu/support/trace'
67
- require 'vedeu/configuration'
68
72
 
69
73
  require 'vedeu/models/attributes/coercions'
70
74
  require 'vedeu/models/attributes/colour_translator'
@@ -82,6 +86,7 @@ require 'vedeu/models/geometry'
82
86
  require 'vedeu/models/colour'
83
87
  require 'vedeu/models/style'
84
88
  require 'vedeu/models/interface'
89
+ require 'vedeu/models/keymap'
85
90
  require 'vedeu/models/line'
86
91
  require 'vedeu/models/stream'
87
92
 
@@ -92,17 +97,22 @@ require 'vedeu/api/api'
92
97
  require 'vedeu/api/composition'
93
98
  require 'vedeu/api/helpers'
94
99
  require 'vedeu/api/interface'
100
+ require 'vedeu/api/keymap'
95
101
  require 'vedeu/api/line'
96
102
  require 'vedeu/api/menu'
97
103
  require 'vedeu/api/stream'
98
104
 
99
105
  require 'vedeu/repositories/menus'
106
+ require 'vedeu/repositories/keymap_validator'
107
+ require 'vedeu/repositories/keymaps'
100
108
  require 'vedeu/repositories/interfaces'
101
109
  require 'vedeu/repositories/groups'
102
110
  require 'vedeu/repositories/focus'
103
111
  require 'vedeu/repositories/events'
104
112
  require 'vedeu/repositories/buffers'
105
113
 
114
+ require 'vedeu/support/registrar'
115
+
106
116
  require 'vedeu/output/clear'
107
117
  require 'vedeu/output/compositor'
108
118
  require 'vedeu/output/refresh'
data/lib/vedeu/api/api.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Vedeu
2
2
 
3
+ # Vedeu::Trace.call({ trace: true })
4
+
3
5
  # Provides the API to Vedeu. Methods therein, and classes belonging to this
4
6
  # module expose Vedeu's core functionality.
5
7
  module API
@@ -59,7 +61,7 @@ module Vedeu
59
61
  #
60
62
  # @return [Hash]
61
63
  def event(name, opts = {}, &block)
62
- Vedeu.events.event(name, opts = {}, &block)
64
+ Vedeu.events.event(name, opts, &block)
63
65
  end
64
66
 
65
67
  # Initially accessed by Vedeu itself, this sets up some basic events needed
@@ -117,29 +119,45 @@ module Vedeu
117
119
  API::Interface.define({ name: name }, &block)
118
120
  end
119
121
 
120
- # Handles the keypress in your application. Can also be used to simulate a
121
- # keypress. The example below will have the following workflow:
122
- #
123
- # 1) Trigger the event `:key` in your application, which you will handle
124
- # and perform the appropriate action- maybe nothing.
125
- # 2) If debugging is enabled in Vedeu, then the key is logged to the log
126
- # file.
127
- #
128
122
  # @api public
129
- # @param key [String|Symbol] The key which was pressed. Escape sequences
130
- # are also supported. Special keys like the F-keys are named as symbols;
131
- # i.e. `:f4`. A list of these translations can be found at {Vedeu::Input}.
132
123
  #
133
124
  # @example
134
125
  # Vedeu.keypress('s')
135
126
  #
136
- # @return []
127
+ # @see Vedeu::Keymaps.use
137
128
  def keypress(key)
138
- Vedeu.trigger(:key, key)
139
- Vedeu.trigger(:_log_, "Key: #{key}") if Configuration.debug?
140
- Vedeu.trigger(:_mode_switch_) if key == :escape
141
- Vedeu.trigger(:_focus_next_) if key == :tab
142
- Vedeu.trigger(:_focus_prev_) if key == :shift_tab
129
+ Vedeu::Keymaps.use(key)
130
+ end
131
+
132
+ # Define actions for keypresses for when specific interfaces are in focus.
133
+ # Unless an interface is specified, the key will be assumed to be global,
134
+ # meaning its action will happen regardless of the interface in focus.
135
+ #
136
+ # @api public
137
+ # @param name_or_names [String] The name or names of the interface(s) which
138
+ # will handle these keys.
139
+ # @param block [Proc]
140
+ #
141
+ # @example
142
+ # keys do # => will be global
143
+ # key('s') { :something }
144
+ # ...
145
+ #
146
+ # keys 'my_interface' do # => will only function when 'my_interface'
147
+ # ... # is in focus
148
+ #
149
+ # keys('main', 'other') do # => will function for both 'main' and
150
+ # ... # 'other' interfaces
151
+ #
152
+ # keys do
153
+ # interface 'my_interface' # => will only function when 'my_interface'
154
+ # ... # is in focus
155
+ #
156
+ # @return [API::Keymap]
157
+ def keys(*name_or_names, &block)
158
+ fail InvalidSyntax, '`keys` requires a block.' unless block_given?
159
+
160
+ API::Keymap.define({ interfaces: name_or_names }, &block)
143
161
  end
144
162
 
145
163
  # Write a message to the Vedeu log file located at `$HOME/.vedeu/vedeu.log`
@@ -147,7 +165,7 @@ module Vedeu
147
165
  # @api public
148
166
  # @param message [String] The message you wish to emit to the log
149
167
  # file, useful for debugging.
150
- # @param force [TrueClass|FalseClass] When evaluates to true will
168
+ # @param force [Boolean] When evaluates to true will
151
169
  # write to the log file regardless of the Configuration setting.
152
170
  #
153
171
  # @example
@@ -158,40 +176,65 @@ module Vedeu
158
176
  Vedeu::Log.logger.debug(message) if Configuration.debug? || force
159
177
  end
160
178
 
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.
179
+ # Register a menu by name which will display a collection of items for your
180
+ # users to select; and provide interactivity within your application.
164
181
  #
165
182
  # @api public
166
183
  # @param name [String] The name of the menu. Used to reference the
167
184
  # menu throughout your application's execution lifetime.
168
185
  # @param block [Proc] A set of attributes which define the features of the
169
- # menu. TODO: More help.
186
+ # menu. See {Vedeu::API::Menu#items} and {Vedeu::API::Menu#name}.
170
187
  #
171
188
  # @example
172
189
  # Vedeu.menu 'my_interface' do
190
+ # items [:item_1, :item_2, :item_3]
173
191
  # ...
174
192
  #
175
193
  # Vedeu.menu do
176
194
  # name 'menus_must_have_a_name'
195
+ # items Track.all_my_favourites
177
196
  # ...
178
197
  #
179
198
  # @return [API::Menu]
180
199
  def menu(name = '', &block)
200
+ fail InvalidSyntax, '`menu` requires a block.' unless block_given?
201
+
181
202
  API::Menu.define({ name: name }, &block)
182
203
  end
183
204
 
205
+ # Directly write a view buffer to the terminal. Using this method means
206
+ # that the refresh event does not need to be triggered after creating the
207
+ # view or views, though can be later triggered if needed.
208
+ #
209
+ # @api public
210
+ # @param block [Proc] The directives you wish to send to render. Must
211
+ # include `view` or `views` with associated sub-
212
+ # directives.
213
+ #
214
+ # @example
215
+ # Vedeu.render do
216
+ # views do
217
+ # view 'my_interface' do
218
+ # ...
219
+ #
220
+ # @return [Array]
221
+ def render(&block)
222
+ API::Composition.render(&block)
223
+ end
224
+
184
225
  # When the terminal emit the 'SIGWINCH' signal, Vedeu can intercept this
185
226
  # and attempt to redraw the current interface with varying degrees of
186
227
  # success. Can also be used to simulate a terminal resize.
187
228
  #
188
229
  # @api private
189
- # @return []
230
+ # @return [TrueClass]
190
231
  # :nocov:
191
232
  def resize
192
233
  trigger(:_clear_)
193
234
 
194
235
  trigger(:_refresh_)
236
+
237
+ true
195
238
  end
196
239
  # :nocov:
197
240