vedeu 0.0.39 → 0.0.40
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -30
- data/Rakefile +8 -9
- data/bin/log +13 -0
- data/deps.md +11 -95
- data/lib/vedeu.rb +14 -46
- data/lib/vedeu/application.rb +4 -8
- data/lib/vedeu/instrumentation.rb +111 -0
- data/lib/vedeu/launcher.rb +2 -2
- data/lib/vedeu/models/attributes/interface_collection.rb +2 -2
- data/lib/vedeu/models/attributes/line_collection.rb +2 -2
- data/lib/vedeu/models/attributes/stream_collection.rb +2 -2
- data/lib/vedeu/models/colour.rb +1 -1
- data/lib/vedeu/models/composition.rb +1 -1
- data/lib/vedeu/models/interface.rb +18 -10
- data/lib/vedeu/models/line.rb +3 -3
- data/lib/vedeu/models/presentation.rb +1 -1
- data/lib/vedeu/models/stream.rb +2 -2
- data/lib/vedeu/models/style.rb +1 -1
- data/lib/vedeu/output/render_interface.rb +1 -1
- data/lib/vedeu/{support → parsing}/compositor.rb +1 -1
- data/lib/vedeu/parsing/hash_parser.rb +1 -1
- data/lib/vedeu/parsing/parser.rb +6 -10
- data/lib/vedeu/{models/builders → support}/builder.rb +19 -9
- data/lib/vedeu/support/esc.rb +1 -1
- data/lib/vedeu/support/events.rb +15 -19
- data/lib/vedeu/support/geometry.rb +3 -3
- data/lib/vedeu/{input → support}/input.rb +6 -9
- data/lib/vedeu/support/menu.rb +3 -3
- data/lib/vedeu/support/persistence.rb +41 -0
- data/lib/vedeu/support/terminal.rb +1 -1
- data/test/example_app/lib/app.rb +85 -5
- data/test/lib/vedeu/application_test.rb +2 -2
- data/test/lib/vedeu/configuration_test.rb +2 -2
- data/test/lib/vedeu/launcher_test.rb +2 -2
- data/test/lib/vedeu/models/attributes/collection_test.rb +2 -2
- data/test/lib/vedeu/models/attributes/interface_collection_test.rb +4 -4
- data/test/lib/vedeu/models/attributes/line_collection_test.rb +3 -3
- data/test/lib/vedeu/models/attributes/stream_collection_test.rb +3 -3
- data/test/lib/vedeu/models/colour_test.rb +2 -2
- data/test/lib/vedeu/models/composition_test.rb +19 -19
- data/test/lib/vedeu/models/interface_test.rb +46 -34
- data/test/lib/vedeu/models/line_test.rb +2 -2
- data/test/lib/vedeu/models/presentation_test.rb +2 -2
- data/test/lib/vedeu/models/stream_test.rb +2 -2
- data/test/lib/vedeu/models/style_test.rb +31 -31
- data/test/lib/vedeu/output/clear_interface_test.rb +5 -5
- data/test/lib/vedeu/output/render_interface_test.rb +5 -6
- data/test/lib/vedeu/output/template.rb +2 -1
- data/test/lib/vedeu/{support → parsing}/compositor_test.rb +6 -4
- data/test/lib/vedeu/parsing/hash_parser_test.rb +2 -2
- data/test/lib/vedeu/parsing/json_parser_test.rb +2 -2
- data/test/lib/vedeu/parsing/parser_test.rb +6 -5
- data/test/lib/vedeu/parsing/text_adaptor_test.rb +2 -2
- data/test/lib/vedeu/{models/builders/interface_builder_test.rb → support/builder_test.rb} +10 -10
- data/test/lib/vedeu/support/esc_test.rb +2 -2
- data/test/lib/vedeu/support/events_test.rb +2 -2
- data/test/lib/vedeu/support/geometry_test.rb +2 -2
- data/test/lib/vedeu/{input → support}/input_test.rb +6 -7
- data/test/lib/vedeu/support/menu_test.rb +2 -2
- data/test/lib/vedeu/support/persistence_test.rb +55 -0
- data/test/lib/vedeu/support/queue_test.rb +2 -2
- data/test/lib/vedeu/support/terminal_test.rb +2 -2
- data/test/lib/vedeu/support/translator_test.rb +2 -2
- data/test/lib/vedeu/support/wordwrap_test.rb +2 -2
- data/test/lib/vedeu_test.rb +17 -2
- data/test/support/bench.rb +34 -0
- data/test/test_helper.rb +3 -11
- data/vedeu.gemspec +2 -2
- metadata +20 -44
- data/lib/vedeu/models/builders/command_builder.rb +0 -10
- data/lib/vedeu/models/builders/interface_builder.rb +0 -32
- data/lib/vedeu/models/command.rb +0 -23
- data/lib/vedeu/output/output.rb +0 -14
- data/lib/vedeu/process/process.rb +0 -51
- data/lib/vedeu/repository/command_repository.rb +0 -31
- data/lib/vedeu/repository/interface_repository.rb +0 -31
- data/lib/vedeu/repository/repository.rb +0 -41
- data/lib/vedeu/repository/storage.rb +0 -40
- data/lib/vedeu/support/exit.rb +0 -9
- data/test/lib/vedeu/models/builders/builder_test.rb +0 -11
- data/test/lib/vedeu/models/builders/command_builder_test.rb +0 -16
- data/test/lib/vedeu/models/command_test.rb +0 -40
- data/test/lib/vedeu/output/output_test.rb +0 -19
- data/test/lib/vedeu/process/process_test.rb +0 -71
- data/test/lib/vedeu/repository/command_repository_test.rb +0 -55
- data/test/lib/vedeu/repository/interface_repository_test.rb +0 -67
- data/test/lib/vedeu/repository/repository_test.rb +0 -81
- data/test/lib/vedeu/repository/storage_test.rb +0 -70
- data/test/lib/vedeu/support/exit_test.rb +0 -12
- data/test/support/dummy_command.rb +0 -9
data/lib/vedeu/launcher.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'virtus'
|
2
2
|
|
3
|
-
|
3
|
+
require 'vedeu/support/persistence'
|
4
4
|
|
5
5
|
module Vedeu
|
6
6
|
class InterfaceCollection < Virtus::Attribute
|
@@ -8,7 +8,7 @@ module Vedeu
|
|
8
8
|
return [] if values.nil? || values.empty?
|
9
9
|
|
10
10
|
[values].flatten.map do |value|
|
11
|
-
|
11
|
+
Persistence.update(value.fetch(:name, nil), value)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/vedeu/models/colour.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'virtus'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
require 'vedeu'
|
5
|
+
require 'vedeu/models/attributes/line_collection'
|
6
|
+
require 'vedeu/models/presentation'
|
7
|
+
require 'vedeu/models/style'
|
8
|
+
require 'vedeu/output/clear_interface'
|
9
|
+
require 'vedeu/output/render_interface'
|
10
|
+
require 'vedeu/support/geometry'
|
11
|
+
require 'vedeu/support/queue'
|
12
|
+
require 'vedeu/support/terminal'
|
12
13
|
|
13
14
|
module Vedeu
|
14
15
|
class Interface
|
@@ -21,13 +22,18 @@ module Vedeu
|
|
21
22
|
attribute :lines, LineCollection
|
22
23
|
attribute :y, Integer, default: 1
|
23
24
|
attribute :x, Integer, default: 1
|
24
|
-
attribute :z, Integer, default: 1
|
25
25
|
attribute :width, Integer, default: Terminal.width
|
26
26
|
attribute :height, Integer, default: Terminal.height
|
27
27
|
attribute :current, String, default: ''
|
28
28
|
attribute :cursor, Boolean, default: true
|
29
29
|
attribute :centred, Boolean, default: false
|
30
30
|
|
31
|
+
def initialize(attributes = {})
|
32
|
+
Vedeu.events.on(:refresh) { refresh }
|
33
|
+
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
31
37
|
def enqueue
|
32
38
|
super(self.to_s)
|
33
39
|
end
|
@@ -51,6 +57,9 @@ module Vedeu
|
|
51
57
|
self.current
|
52
58
|
|
53
59
|
end
|
60
|
+
Terminal.output(self.current)
|
61
|
+
|
62
|
+
self.current
|
54
63
|
end
|
55
64
|
|
56
65
|
def to_json(*args)
|
@@ -61,7 +70,6 @@ module Vedeu
|
|
61
70
|
lines: lines,
|
62
71
|
y: y,
|
63
72
|
x: x,
|
64
|
-
z: z,
|
65
73
|
width: width,
|
66
74
|
height: height,
|
67
75
|
cursor: cursor
|
data/lib/vedeu/models/line.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'virtus'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
require 'vedeu/models/attributes/stream_collection'
|
5
|
+
require 'vedeu/models/presentation'
|
6
|
+
require 'vedeu/models/style'
|
7
7
|
|
8
8
|
module Vedeu
|
9
9
|
class Line
|
data/lib/vedeu/models/stream.rb
CHANGED
data/lib/vedeu/models/style.rb
CHANGED
data/lib/vedeu/parsing/parser.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'vedeu/parsing/compositor'
|
2
|
+
require 'vedeu/parsing/hash_parser'
|
3
|
+
require 'vedeu/parsing/json_parser'
|
4
4
|
|
5
5
|
module Vedeu
|
6
|
-
|
6
|
+
ParseError = Class.new(StandardError)
|
7
7
|
|
8
8
|
class Parser
|
9
9
|
def self.parse(output = {})
|
10
|
+
return nil if output.nil? || output.empty?
|
11
|
+
|
10
12
|
new(output).parse
|
11
13
|
end
|
12
14
|
|
@@ -15,8 +17,6 @@ module Vedeu
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def parse
|
18
|
-
return nil if empty?
|
19
|
-
|
20
20
|
Compositor.enqueue(parsed_output)
|
21
21
|
end
|
22
22
|
|
@@ -42,9 +42,5 @@ module Vedeu
|
|
42
42
|
def json?
|
43
43
|
output.is_a?(String)
|
44
44
|
end
|
45
|
-
|
46
|
-
def empty?
|
47
|
-
output.nil? || output.empty?
|
48
|
-
end
|
49
45
|
end
|
50
46
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'vedeu/support/geometry'
|
2
|
+
require 'vedeu/support/persistence'
|
3
|
+
|
1
4
|
module Vedeu
|
2
5
|
class Builder
|
3
6
|
def self.build(name, &block)
|
@@ -11,23 +14,30 @@ module Vedeu
|
|
11
14
|
def build(&block)
|
12
15
|
self.instance_eval(&block)
|
13
16
|
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def repository
|
18
|
-
fail StandardError, 'Subclasses implement this.'
|
17
|
+
Persistence.create(attributes)
|
19
18
|
end
|
20
19
|
|
21
20
|
private
|
22
21
|
|
23
22
|
attr_reader :name
|
24
23
|
|
25
|
-
def
|
26
|
-
user_attributes
|
24
|
+
def overrides
|
25
|
+
@overrides = if user_attributes[:centred] == true
|
26
|
+
{ x: geometry.left, y: geometry.top }
|
27
|
+
else
|
28
|
+
{}
|
29
|
+
end
|
27
30
|
end
|
28
31
|
|
29
|
-
def
|
30
|
-
{
|
32
|
+
def geometry
|
33
|
+
@_geometry ||= Geometry.new({
|
34
|
+
height: user_attributes[:height],
|
35
|
+
width: user_attributes[:width],
|
36
|
+
})
|
37
|
+
end
|
38
|
+
|
39
|
+
def attributes
|
40
|
+
user_attributes.merge!(overrides)
|
31
41
|
end
|
32
42
|
|
33
43
|
def user_attributes
|
data/lib/vedeu/support/esc.rb
CHANGED
data/lib/vedeu/support/events.rb
CHANGED
@@ -3,8 +3,7 @@ module Vedeu
|
|
3
3
|
def initialize(&block)
|
4
4
|
@handlers = Hash.new { |h, k| h[k] = [] }
|
5
5
|
|
6
|
-
log("
|
7
|
-
"self: #{self.object_id}")
|
6
|
+
log("self: #{self.object_id}")
|
8
7
|
|
9
8
|
self.instance_eval(&block) if block_given?
|
10
9
|
|
@@ -12,47 +11,44 @@ module Vedeu
|
|
12
11
|
end
|
13
12
|
|
14
13
|
def add(object, &block)
|
15
|
-
log("
|
16
|
-
|
17
|
-
"menu: #{object.object_id}")
|
14
|
+
log("self: #{self.object_id}")
|
15
|
+
log("object: #{object.object_id}")
|
18
16
|
|
19
|
-
@self_before_instance_eval = eval
|
17
|
+
@self_before_instance_eval = eval 'self', block.binding
|
20
18
|
|
21
19
|
self.instance_eval(&block)
|
22
20
|
end
|
23
21
|
|
24
22
|
def on(event, &block)
|
25
|
-
log("
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
log("self: #{self.object_id}")
|
24
|
+
log("block: #{block.object_id}")
|
25
|
+
log("storing: #{event.inspect}")
|
26
|
+
|
29
27
|
handlers[event] << block
|
30
28
|
end
|
31
29
|
|
32
30
|
def trigger(event, *args)
|
33
31
|
handlers[event].each do |handler|
|
34
|
-
log("
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
log("self: #{self.object_id}")
|
33
|
+
log("handler: #{handler.object_id}")
|
34
|
+
log("running: #{event.inspect}")
|
35
|
+
|
38
36
|
handler.call(*args)
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
40
|
+
# :nocov:
|
42
41
|
def method_missing(method, *args, &block)
|
43
42
|
@self_before_instance_eval.send method, *args, &block
|
44
43
|
end
|
44
|
+
# :nocov:
|
45
45
|
|
46
46
|
private
|
47
47
|
|
48
48
|
attr_reader :handlers
|
49
49
|
|
50
50
|
def log(message)
|
51
|
-
Vedeu.
|
52
|
-
end
|
53
|
-
|
54
|
-
def debug?
|
55
|
-
false
|
51
|
+
Vedeu.log(sprintf("%42s%s", '', message))
|
56
52
|
end
|
57
53
|
end
|
58
54
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'vedeu/support/esc'
|
2
|
+
require 'vedeu/support/terminal'
|
3
3
|
|
4
4
|
module Vedeu
|
5
|
-
|
5
|
+
OutOfBoundsError = Class.new(StandardError)
|
6
6
|
|
7
7
|
class Geometry
|
8
8
|
def initialize(attrs = {})
|
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require_relative '../../vedeu'
|
1
|
+
require 'vedeu/support/terminal'
|
2
|
+
require 'vedeu'
|
4
3
|
|
5
4
|
module Vedeu
|
6
5
|
class Input
|
@@ -10,12 +9,14 @@ module Vedeu
|
|
10
9
|
|
11
10
|
def capture
|
12
11
|
Vedeu.trigger(:_keypress_, keypress)
|
13
|
-
|
14
|
-
Queue.enqueue(keypress)
|
15
12
|
end
|
16
13
|
|
17
14
|
private
|
18
15
|
|
16
|
+
def input
|
17
|
+
@_input ||= Terminal.input
|
18
|
+
end
|
19
|
+
|
19
20
|
def keypress
|
20
21
|
key = input
|
21
22
|
translated = case key
|
@@ -53,9 +54,5 @@ module Vedeu
|
|
53
54
|
|
54
55
|
translated
|
55
56
|
end
|
56
|
-
|
57
|
-
def input
|
58
|
-
@_input ||= Terminal.input
|
59
|
-
end
|
60
57
|
end
|
61
58
|
end
|
data/lib/vedeu/support/menu.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'vedeu'
|
2
|
+
require 'vedeu/support/events'
|
3
3
|
|
4
4
|
module Vedeu
|
5
5
|
class Menu
|
@@ -47,7 +47,7 @@ module Vedeu
|
|
47
47
|
def items
|
48
48
|
items = []
|
49
49
|
@collection.each_with_index do |item, index|
|
50
|
-
if index
|
50
|
+
if index == @current && index == @selected
|
51
51
|
items << [true, true, item]
|
52
52
|
|
53
53
|
elsif index == @current
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'vedeu/models/interface'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
EntityNotFound = Class.new(StandardError)
|
5
|
+
|
6
|
+
module Persistence
|
7
|
+
extend self
|
8
|
+
|
9
|
+
def update(name, attributes = {})
|
10
|
+
interface = query(name)
|
11
|
+
interface.attributes = attributes
|
12
|
+
interface
|
13
|
+
rescue EntityNotFound
|
14
|
+
create(attributes)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(attributes)
|
18
|
+
storage.store(attributes[:name], Interface.new(attributes))
|
19
|
+
end
|
20
|
+
|
21
|
+
def query(value)
|
22
|
+
return false if value.nil? || value.empty?
|
23
|
+
|
24
|
+
storage.select do |name, result|
|
25
|
+
return result if name == value
|
26
|
+
end
|
27
|
+
|
28
|
+
fail EntityNotFound, "Interface could not be found."
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset
|
32
|
+
@storage = {}
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def storage
|
38
|
+
@storage ||= {}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|