vedeu 0.1.13 → 0.1.14
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 -0
- data/lib/vedeu/api/api.rb +9 -1
- data/lib/vedeu/api/composition.rb +29 -0
- data/lib/vedeu/api/interface.rb +4 -4
- data/lib/vedeu/launcher.rb +0 -4
- data/lib/vedeu/models/attributes/colour_translator.rb +9 -69
- data/lib/vedeu/models/colour.rb +2 -4
- data/lib/vedeu/models/interface.rb +11 -1
- data/lib/vedeu/models/store.rb +19 -15
- data/lib/vedeu/output/buffers.rb +35 -40
- data/lib/vedeu/output/clear.rb +2 -2
- data/lib/vedeu/output/render.rb +1 -0
- data/lib/vedeu/output/view.rb +1 -3
- data/lib/vedeu/support/buffer.rb +41 -0
- data/test/lib/vedeu/api/api_test.rb +94 -0
- data/test/lib/vedeu/api/composition_test.rb +72 -0
- data/test/lib/vedeu/api/interface_test.rb +52 -69
- data/test/lib/vedeu/models/attributes/colour_translator_test.rb +12 -12
- data/test/lib/vedeu/models/colour_test.rb +5 -5
- data/test/lib/vedeu/models/composition_test.rb +17 -17
- data/test/lib/vedeu/models/interface_test.rb +10 -9
- data/test/lib/vedeu/models/line_test.rb +6 -14
- data/test/lib/vedeu/models/store_test.rb +2 -2
- data/test/lib/vedeu/models/stream_test.rb +4 -4
- data/test/lib/vedeu/output/buffers_test.rb +9 -100
- data/test/lib/vedeu/output/clear_test.rb +1 -1
- data/test/lib/vedeu/output/render_test.rb +4 -3
- data/test/lib/vedeu/output/view_test.rb +1 -1
- data/test/lib/vedeu/support/buffer_test.rb +35 -0
- data/vedeu.gemspec +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79cbcf71bd0a9c214cd3764d10cfc21e8b6aeffa
|
4
|
+
data.tar.gz: 570893355905af7e58d89e64cc419ee361133dd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d143574721a8b5a0e07eb6fb081c3768fa3c994c28a72303b07f9c1abc3a384262fa8c7abe493dceb5c3069f060b0521c804d1c7cff6bf5864fb2cd9922ba22
|
7
|
+
data.tar.gz: 502eb3bba9db28fc1ca44b1f6cd7dd017c18fc3d1f0ce6783d23b56459d758d3dd9cd0d1fb6dc54448fc13342b001304123b4914b206e43617f437cfa5980967
|
data/lib/vedeu.rb
CHANGED
@@ -25,6 +25,7 @@ require 'vedeu/models/store'
|
|
25
25
|
require 'vedeu/models/stream'
|
26
26
|
|
27
27
|
require 'vedeu/api/api'
|
28
|
+
require 'vedeu/api/composition'
|
28
29
|
require 'vedeu/api/events'
|
29
30
|
require 'vedeu/api/grid'
|
30
31
|
require 'vedeu/api/helpers'
|
@@ -42,6 +43,7 @@ require 'vedeu/output/clear'
|
|
42
43
|
require 'vedeu/output/render'
|
43
44
|
require 'vedeu/output/view'
|
44
45
|
|
46
|
+
require 'vedeu/support/buffer'
|
45
47
|
require 'vedeu/support/position'
|
46
48
|
require 'vedeu/support/esc'
|
47
49
|
require 'vedeu/support/input'
|
data/lib/vedeu/api/api.rb
CHANGED
@@ -42,7 +42,15 @@ module Vedeu
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def view(name, &block)
|
45
|
-
|
45
|
+
{
|
46
|
+
interfaces: [
|
47
|
+
API::Interface.build({ name: name }, &block)
|
48
|
+
]
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def views(&block)
|
53
|
+
API::Composition.build(&block)
|
46
54
|
end
|
47
55
|
|
48
56
|
def width
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Vedeu
|
2
|
+
module API
|
3
|
+
class Composition < Vedeu::Composition
|
4
|
+
def self.build(&block)
|
5
|
+
new(&block).attributes
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(&block)
|
9
|
+
super
|
10
|
+
|
11
|
+
if block_given?
|
12
|
+
@self_before_instance_eval = eval('self', block.binding)
|
13
|
+
|
14
|
+
instance_eval(&block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def view(name, &block)
|
19
|
+
attributes[:interfaces] << Interface.build({ name: name }, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def method_missing(method, *args, &block)
|
25
|
+
@self_before_instance_eval.send(method, *args, &block)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/vedeu/api/interface.rb
CHANGED
@@ -26,10 +26,8 @@ module Vedeu
|
|
26
26
|
|
27
27
|
def define(&block)
|
28
28
|
instance_eval(&block) if block_given?
|
29
|
-
|
30
|
-
|
31
|
-
Vedeu::Buffers.create(interface)
|
32
|
-
interface
|
29
|
+
|
30
|
+
Vedeu::Store.create(attributes)
|
33
31
|
end
|
34
32
|
|
35
33
|
def line(&block)
|
@@ -88,6 +86,8 @@ module Vedeu
|
|
88
86
|
attributes[:style] = value
|
89
87
|
end
|
90
88
|
|
89
|
+
private
|
90
|
+
|
91
91
|
def y_out_of_bounds?(value)
|
92
92
|
value < 1 || value > Terminal.height
|
93
93
|
end
|
data/lib/vedeu/launcher.rb
CHANGED
@@ -18,10 +18,6 @@ module Vedeu
|
|
18
18
|
Application.start(configuration)
|
19
19
|
|
20
20
|
@exit_code = 0
|
21
|
-
# rescue Vedeu::API::InvalidHeight, Vedeu::API::InvalidWidth
|
22
|
-
# Vedeu.error("Cannot run this application.\n " \
|
23
|
-
# "Your terminal window is too small.")
|
24
|
-
|
25
21
|
rescue StandardError => uncaught_exception
|
26
22
|
puts uncaught_exception.message
|
27
23
|
puts uncaught_exception.backtrace.join("\n")
|
@@ -1,34 +1,19 @@
|
|
1
1
|
module Vedeu
|
2
2
|
class ColourTranslator
|
3
|
-
def initialize(html_colour = ''
|
3
|
+
def initialize(html_colour = '')
|
4
4
|
@html_colour = html_colour
|
5
|
-
@options = options
|
6
5
|
end
|
7
6
|
|
8
7
|
def background
|
9
8
|
return '' unless valid?
|
10
9
|
|
11
|
-
|
12
|
-
r, g, b = translate
|
13
|
-
["\e[48;2;", r, ';', g, ';', b, 'm'].join
|
14
|
-
|
15
|
-
else
|
16
|
-
["\e[48;5;", translate, 'm'].join
|
17
|
-
|
18
|
-
end
|
10
|
+
sprintf("\e[48;2;%s;%s;%sm", *translate)
|
19
11
|
end
|
20
12
|
|
21
13
|
def foreground
|
22
14
|
return '' unless valid?
|
23
15
|
|
24
|
-
|
25
|
-
r, g, b = translate
|
26
|
-
["\e[38;2;", r, ';', g, ';', b, 'm'].join
|
27
|
-
|
28
|
-
else
|
29
|
-
["\e[38;5;", translate, 'm'].join
|
30
|
-
|
31
|
-
end
|
16
|
+
sprintf("\e[38;2;%s;%s;%sm", *translate)
|
32
17
|
end
|
33
18
|
|
34
19
|
private
|
@@ -36,60 +21,15 @@ module Vedeu
|
|
36
21
|
attr_reader :html_colour
|
37
22
|
|
38
23
|
def translate
|
39
|
-
|
40
|
-
[
|
41
|
-
|
42
|
-
[
|
43
|
-
|
44
|
-
((red / 51) * 36),
|
45
|
-
((green / 51) * 6),
|
46
|
-
((blue / 51) * 1)
|
47
|
-
].inject(:+)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def red
|
52
|
-
html_colour[1..2].to_i(16)
|
53
|
-
end
|
54
|
-
|
55
|
-
def green
|
56
|
-
html_colour[3..4].to_i(16)
|
57
|
-
end
|
58
|
-
|
59
|
-
def blue
|
60
|
-
html_colour[5..6].to_i(16)
|
24
|
+
[
|
25
|
+
html_colour[1..2].to_i(16),
|
26
|
+
html_colour[3..4].to_i(16),
|
27
|
+
html_colour[5..6].to_i(16)
|
28
|
+
]
|
61
29
|
end
|
62
30
|
|
63
31
|
def valid?
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
def present?
|
68
|
-
return true unless html_colour.nil? || html_colour.empty?
|
69
|
-
|
70
|
-
false
|
71
|
-
end
|
72
|
-
|
73
|
-
def valid_type?
|
74
|
-
html_colour.is_a?(String)
|
75
|
-
end
|
76
|
-
|
77
|
-
def valid_format?
|
78
|
-
html_colour =~ /^#([A-Fa-f0-9]{6})$/
|
79
|
-
end
|
80
|
-
|
81
|
-
def truecolor?
|
82
|
-
options.fetch(:truecolor)
|
83
|
-
end
|
84
|
-
|
85
|
-
def options
|
86
|
-
defaults.merge!(@options)
|
87
|
-
end
|
88
|
-
|
89
|
-
def defaults
|
90
|
-
{
|
91
|
-
truecolor: false
|
92
|
-
}
|
32
|
+
html_colour.is_a?(String) && html_colour =~ /^#([A-Fa-f0-9]{6})$/
|
93
33
|
end
|
94
34
|
end
|
95
35
|
end
|
data/lib/vedeu/models/colour.rb
CHANGED
@@ -9,13 +9,11 @@ module Vedeu
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def foreground
|
12
|
-
@foreground ||= ColourTranslator
|
13
|
-
.new(attributes[:foreground], { truecolor: false }).foreground
|
12
|
+
@foreground ||= ColourTranslator.new(attributes[:foreground]).foreground
|
14
13
|
end
|
15
14
|
|
16
15
|
def background
|
17
|
-
@background ||= ColourTranslator
|
18
|
-
.new(attributes[:background], { truecolor: false }).background
|
16
|
+
@background ||= ColourTranslator.new(attributes[:background]).background
|
19
17
|
end
|
20
18
|
|
21
19
|
def to_s
|
@@ -39,7 +39,13 @@ module Vedeu
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def cursor
|
42
|
-
@cursor ||=
|
42
|
+
@cursor ||= if cursor?
|
43
|
+
Esc.string('show_cursor')
|
44
|
+
|
45
|
+
else
|
46
|
+
Esc.string('hide_cursor')
|
47
|
+
|
48
|
+
end
|
43
49
|
end
|
44
50
|
|
45
51
|
def delay
|
@@ -52,6 +58,10 @@ module Vedeu
|
|
52
58
|
|
53
59
|
private
|
54
60
|
|
61
|
+
def cursor?
|
62
|
+
attributes[:cursor] == true
|
63
|
+
end
|
64
|
+
|
55
65
|
def defaults
|
56
66
|
{
|
57
67
|
name: '',
|
data/lib/vedeu/models/store.rb
CHANGED
@@ -1,25 +1,29 @@
|
|
1
1
|
module Vedeu
|
2
2
|
EntityNotFound = Class.new(StandardError)
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module Store
|
5
|
+
extend self
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
end
|
7
|
+
def create(attributes)
|
8
|
+
storage.store(attributes[:name], attributes)
|
10
9
|
|
11
|
-
|
12
|
-
storage.fetch(name) { fail EntityNotFound, 'Interface was not found.' }
|
13
|
-
end
|
10
|
+
Buffers.create(Interface.new(attributes))
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
storage
|
13
|
+
end
|
14
|
+
|
15
|
+
def query(name)
|
16
|
+
storage.fetch(name) { fail EntityNotFound, 'Interface was not found.' }
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset
|
20
|
+
@storage = {}
|
21
|
+
end
|
18
22
|
|
19
|
-
|
23
|
+
private
|
20
24
|
|
21
|
-
|
22
|
-
|
23
|
-
end
|
25
|
+
def storage
|
26
|
+
@storage ||= {}
|
24
27
|
end
|
28
|
+
end
|
25
29
|
end
|
data/lib/vedeu/output/buffers.rb
CHANGED
@@ -5,66 +5,61 @@ module Vedeu
|
|
5
5
|
extend self
|
6
6
|
|
7
7
|
def create(interface)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
refresh_group(interface.group)
|
18
|
-
end
|
19
|
-
end
|
8
|
+
store(interface.name, Buffer.new({
|
9
|
+
name: interface.name,
|
10
|
+
clear: Clear.call(interface),
|
11
|
+
current: '',
|
12
|
+
group: interface.group,
|
13
|
+
next: ''
|
14
|
+
}))
|
15
|
+
|
16
|
+
create_events(interface.name, interface.group, interface.delay)
|
20
17
|
end
|
21
18
|
|
22
19
|
def enqueue(name, sequence)
|
23
|
-
|
20
|
+
store(name, query(name).enqueue(sequence))
|
24
21
|
end
|
25
22
|
|
26
|
-
def
|
27
|
-
buffers.
|
28
|
-
fail RefreshFailed, 'Cannot refresh non-existent interface.'
|
29
|
-
end
|
23
|
+
def refresh_all
|
24
|
+
buffers.keys.map { |name| refresh(name) }
|
30
25
|
end
|
31
26
|
|
32
|
-
def
|
33
|
-
buffers
|
34
|
-
name if buffer[:group] == group
|
35
|
-
end.compact.map { |name| refresh(name) }
|
27
|
+
def reset
|
28
|
+
@buffers = {}
|
36
29
|
end
|
37
30
|
|
38
|
-
|
39
|
-
data = query(name)
|
40
|
-
|
41
|
-
sequence = if data[:next].any?
|
42
|
-
data[:current] = data[:next].pop
|
31
|
+
private
|
43
32
|
|
44
|
-
|
45
|
-
|
33
|
+
def create_events(name, group, delay)
|
34
|
+
Vedeu.event("_refresh_#{name}_".to_sym, delay) { refresh(name) }
|
46
35
|
|
47
|
-
|
48
|
-
|
36
|
+
Vedeu.event("_refresh_group_#{group}_".to_sym, delay) do
|
37
|
+
refresh_group(group)
|
38
|
+
end unless group.nil? || group.empty?
|
39
|
+
end
|
49
40
|
|
50
|
-
|
51
|
-
|
41
|
+
def query(name)
|
42
|
+
buffers.fetch(name) {
|
43
|
+
fail RefreshFailed, 'Cannot refresh non-existent interface.'
|
44
|
+
}
|
52
45
|
end
|
53
46
|
|
54
|
-
def
|
55
|
-
|
47
|
+
def refresh(name)
|
48
|
+
store(name, query(name).refresh)
|
56
49
|
end
|
57
50
|
|
58
|
-
def
|
59
|
-
|
51
|
+
def refresh_group(group)
|
52
|
+
buffers.select.map do |name, buffer|
|
53
|
+
name if buffer.group == group
|
54
|
+
end.compact.map { |name| refresh(name) }
|
60
55
|
end
|
61
56
|
|
62
|
-
|
57
|
+
def store(name, buffer)
|
58
|
+
buffers.store(name, buffer)
|
59
|
+
end
|
63
60
|
|
64
61
|
def buffers
|
65
|
-
@buffers ||=
|
66
|
-
hash[key] = { current: '', next: [], clear: '', group: '' }
|
67
|
-
end
|
62
|
+
@buffers ||= {}
|
68
63
|
end
|
69
64
|
end
|
70
65
|
end
|
data/lib/vedeu/output/clear.rb
CHANGED
@@ -9,7 +9,7 @@ module Vedeu
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def clear
|
12
|
-
|
12
|
+
rows.inject([colours]) do |line, index|
|
13
13
|
line << interface.origin(index) { ' ' * interface.width }
|
14
14
|
end.join
|
15
15
|
end
|
@@ -22,7 +22,7 @@ module Vedeu
|
|
22
22
|
interface.colour.to_s
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def rows
|
26
26
|
interface.height.times
|
27
27
|
end
|
28
28
|
end
|
data/lib/vedeu/output/render.rb
CHANGED
data/lib/vedeu/output/view.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Vedeu
|
2
|
+
class Buffer
|
3
|
+
attr_reader :clear, :current, :group, :name, :_next
|
4
|
+
|
5
|
+
def initialize(vars)
|
6
|
+
@vars = vars
|
7
|
+
@name = vars.fetch(:name)
|
8
|
+
@clear = vars.fetch(:clear)
|
9
|
+
@current = vars.fetch(:current)
|
10
|
+
@group = vars.fetch(:group)
|
11
|
+
@_next = vars.fetch(:next)
|
12
|
+
end
|
13
|
+
|
14
|
+
def enqueue(sequence)
|
15
|
+
merge({ next: sequence })
|
16
|
+
end
|
17
|
+
|
18
|
+
def refresh
|
19
|
+
sequence = if !_next.empty?
|
20
|
+
merge({ current: _next, next: '' }).current
|
21
|
+
|
22
|
+
elsif current.empty?
|
23
|
+
clear
|
24
|
+
|
25
|
+
else
|
26
|
+
current
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
Terminal.output(sequence)
|
31
|
+
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def merge(vars)
|
38
|
+
Buffer.new(@vars.merge(vars))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|