vedeu 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -23
  3. data/deps.md +15 -19
  4. data/lib/vedeu.rb +8 -54
  5. data/lib/vedeu/api/base.rb +5 -3
  6. data/lib/vedeu/api/events.rb +75 -0
  7. data/lib/vedeu/api/interface.rb +12 -2
  8. data/lib/vedeu/api/store.rb +37 -0
  9. data/lib/vedeu/api/view.rb +12 -4
  10. data/lib/vedeu/application.rb +7 -3
  11. data/lib/vedeu/configuration.rb +4 -0
  12. data/lib/vedeu/instrumentation.rb +1 -9
  13. data/lib/vedeu/launcher.rb +5 -3
  14. data/lib/vedeu/models/attributes/background.rb +11 -0
  15. data/lib/vedeu/models/attributes/collection.rb +1 -7
  16. data/lib/vedeu/{output → models/attributes}/colour_translator.rb +19 -3
  17. data/lib/vedeu/models/attributes/foreground.rb +11 -0
  18. data/lib/vedeu/models/attributes/interface_collection.rb +5 -5
  19. data/lib/vedeu/models/colour.rb +2 -18
  20. data/lib/vedeu/models/interface.rb +22 -13
  21. data/lib/vedeu/models/line.rb +1 -2
  22. data/lib/vedeu/models/stream.rb +21 -13
  23. data/lib/vedeu/output/{clear_interface.rb → clear.rb} +5 -5
  24. data/lib/vedeu/output/{render_interface.rb → render.rb} +4 -4
  25. data/lib/vedeu/support/esc.rb +3 -0
  26. data/lib/vedeu/support/menu.rb +1 -1
  27. data/lib/vedeu/support/terminal.rb +4 -10
  28. data/test/lib/vedeu/api/base_test.rb +1 -1
  29. data/test/lib/vedeu/api/events_test.rb +37 -0
  30. data/test/lib/vedeu/api/grid_test.rb +11 -9
  31. data/test/lib/vedeu/api/interface_test.rb +10 -13
  32. data/test/lib/vedeu/api/line_test.rb +0 -2
  33. data/test/lib/vedeu/api/store_test.rb +49 -0
  34. data/test/lib/vedeu/api/stream_test.rb +1 -1
  35. data/test/lib/vedeu/api/view_test.rb +1 -1
  36. data/test/lib/vedeu/models/attributes/background_test.rb +8 -0
  37. data/test/lib/vedeu/models/attributes/colour_translator_test.rb +78 -0
  38. data/test/lib/vedeu/models/attributes/foreground_test.rb +8 -0
  39. data/test/lib/vedeu/models/attributes/interface_collection_test.rb +22 -6
  40. data/test/lib/vedeu/models/attributes/line_collection_test.rb +1 -6
  41. data/test/lib/vedeu/models/attributes/stream_collection_test.rb +1 -1
  42. data/test/lib/vedeu/models/composition_test.rb +108 -62
  43. data/test/lib/vedeu/models/geometry_test.rb +48 -0
  44. data/test/lib/vedeu/models/interface_test.rb +26 -10
  45. data/test/lib/vedeu/models/line_test.rb +0 -5
  46. data/test/lib/vedeu/output/{clear_interface_test.rb → clear_test.rb} +8 -8
  47. data/test/lib/vedeu/output/{render_interface_test.rb → render_test.rb} +7 -7
  48. data/test/lib/vedeu/support/esc_test.rb +12 -0
  49. data/test/lib/vedeu/support/terminal_test.rb +2 -1
  50. data/test/lib/vedeu_test.rb +0 -38
  51. data/test/support/colours.rb +1 -1
  52. data/vedeu.gemspec +1 -1
  53. metadata +23 -23
  54. data/lib/vedeu/output/text_adaptor.rb +0 -35
  55. data/lib/vedeu/support/events.rb +0 -51
  56. data/lib/vedeu/support/interface_store.rb +0 -43
  57. data/lib/vedeu/support/queue.rb +0 -31
  58. data/test/lib/vedeu/output/colour_translator_test.rb +0 -42
  59. data/test/lib/vedeu/output/text_adaptor_test.rb +0 -73
  60. data/test/lib/vedeu/support/events_test.rb +0 -35
  61. data/test/lib/vedeu/support/interface_store_test.rb +0 -51
  62. data/test/lib/vedeu/support/queue_test.rb +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f08172957be2fc1e8da242d1e5169f2ef6f9f6c3
4
- data.tar.gz: c6692d292848d90ee1544ef5c0ebf41086f66637
3
+ metadata.gz: b30006037c42b5b8edf6c8dadb382342a593a509
4
+ data.tar.gz: 14c1db8169f22fa1266dfd249942d7aca7ddbe69
5
5
  SHA512:
6
- metadata.gz: 2e5009a40a5c90ca3b4bd2cb36481ae2dfa5af09df0146c29ce80cdcd6045ea81e905181576a5011986132ca72854323c55688a22c38a2622c6a52af729c5d9d
7
- data.tar.gz: 7af3be17bd322e76965c62d13253e2f3044fe4f7145e82b38ea32993228f61b4c2596b78710606d15ac2656f542a2a1b44f09ca556b38ceca50852d546810eb7
6
+ metadata.gz: f5b66b1fb91bb76e83defef25c99f79af93c36297e3607a592e8302a5165c0a2c076b31325d803c19a74f1613493a9fba26772ecf98e13d2f49f842a4981d4f3
7
+ data.tar.gz: 9b090b685842e11c0f45aa2c341ae8eb99234a0fcade6c58f5b0e6b4fda1c16afb75b3df01d95006a715a24e6f892e331fdee6a0ef7a53a55b49e95c1458e9d0
data/README.md CHANGED
@@ -50,9 +50,9 @@ Expect proper documentation soon!
50
50
  when 'a' then puts "Apple"
51
51
  when 'b' then puts "Banana"
52
52
  # ...
53
- when :f1 then run(:some_event)
53
+ when :f1 then trigger(:some_event)
54
54
  when :f2 then
55
- run(:other_event, { args: here }, [:or, :here], :etc)
55
+ trigger(:other_event, { args: here }, [:or, :here], :etc)
56
56
  end
57
57
  end
58
58
  end
@@ -116,7 +116,9 @@ Note: not setting a width or height will set the values to the terminal's report
116
116
  event :event_name do |arg1, arg2|
117
117
  end
118
118
 
119
- One can define events which perform work or trigger other events. Vedeu has built-in events which are namespaced with underscores as to hopefully not cause a collision with events you wish to create:
119
+ One can define events which perform work or trigger other events. Vedeu has built-in events which are namespaced with underscores:
120
+
121
+ - `:_initialize_` 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.
120
122
 
121
123
  - `:_clear_` Clears the whole terminal space.
122
124
 
@@ -155,25 +157,26 @@ Vedeu has a range of symbol styles which are compatible with most terminals whic
155
157
 
156
158
  Like colours, they can be defined in either interfaces, for specific lines or within streams. Styles are applied as encountered.
157
159
 
158
- | Style name | Escape Sequence |
159
- |---------------|--------------------------|
160
- | bg_reset | `\e[48;2;49m` |
161
- | blink | `\e[5m` |
162
- | blink_off | `\e[25m` |
163
- | bold | `\e[1m` |
164
- | bold_off | `\e[21m` |
165
- | clear | `\e[2J` |
166
- | colour_reset | `\e[38;2;39m\e[48;2;49m` |
167
- | fg_reset | `\e[38;2;39m` |
168
- | hide_cursor | `\e[?25l` |
169
- | negative | `\e[7m` |
170
- | positive | `\e[27m` |
171
- | reset | `\e[0m` |
172
- | normal | `\e[24m\e[21m\e[27m` |
173
- | dim | `\e[2m` |
174
- | show_cursor | `\e[?25h` |
175
- | underline | `\e[4m` |
176
- | underline_off | `\e[24m` |
160
+ | Style name | Escape Sequence |
161
+ |---------------|-------------------------------|
162
+ | bg_reset | `\e[48;2;49m` |
163
+ | blink | `\e[5m` |
164
+ | blink_off | `\e[25m` |
165
+ | bold | `\e[1m` |
166
+ | bold_off | `\e[21m` |
167
+ | clear | `\e[2J` |
168
+ | clear_line | `\e[38;2;39m\e[48;2;49m\e[2K` |
169
+ | colour_reset | `\e[38;2;39m\e[48;2;49m` |
170
+ | fg_reset | `\e[38;2;39m` |
171
+ | hide_cursor | `\e[?25l` |
172
+ | negative | `\e[7m` |
173
+ | positive | `\e[27m` |
174
+ | reset | `\e[0m` |
175
+ | normal | `\e[24m\e[21m\e[27m` |
176
+ | dim | `\e[2m` |
177
+ | show_cursor | `\e[?25h` |
178
+ | underline | `\e[4m` |
179
+ | underline_off | `\e[24m` |
177
180
 
178
181
 
179
182
  ## Contributing
@@ -186,4 +189,4 @@ Like colours, they can be defined in either interfaces, for specific lines or wi
186
189
  6. Write some tests, write some code, have some fun
187
190
  7. Commit your changes (`git commit -am 'Add some feature'`)
188
191
  8. Push to the branch (`git push origin my-new-feature`)
189
- 9. Create new Pull Request
192
+ 9. Create a new pull request
data/deps.md CHANGED
@@ -22,7 +22,7 @@ API::Interface
22
22
  API::Grid
23
23
  Geometry
24
24
  Interface
25
- InterfaceStore
25
+ API::Store
26
26
  Terminal
27
27
 
28
28
  API::Line
@@ -34,13 +34,13 @@ API::Stream
34
34
 
35
35
  API::View
36
36
  API::Line
37
- InterfaceStore
37
+ API::Store
38
38
 
39
39
  Application
40
40
  Input
41
41
  Terminal
42
42
 
43
- ClearInterface
43
+ Clear
44
44
 
45
45
  Collection
46
46
 
@@ -63,10 +63,10 @@ Geometry
63
63
 
64
64
  Esc
65
65
 
66
- Events
66
+ API::Events
67
67
 
68
68
  Input
69
- Events
69
+ API::Events
70
70
  Terminal
71
71
 
72
72
  Instrumentation
@@ -74,17 +74,16 @@ Instrumentation
74
74
  Trace
75
75
 
76
76
  Interface
77
- ClearInterface
77
+ Clear
78
78
  Colour
79
79
  Geometry
80
80
  LineCollection
81
- Queue
82
- RenderInterface
81
+ Render
83
82
  Style
84
83
  Terminal
85
84
 
86
85
  InterfaceCollection
87
- InterfaceStore
86
+ API::Store
88
87
 
89
88
  Launcher
90
89
  Application
@@ -100,14 +99,12 @@ LineCollection
100
99
  Line
101
100
 
102
101
  Menu
103
- Events
102
+ API::Events
104
103
 
105
- InterfaceStore
104
+ API::Store
106
105
  Interface
107
106
 
108
- Queue
109
-
110
- RenderInterface
107
+ Render
111
108
  Line
112
109
  Stream
113
110
 
@@ -144,7 +141,7 @@ Grouped
144
141
  API::Interface
145
142
  Interface
146
143
  Geometry
147
- InterfaceStore
144
+ API::Store
148
145
 
149
146
  Launcher
150
147
  Application
@@ -158,9 +155,9 @@ Launcher
158
155
  View
159
156
  Composition
160
157
  InterfaceCollection
161
- InterfaceStore
158
+ API::Store
162
159
  Interface
163
- ClearInterface
160
+ Clear
164
161
  Colour
165
162
  Background
166
163
  Foreground
@@ -184,8 +181,7 @@ View
184
181
  Esc
185
182
  Style
186
183
  Esc
187
- Queue
188
- RenderInterface
184
+ Render
189
185
  Line
190
186
  Stream
191
187
  Style
data/lib/vedeu.rb CHANGED
@@ -1,61 +1,18 @@
1
1
  require 'vedeu/instrumentation'
2
+
3
+ require 'vedeu/api/events'
4
+ require 'vedeu/api/grid'
2
5
  require 'vedeu/api/interface'
3
- require 'vedeu/support/events'
4
- require 'vedeu/support/interface_store'
6
+ require 'vedeu/api/line'
7
+ require 'vedeu/api/store'
8
+ require 'vedeu/api/stream'
5
9
  require 'vedeu/api/view'
6
- require 'vedeu/models/geometry'
10
+
7
11
  require 'vedeu/support/menu'
8
- require 'vedeu/output/view'
9
12
  require 'vedeu/launcher'
10
13
 
11
- # Todo: mutation (events)
12
-
13
14
  module Vedeu
14
- # :nocov:
15
- def self.debug?
16
- false
17
- end
18
-
19
- Vedeu::Instrumentation::Trace.call if debug?
20
-
21
- module API
22
- def interface(name, &block)
23
- Interface.save(name, &block)
24
- end
25
-
26
- def on(name, delay = 0, &block)
27
- Vedeu.events.on(name, delay, &block)
28
- end
29
- alias_method :event, :on
30
-
31
- def trigger(name, *args)
32
- Vedeu.events.trigger(name, *args)
33
- end
34
- alias_method :run, :trigger
35
-
36
- def with(name, &block)
37
- InterfaceStore.query(name)
38
- end
39
-
40
- def view(name = '', &block)
41
- Vedeu::API::View.build(name, &block)
42
- end
43
- end
44
-
45
- def self.events
46
- @events ||= Events.new do
47
- on(:_exit_) { fail StopIteration }
48
- on(:_log_) { |message| Vedeu.log(message) }
49
- on(:_mode_switch_) { fail ModeSwitch }
50
- on(:_clear_) { Terminal.output(Esc.string('clear')) }
51
-
52
- on(:_keypress_) do |key|
53
- trigger(:key, key)
54
- trigger(:_log_, (' ' * 42) + "key: #{key}")
55
- trigger(:_mode_switch_) if key == :escape
56
- end
57
- end
58
- end
15
+ extend API
59
16
 
60
17
  def self.log(message)
61
18
  Vedeu::Instrumentation::Log.logger.debug(message)
@@ -69,7 +26,4 @@ module Vedeu
69
26
  receiver.send(:include, API)
70
27
  receiver.extend(API)
71
28
  end
72
-
73
- extend API
74
- # :nocov:
75
29
  end
@@ -5,7 +5,7 @@ module Vedeu
5
5
  new(attributes, &block).build
6
6
  end
7
7
 
8
- def initialize(attributes, &block)
8
+ def initialize(attributes = {}, &block)
9
9
  @attributes = attributes
10
10
 
11
11
  @self_before_instance_eval = eval 'self', block.binding
@@ -30,16 +30,18 @@ module Vedeu
30
30
  def style(values = [], &block)
31
31
  if block_given?
32
32
  attributes[:streams] << API::Stream.build({ style: [values] }, &block)
33
+
33
34
  else
34
35
  [values].flatten.each { |value| attributes[:style] << value }
36
+
35
37
  end
36
38
  end
37
39
 
38
- # :nocov:
40
+ private
41
+
39
42
  def method_missing(method, *args, &block)
40
43
  @self_before_instance_eval.send method, *args, &block
41
44
  end
42
- # :nocov
43
45
  end
44
46
  end
45
47
  end
@@ -0,0 +1,75 @@
1
+ # Todo: mutation (events)
2
+
3
+ module Vedeu
4
+ module API
5
+ def on(name, delay = 0, &block)
6
+ Vedeu.events.on(name, delay, &block)
7
+ end
8
+ alias_method :event, :on
9
+
10
+ def trigger(name, *args)
11
+ Vedeu.events.trigger(name, *args)
12
+ end
13
+
14
+ def events
15
+ @events ||= API::Events.new do
16
+ on(:_exit_) { fail StopIteration }
17
+ on(:_log_) { |message| Vedeu.log(message) }
18
+ on(:_mode_switch_) { fail ModeSwitch }
19
+ on(:_clear_) { Terminal.output(Esc.string('clear')) }
20
+
21
+ on(:_keypress_) do |key|
22
+ trigger(:key, key)
23
+ trigger(:_log_, (' ' * 42) + "key: #{key}")
24
+ trigger(:_mode_switch_) if key == :escape
25
+ end
26
+ end
27
+ end
28
+
29
+ class Events
30
+ def initialize(&block)
31
+ @handlers = Hash.new do |hash, key|
32
+ hash[key] = {
33
+ delay: 0,
34
+ events: [],
35
+ last_exec: 0,
36
+ }
37
+ end
38
+ self.instance_eval(&block) if block_given?
39
+ self
40
+ end
41
+
42
+ def add(object, &block)
43
+ @self_before_instance_eval = eval 'self', block.binding
44
+
45
+ self.instance_eval(&block)
46
+ end
47
+
48
+ def on(event, delay = 0, &block)
49
+ handlers[event][:events] << block
50
+ handlers[event][:delay] = delay
51
+ handlers[event]
52
+ end
53
+
54
+ def trigger(event, *args)
55
+ elapsed = Time.now.to_f - handlers[event][:last_exec]
56
+
57
+ if elapsed > handlers[event][:delay]
58
+ handlers[event][:last_exec] = Time.now.to_f
59
+
60
+ handlers[event][:events].each do |handler|
61
+ handler.call(*args)
62
+ end
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ attr_reader :handlers, :throttles
69
+
70
+ def method_missing(method, *args, &block)
71
+ @self_before_instance_eval.send method, *args, &block
72
+ end
73
+ end
74
+ end
75
+ end
@@ -1,6 +1,6 @@
1
1
  require 'vedeu/models/geometry'
2
2
  require 'vedeu/api/grid'
3
- require 'vedeu/support/interface_store'
3
+ require 'vedeu/api/store'
4
4
  require 'vedeu/support/terminal'
5
5
 
6
6
  module Vedeu
@@ -10,6 +10,10 @@ module Vedeu
10
10
  XOutOfBounds = Class.new(StandardError)
11
11
  YOutOfBounds = Class.new(StandardError)
12
12
 
13
+ def interface(name, &block)
14
+ Interface.save(name, &block)
15
+ end
16
+
13
17
  class Interface
14
18
  def self.save(name, &block)
15
19
  new(name).save(&block)
@@ -22,13 +26,19 @@ module Vedeu
22
26
  def save(&block)
23
27
  self.instance_eval(&block) if block_given?
24
28
 
25
- InterfaceStore.create(attributes)
29
+ stored_attributes = Store.create(attributes)
30
+
31
+ Vedeu::Interface.new(stored_attributes)
26
32
  end
27
33
 
28
34
  private
29
35
 
30
36
  attr_reader :name
31
37
 
38
+ def use(value)
39
+ Vedeu.use(value)
40
+ end
41
+
32
42
  def x(value)
33
43
  fail XOutOfBounds if x_out_of_bounds?(value)
34
44
 
@@ -0,0 +1,37 @@
1
+ require 'vedeu/models/interface'
2
+
3
+ # Todo: mutation (persistence)
4
+
5
+ module Vedeu
6
+ module API
7
+ EntityNotFound = Class.new(StandardError)
8
+
9
+ def use(name)
10
+ Vedeu::Interface.new(Store.query(name))
11
+ end
12
+
13
+ module Store
14
+ extend self
15
+
16
+ def create(attributes)
17
+ storage.store(attributes[:name], attributes)
18
+ end
19
+
20
+ def query(name)
21
+ attributes = storage.fetch(name) do
22
+ fail EntityNotFound, 'Interface was not found.'
23
+ end
24
+ end
25
+
26
+ def reset
27
+ @storage = {}
28
+ end
29
+
30
+ private
31
+
32
+ def storage
33
+ @storage ||= {}
34
+ end
35
+ end
36
+ end
37
+ end