vedeu 0.1.10 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vedeu.rb +2 -10
- data/lib/vedeu/api/api.rb +29 -1
- data/lib/vedeu/api/events.rb +1 -26
- data/lib/vedeu/api/{base.rb → helpers.rb} +1 -18
- data/lib/vedeu/api/interface.rb +16 -3
- data/lib/vedeu/api/line.rb +29 -4
- data/lib/vedeu/api/log.rb +13 -1
- data/lib/vedeu/api/store.rb +0 -4
- data/lib/vedeu/api/stream.rb +29 -2
- data/lib/vedeu/api/view.rb +4 -2
- data/lib/vedeu/models/attributes/attributes.rb +25 -0
- data/lib/vedeu/models/attributes/colour_translator.rb +0 -10
- data/lib/vedeu/models/colour.rb +23 -3
- data/lib/vedeu/models/composition.rb +32 -2
- data/lib/vedeu/models/geometry.rb +38 -22
- data/lib/vedeu/models/interface.rb +57 -12
- data/lib/vedeu/models/line.rb +28 -4
- data/lib/vedeu/models/stream.rb +36 -6
- data/lib/vedeu/output/buffers.rb +8 -4
- data/lib/vedeu/output/clear.rb +1 -3
- data/lib/vedeu/output/render.rb +12 -4
- data/lib/vedeu/support/esc.rb +12 -2
- data/lib/vedeu/support/menu.rb +10 -10
- data/test/lib/vedeu/api/events_test.rb +4 -4
- data/test/lib/vedeu/api/interface_test.rb +9 -9
- data/test/lib/vedeu/api/view_test.rb +1 -1
- data/test/lib/vedeu/models/attributes/{collection_test.rb → attributes_test.rb} +7 -7
- data/test/lib/vedeu/models/geometry_test.rb +0 -65
- data/test/lib/vedeu/models/line_test.rb +29 -4
- data/test/lib/vedeu/models/stream_test.rb +56 -11
- data/test/lib/vedeu/output/render_test.rb +1 -0
- data/vedeu.gemspec +1 -3
- metadata +6 -38
- data/lib/vedeu/models/attributes/background.rb +0 -7
- data/lib/vedeu/models/attributes/collection.rb +0 -11
- data/lib/vedeu/models/attributes/foreground.rb +0 -7
- data/lib/vedeu/models/attributes/interface_collection.rb +0 -13
- data/lib/vedeu/models/attributes/line_collection.rb +0 -9
- data/lib/vedeu/models/attributes/stream_collection.rb +0 -9
- data/lib/vedeu/models/style.rb +0 -15
- data/test/lib/vedeu/models/attributes/interface_collection_test.rb +0 -40
- data/test/lib/vedeu/models/attributes/line_collection_test.rb +0 -25
- data/test/lib/vedeu/models/attributes/stream_collection_test.rb +0 -23
- data/test/lib/vedeu/models/style_test.rb +0 -48
- data/test/support/bench.rb +0 -34
- data/test/support/colours.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da7db44d3fbb1a694c60eb4a8112015a79fa0f4e
|
4
|
+
data.tar.gz: a132a4ac6eff1b1a4d12684837ce72edf667ec77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cfc8f7d4de135c80242b489e3bfb04ed627896c2fc945380dbc7c1c54c85a17792430fbd0a68ecf9734589819ab3f27c83121feeee0cfe895a0228896c894ad
|
7
|
+
data.tar.gz: 58e58be65d0e522abb67d542f1a7f390c8663fb80748664a9d5b7fe248307ea8b378bc77d79d727af585f2a4d03cb9bc2f0c51e8bbe70b30b0cb41bffbeb020f
|
data/lib/vedeu.rb
CHANGED
@@ -13,12 +13,10 @@ require 'io/console'
|
|
13
13
|
require 'logger'
|
14
14
|
require 'optparse'
|
15
15
|
|
16
|
-
require 'virtus'
|
17
|
-
|
18
16
|
require 'vedeu/api/api'
|
19
|
-
require 'vedeu/api/base'
|
20
17
|
require 'vedeu/api/events'
|
21
18
|
require 'vedeu/api/grid'
|
19
|
+
require 'vedeu/api/helpers'
|
22
20
|
require 'vedeu/api/interface'
|
23
21
|
require 'vedeu/api/line'
|
24
22
|
require 'vedeu/api/log'
|
@@ -30,18 +28,12 @@ require 'vedeu/application'
|
|
30
28
|
require 'vedeu/configuration'
|
31
29
|
require 'vedeu/launcher'
|
32
30
|
|
33
|
-
require 'vedeu/models/attributes/
|
34
|
-
require 'vedeu/models/attributes/collection'
|
31
|
+
require 'vedeu/models/attributes/attributes'
|
35
32
|
require 'vedeu/models/attributes/colour_translator'
|
36
|
-
require 'vedeu/models/attributes/foreground'
|
37
|
-
require 'vedeu/models/attributes/interface_collection'
|
38
|
-
require 'vedeu/models/attributes/line_collection'
|
39
|
-
require 'vedeu/models/attributes/stream_collection'
|
40
33
|
require 'vedeu/models/composition'
|
41
34
|
require 'vedeu/support/terminal'
|
42
35
|
require 'vedeu/models/geometry'
|
43
36
|
require 'vedeu/models/colour'
|
44
|
-
require 'vedeu/models/style'
|
45
37
|
require 'vedeu/models/interface'
|
46
38
|
require 'vedeu/models/line'
|
47
39
|
require 'vedeu/models/stream'
|
data/lib/vedeu/api/api.rb
CHANGED
@@ -1,7 +1,27 @@
|
|
1
1
|
module Vedeu
|
2
2
|
module API
|
3
|
+
def event(name, delay = 0, &block)
|
4
|
+
Vedeu.events.event(name, delay, &block)
|
5
|
+
end
|
6
|
+
|
7
|
+
def events
|
8
|
+
@events ||= API::Events.new do
|
9
|
+
event(:_exit_) { fail StopIteration }
|
10
|
+
event(:_log_) { |message| Vedeu.log(message) }
|
11
|
+
event(:_mode_switch_) { fail ModeSwitch }
|
12
|
+
event(:_clear_) { Terminal.output(Esc.string('clear')) }
|
13
|
+
event(:_refresh_) { Buffers.refresh_all }
|
14
|
+
|
15
|
+
event(:_keypress_) do |key|
|
16
|
+
trigger(:key, key)
|
17
|
+
trigger(:_log_, (' ' * 42) + "key: #{key}")
|
18
|
+
trigger(:_mode_switch_) if key == :escape
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
3
23
|
def interface(name, &block)
|
4
|
-
API::Interface.
|
24
|
+
API::Interface.create(name, &block)
|
5
25
|
end
|
6
26
|
|
7
27
|
def log(message)
|
@@ -12,6 +32,14 @@ module Vedeu
|
|
12
32
|
# Vedeu::View.render(object)
|
13
33
|
# end
|
14
34
|
|
35
|
+
def trigger(name, *args)
|
36
|
+
Vedeu.events.trigger(name, *args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def use(name)
|
40
|
+
Vedeu::Interface.new(Store.query(name))
|
41
|
+
end
|
42
|
+
|
15
43
|
def view(name, &block)
|
16
44
|
API::View.build(name, &block)
|
17
45
|
end
|
data/lib/vedeu/api/events.rb
CHANGED
@@ -1,30 +1,5 @@
|
|
1
1
|
module Vedeu
|
2
2
|
module API
|
3
|
-
def on(name, delay = 0, &block)
|
4
|
-
Vedeu.events.on(name, delay, &block)
|
5
|
-
end
|
6
|
-
alias_method :event, :on
|
7
|
-
|
8
|
-
def trigger(name, *args)
|
9
|
-
Vedeu.events.trigger(name, *args)
|
10
|
-
end
|
11
|
-
|
12
|
-
def events
|
13
|
-
@events ||= API::Events.new do
|
14
|
-
on(:_exit_) { fail StopIteration }
|
15
|
-
on(:_log_) { |message| Vedeu.log(message) }
|
16
|
-
on(:_mode_switch_) { fail ModeSwitch }
|
17
|
-
on(:_clear_) { Terminal.output(Esc.string('clear')) }
|
18
|
-
on(:_refresh_) { Buffers.refresh_all }
|
19
|
-
|
20
|
-
on(:_keypress_) do |key|
|
21
|
-
trigger(:key, key)
|
22
|
-
trigger(:_log_, (' ' * 42) + "key: #{key}")
|
23
|
-
trigger(:_mode_switch_) if key == :escape
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
3
|
class Events
|
29
4
|
def initialize(&block)
|
30
5
|
@handlers = Hash.new do |hash, key|
|
@@ -43,7 +18,7 @@ module Vedeu
|
|
43
18
|
instance_eval(&block)
|
44
19
|
end
|
45
20
|
|
46
|
-
def
|
21
|
+
def event(event, delay = 0, &block)
|
47
22
|
handlers[event][:events] << block
|
48
23
|
handlers[event][:delay] = delay
|
49
24
|
handlers[event]
|
@@ -1,17 +1,6 @@
|
|
1
1
|
module Vedeu
|
2
2
|
module API
|
3
|
-
|
4
|
-
def self.build(attributes = {}, &block)
|
5
|
-
new(attributes, &block).build
|
6
|
-
end
|
7
|
-
|
8
|
-
def initialize(attributes = {}, &block)
|
9
|
-
@attributes = attributes
|
10
|
-
@self_before_instance_eval = eval('self', block.binding)
|
11
|
-
|
12
|
-
instance_eval(&block)
|
13
|
-
end
|
14
|
-
|
3
|
+
module Helpers
|
15
4
|
def colour(values = {})
|
16
5
|
fail InvalidArgument, '#colour expects a Hash containing :foreground,' \
|
17
6
|
' :background or both.' unless values.is_a?(Hash)
|
@@ -28,12 +17,6 @@ module Vedeu
|
|
28
17
|
|
29
18
|
end
|
30
19
|
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def method_missing(method, *args, &block)
|
35
|
-
@self_before_instance_eval.send method, *args, &block
|
36
|
-
end
|
37
20
|
end
|
38
21
|
end
|
39
22
|
end
|
data/lib/vedeu/api/interface.rb
CHANGED
@@ -6,18 +6,19 @@ module Vedeu
|
|
6
6
|
|
7
7
|
module API
|
8
8
|
class Interface
|
9
|
-
def self.
|
10
|
-
new(name).
|
9
|
+
def self.create(name, &block)
|
10
|
+
new(name).create(&block)
|
11
11
|
end
|
12
12
|
|
13
13
|
def initialize(name)
|
14
14
|
@name = name.to_s
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def create(&block)
|
18
18
|
instance_eval(&block) if block_given?
|
19
19
|
|
20
20
|
stored_attributes = Store.create(attributes)
|
21
|
+
|
21
22
|
interface = Vedeu::Interface.new(stored_attributes)
|
22
23
|
|
23
24
|
Vedeu::Buffers.create(interface)
|
@@ -33,6 +34,18 @@ module Vedeu
|
|
33
34
|
Vedeu.use(value)
|
34
35
|
end
|
35
36
|
|
37
|
+
def cursor(value)
|
38
|
+
attributes[:cursor] = value
|
39
|
+
end
|
40
|
+
|
41
|
+
def delay(value)
|
42
|
+
attributes[:delay] = value
|
43
|
+
end
|
44
|
+
|
45
|
+
def group(value)
|
46
|
+
attributes[:group] = value
|
47
|
+
end
|
48
|
+
|
36
49
|
def x(value)
|
37
50
|
fail XOutOfBounds if x_out_of_bounds?(value)
|
38
51
|
|
data/lib/vedeu/api/line.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
module Vedeu
|
2
2
|
module API
|
3
|
-
class Line
|
3
|
+
class Line
|
4
|
+
include Helpers
|
5
|
+
|
6
|
+
def self.build(attributes = {}, &block)
|
7
|
+
new(attributes, &block).build
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(attributes = {}, &block)
|
11
|
+
@attributes = attributes
|
12
|
+
@self_before_instance_eval = eval('self', block.binding)
|
13
|
+
|
14
|
+
instance_eval(&block)
|
15
|
+
end
|
16
|
+
|
4
17
|
def build
|
5
18
|
attributes
|
6
19
|
end
|
@@ -26,9 +39,21 @@ module Vedeu
|
|
26
39
|
end
|
27
40
|
|
28
41
|
def attributes
|
29
|
-
@_attributes ||=
|
30
|
-
|
31
|
-
|
42
|
+
@_attributes ||= defaults.merge!(@attributes)
|
43
|
+
end
|
44
|
+
|
45
|
+
def defaults
|
46
|
+
{
|
47
|
+
colour: {},
|
48
|
+
style: [],
|
49
|
+
streams: []
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def method_missing(method, *args, &block)
|
56
|
+
@self_before_instance_eval.send method, *args, &block
|
32
57
|
end
|
33
58
|
end
|
34
59
|
end
|
data/lib/vedeu/api/log.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
1
3
|
module Vedeu
|
2
4
|
module API
|
3
5
|
class Log
|
@@ -19,7 +21,17 @@ module Vedeu
|
|
19
21
|
private
|
20
22
|
|
21
23
|
def self.filename
|
22
|
-
|
24
|
+
@_filename ||= directory + '/vedeu.log'
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.directory
|
28
|
+
FileUtils.mkdir_p(path) unless File.directory?(path)
|
29
|
+
|
30
|
+
path
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.path
|
34
|
+
Dir.home + '/.vedeu'
|
23
35
|
end
|
24
36
|
end
|
25
37
|
|
data/lib/vedeu/api/store.rb
CHANGED
data/lib/vedeu/api/stream.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
module Vedeu
|
2
2
|
module API
|
3
|
-
class Stream
|
3
|
+
class Stream
|
4
|
+
include Helpers
|
5
|
+
|
6
|
+
def self.build(attributes = {}, &block)
|
7
|
+
new(attributes, &block).build
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(attributes = {}, &block)
|
11
|
+
@attributes = attributes
|
12
|
+
@self_before_instance_eval = eval('self', block.binding)
|
13
|
+
|
14
|
+
instance_eval(&block)
|
15
|
+
end
|
16
|
+
|
4
17
|
def build
|
5
18
|
attributes
|
6
19
|
end
|
@@ -18,7 +31,21 @@ module Vedeu
|
|
18
31
|
end
|
19
32
|
|
20
33
|
def attributes
|
21
|
-
@_attributes ||=
|
34
|
+
@_attributes ||= defaults.merge!(@attributes)
|
35
|
+
end
|
36
|
+
|
37
|
+
def defaults
|
38
|
+
{
|
39
|
+
colour: {},
|
40
|
+
style: [],
|
41
|
+
text: ''
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def method_missing(method, *args, &block)
|
48
|
+
@self_before_instance_eval.send method, *args, &block
|
22
49
|
end
|
23
50
|
end
|
24
51
|
end
|
data/lib/vedeu/api/view.rb
CHANGED
@@ -14,9 +14,11 @@ module Vedeu
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def build(&block)
|
17
|
-
|
17
|
+
if block_given?
|
18
|
+
@self_before_instance_eval = eval('self', block.binding)
|
18
19
|
|
19
|
-
|
20
|
+
instance_eval(&block)
|
21
|
+
end
|
20
22
|
|
21
23
|
attributes
|
22
24
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Vedeu
|
2
|
+
module Attributes
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def coercer(value, model, key)
|
6
|
+
return [] if value.nil? || value.empty?
|
7
|
+
|
8
|
+
[value].flatten.map do |v|
|
9
|
+
if v.is_a?(model)
|
10
|
+
v
|
11
|
+
|
12
|
+
else
|
13
|
+
model.new(v)
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def coerce_styles(values)
|
20
|
+
return '' if values.nil? || values.empty?
|
21
|
+
|
22
|
+
Array(values).flatten.map { |s| Esc.string(s) }.join
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,9 +1,5 @@
|
|
1
1
|
module Vedeu
|
2
2
|
class ColourTranslator
|
3
|
-
def self.translate(html_colour = '')
|
4
|
-
new(html_colour).value
|
5
|
-
end
|
6
|
-
|
7
3
|
def initialize(html_colour = '')
|
8
4
|
@html_colour = html_colour
|
9
5
|
end
|
@@ -20,12 +16,6 @@ module Vedeu
|
|
20
16
|
["\e[38;5;", translate, 'm'].join
|
21
17
|
end
|
22
18
|
|
23
|
-
def value
|
24
|
-
return '' unless valid?
|
25
|
-
|
26
|
-
translate
|
27
|
-
end
|
28
|
-
|
29
19
|
private
|
30
20
|
|
31
21
|
attr_reader :html_colour
|
data/lib/vedeu/models/colour.rb
CHANGED
@@ -1,12 +1,32 @@
|
|
1
1
|
module Vedeu
|
2
2
|
class Colour
|
3
|
-
|
3
|
+
def initialize(attributes = {})
|
4
|
+
@attributes = attributes
|
5
|
+
end
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
def attributes
|
8
|
+
defaults.merge!(@attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
def foreground
|
12
|
+
@foreground ||= ColourTranslator.new(attributes[:foreground]).foreground
|
13
|
+
end
|
14
|
+
|
15
|
+
def background
|
16
|
+
@background ||= ColourTranslator.new(attributes[:background]).background
|
17
|
+
end
|
7
18
|
|
8
19
|
def to_s
|
9
20
|
foreground + background
|
10
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def defaults
|
26
|
+
{
|
27
|
+
foreground: '',
|
28
|
+
background: ''
|
29
|
+
}
|
30
|
+
end
|
11
31
|
end
|
12
32
|
end
|
@@ -1,11 +1,41 @@
|
|
1
1
|
module Vedeu
|
2
2
|
class Composition
|
3
|
-
|
3
|
+
def initialize(attributes = {})
|
4
|
+
@attributes = attributes
|
5
|
+
end
|
6
|
+
|
7
|
+
def attributes
|
8
|
+
defaults.merge!(@attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
def interfaces
|
12
|
+
@interfaces ||= if _interfaces.nil? || _interfaces.empty?
|
13
|
+
[]
|
14
|
+
|
15
|
+
else
|
16
|
+
[_interfaces].flatten.map do |new_attributes|
|
17
|
+
stored_attributes = API::Store.query(new_attributes[:name])
|
18
|
+
|
19
|
+
Interface.new(stored_attributes.merge!(new_attributes))
|
20
|
+
end
|
4
21
|
|
5
|
-
|
22
|
+
end
|
23
|
+
end
|
6
24
|
|
7
25
|
def to_s
|
8
26
|
interfaces.map(&:to_s).join
|
9
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def _interfaces
|
32
|
+
attributes[:interfaces]
|
33
|
+
end
|
34
|
+
|
35
|
+
def defaults
|
36
|
+
{
|
37
|
+
interfaces: []
|
38
|
+
}
|
39
|
+
end
|
10
40
|
end
|
11
41
|
end
|