vedeu 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -23
- data/deps.md +15 -19
- data/lib/vedeu.rb +8 -54
- data/lib/vedeu/api/base.rb +5 -3
- data/lib/vedeu/api/events.rb +75 -0
- data/lib/vedeu/api/interface.rb +12 -2
- data/lib/vedeu/api/store.rb +37 -0
- data/lib/vedeu/api/view.rb +12 -4
- data/lib/vedeu/application.rb +7 -3
- data/lib/vedeu/configuration.rb +4 -0
- data/lib/vedeu/instrumentation.rb +1 -9
- data/lib/vedeu/launcher.rb +5 -3
- data/lib/vedeu/models/attributes/background.rb +11 -0
- data/lib/vedeu/models/attributes/collection.rb +1 -7
- data/lib/vedeu/{output → models/attributes}/colour_translator.rb +19 -3
- data/lib/vedeu/models/attributes/foreground.rb +11 -0
- data/lib/vedeu/models/attributes/interface_collection.rb +5 -5
- data/lib/vedeu/models/colour.rb +2 -18
- data/lib/vedeu/models/interface.rb +22 -13
- data/lib/vedeu/models/line.rb +1 -2
- data/lib/vedeu/models/stream.rb +21 -13
- data/lib/vedeu/output/{clear_interface.rb → clear.rb} +5 -5
- data/lib/vedeu/output/{render_interface.rb → render.rb} +4 -4
- data/lib/vedeu/support/esc.rb +3 -0
- data/lib/vedeu/support/menu.rb +1 -1
- data/lib/vedeu/support/terminal.rb +4 -10
- data/test/lib/vedeu/api/base_test.rb +1 -1
- data/test/lib/vedeu/api/events_test.rb +37 -0
- data/test/lib/vedeu/api/grid_test.rb +11 -9
- data/test/lib/vedeu/api/interface_test.rb +10 -13
- data/test/lib/vedeu/api/line_test.rb +0 -2
- data/test/lib/vedeu/api/store_test.rb +49 -0
- data/test/lib/vedeu/api/stream_test.rb +1 -1
- data/test/lib/vedeu/api/view_test.rb +1 -1
- data/test/lib/vedeu/models/attributes/background_test.rb +8 -0
- data/test/lib/vedeu/models/attributes/colour_translator_test.rb +78 -0
- data/test/lib/vedeu/models/attributes/foreground_test.rb +8 -0
- data/test/lib/vedeu/models/attributes/interface_collection_test.rb +22 -6
- data/test/lib/vedeu/models/attributes/line_collection_test.rb +1 -6
- data/test/lib/vedeu/models/attributes/stream_collection_test.rb +1 -1
- data/test/lib/vedeu/models/composition_test.rb +108 -62
- data/test/lib/vedeu/models/geometry_test.rb +48 -0
- data/test/lib/vedeu/models/interface_test.rb +26 -10
- data/test/lib/vedeu/models/line_test.rb +0 -5
- data/test/lib/vedeu/output/{clear_interface_test.rb → clear_test.rb} +8 -8
- data/test/lib/vedeu/output/{render_interface_test.rb → render_test.rb} +7 -7
- data/test/lib/vedeu/support/esc_test.rb +12 -0
- data/test/lib/vedeu/support/terminal_test.rb +2 -1
- data/test/lib/vedeu_test.rb +0 -38
- data/test/support/colours.rb +1 -1
- data/vedeu.gemspec +1 -1
- metadata +23 -23
- data/lib/vedeu/output/text_adaptor.rb +0 -35
- data/lib/vedeu/support/events.rb +0 -51
- data/lib/vedeu/support/interface_store.rb +0 -43
- data/lib/vedeu/support/queue.rb +0 -31
- data/test/lib/vedeu/output/colour_translator_test.rb +0 -42
- data/test/lib/vedeu/output/text_adaptor_test.rb +0 -73
- data/test/lib/vedeu/support/events_test.rb +0 -35
- data/test/lib/vedeu/support/interface_store_test.rb +0 -51
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b30006037c42b5b8edf6c8dadb382342a593a509
|
4
|
+
data.tar.gz: 14c1db8169f22fa1266dfd249942d7aca7ddbe69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
53
|
+
when :f1 then trigger(:some_event)
|
54
54
|
when :f2 then
|
55
|
-
|
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
|
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
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
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
|
-
|
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
|
-
|
37
|
+
API::Store
|
38
38
|
|
39
39
|
Application
|
40
40
|
Input
|
41
41
|
Terminal
|
42
42
|
|
43
|
-
|
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
|
-
|
77
|
+
Clear
|
78
78
|
Colour
|
79
79
|
Geometry
|
80
80
|
LineCollection
|
81
|
-
|
82
|
-
RenderInterface
|
81
|
+
Render
|
83
82
|
Style
|
84
83
|
Terminal
|
85
84
|
|
86
85
|
InterfaceCollection
|
87
|
-
|
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
|
-
|
104
|
+
API::Store
|
106
105
|
Interface
|
107
106
|
|
108
|
-
|
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
|
-
|
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
|
-
|
158
|
+
API::Store
|
162
159
|
Interface
|
163
|
-
|
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
|
-
|
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/
|
4
|
-
require 'vedeu/
|
6
|
+
require 'vedeu/api/line'
|
7
|
+
require 'vedeu/api/store'
|
8
|
+
require 'vedeu/api/stream'
|
5
9
|
require 'vedeu/api/view'
|
6
|
-
|
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
|
-
|
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
|
data/lib/vedeu/api/base.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/vedeu/api/interface.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'vedeu/models/geometry'
|
2
2
|
require 'vedeu/api/grid'
|
3
|
-
require 'vedeu/
|
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
|
-
|
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
|