vedeu 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vedeu.rb +0 -18
- data/lib/vedeu/output/colour.rb +18 -7
- data/lib/vedeu/output/compositor.rb +20 -8
- data/lib/vedeu/process/process.rb +1 -5
- data/lib/vedeu/repository/command.rb +12 -0
- data/lib/vedeu/repository/command_repository.rb +10 -2
- data/lib/vedeu/repository/dummy_command.rb +2 -0
- data/lib/vedeu/repository/dummy_interface.rb +3 -1
- data/lib/vedeu/repository/interface.rb +31 -4
- data/lib/vedeu/repository/interface_repository.rb +5 -1
- data/lib/vedeu/repository/storage.rb +1 -1
- data/lib/vedeu/support/terminal.rb +13 -3
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/application_test.rb +6 -2
- data/test/lib/vedeu/launcher_test.rb +3 -1
- data/test/lib/vedeu/output/background_test.rb +30 -10
- data/test/lib/vedeu/output/colour_test.rb +39 -2
- data/test/lib/vedeu/output/compositor_test.rb +48 -14
- data/test/lib/vedeu/output/directive_test.rb +24 -8
- data/test/lib/vedeu/output/esc_test.rb +48 -16
- data/test/lib/vedeu/output/foreground_test.rb +30 -10
- data/test/lib/vedeu/output/geometry_test.rb +78 -28
- data/test/lib/vedeu/output/position_test.rb +9 -3
- data/test/lib/vedeu/output/renderer_test.rb +15 -5
- data/test/lib/vedeu/output/style_test.rb +30 -10
- data/test/lib/vedeu/output/translator_test.rb +3 -1
- data/test/lib/vedeu/process/event_loop_test.rb +12 -4
- data/test/lib/vedeu/process/exit_test.rb +6 -2
- data/test/lib/vedeu/process/input_test.rb +9 -3
- data/test/lib/vedeu/process/output_test.rb +12 -4
- data/test/lib/vedeu/process/process_test.rb +24 -8
- data/test/lib/vedeu/process/queue_test.rb +32 -8
- data/test/lib/vedeu/repository/command_repository_test.rb +27 -9
- data/test/lib/vedeu/repository/command_test.rb +33 -9
- data/test/lib/vedeu/repository/dummy_command_test.rb +9 -3
- data/test/lib/vedeu/repository/interface_repository_test.rb +18 -6
- data/test/lib/vedeu/repository/interface_test.rb +39 -11
- data/test/lib/vedeu/repository/repository_test.rb +24 -8
- data/test/lib/vedeu/repository/storage_test.rb +39 -2
- data/test/lib/vedeu/support/terminal_test.rb +68 -16
- data/test/lib/vedeu/version_test.rb +3 -1
- data/test/test_helper.rb +3 -0
- data/vedeu.gemspec +13 -12
- metadata +45 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9004c0f8249a525a00f5eb27c74e1d7c72be119f
|
4
|
+
data.tar.gz: de9a255d0e475877fadfe2c755a5f726d4bb1d80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23dccec8e0aea41ba6a14ef913d38ed03107b114410ab72515c09df036f9aa380262a713a194738bc7a0eec9d6221f7761b44d1edc9f27838f83419dd54d490f
|
7
|
+
data.tar.gz: e10078ccce18521f6780ead1606ce58893ac724cbf029bdfe10a8a76cfd91c2dcd066603219950a5385a74f5dd5367507561ba4eb8fb54b37ee55ac777fd3ee2
|
data/lib/vedeu.rb
CHANGED
@@ -39,24 +39,6 @@ require_relative 'vedeu/launcher'
|
|
39
39
|
require_relative 'vedeu/version'
|
40
40
|
|
41
41
|
module Vedeu
|
42
|
-
module ClassMethods
|
43
|
-
def interface(name, geometry = {})
|
44
|
-
interface_name = name.is_a?(Symbol) ? name.to_s : name
|
45
|
-
|
46
|
-
Interface.create({ name: interface_name, geometry: geometry })
|
47
|
-
end
|
48
|
-
|
49
|
-
def command(name, klass, options = {})
|
50
|
-
command_name = name.is_a?(Symbol) ? name.to_s : name
|
51
|
-
|
52
|
-
Command.create({ name: command_name, klass: klass, options: options })
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.included(receiver)
|
57
|
-
receiver.extend(ClassMethods)
|
58
|
-
end
|
59
|
-
|
60
42
|
def self.logger
|
61
43
|
@logger ||= Logger.new(root_path + '/logs/vedeu.log').tap do |log|
|
62
44
|
log.formatter = proc do |mode, time, prog, msg|
|
data/lib/vedeu/output/colour.rb
CHANGED
@@ -7,6 +7,10 @@ module Vedeu
|
|
7
7
|
new(pair).define
|
8
8
|
end
|
9
9
|
alias_method :set, :define
|
10
|
+
|
11
|
+
def reset
|
12
|
+
new.reset
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
def initialize(pair = [])
|
@@ -16,17 +20,24 @@ module Vedeu
|
|
16
20
|
def define
|
17
21
|
[foreground, background].join
|
18
22
|
end
|
23
|
+
alias_method :set, :define
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
def reset
|
26
|
+
[foreground(:default), background(:default)].join
|
27
|
+
end
|
23
28
|
|
24
|
-
def foreground
|
25
|
-
Foreground.escape_sequence(
|
29
|
+
def foreground(value = pair[0])
|
30
|
+
@foreground ||= Foreground.escape_sequence(value)
|
26
31
|
end
|
32
|
+
alias_method :fg, :foreground
|
27
33
|
|
28
|
-
def background
|
29
|
-
Background.escape_sequence(
|
34
|
+
def background(value = pair[1])
|
35
|
+
@background ||= Background.escape_sequence(value)
|
30
36
|
end
|
37
|
+
alias_method :bg, :background
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_reader :pair
|
31
42
|
end
|
32
43
|
end
|
@@ -29,8 +29,15 @@ module Vedeu
|
|
29
29
|
container = []
|
30
30
|
streams = []
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
container << colour.set
|
33
|
+
|
34
|
+
output.map do |lines|
|
35
|
+
if lines.size < geometry.height
|
36
|
+
remaining = geometry.height - lines.size
|
37
|
+
remaining.times { |i| lines << "" }
|
38
|
+
end
|
39
|
+
|
40
|
+
lines.each_with_index do |stream, index|
|
34
41
|
streams << clear(index)
|
35
42
|
streams << Directive.enact(stream)
|
36
43
|
end
|
@@ -39,6 +46,8 @@ module Vedeu
|
|
39
46
|
streams = []
|
40
47
|
end
|
41
48
|
|
49
|
+
container << colour.reset
|
50
|
+
|
42
51
|
container
|
43
52
|
end
|
44
53
|
|
@@ -50,12 +59,20 @@ module Vedeu
|
|
50
59
|
geometry.origin(index)
|
51
60
|
end
|
52
61
|
|
62
|
+
def height
|
63
|
+
geometry.height
|
64
|
+
end
|
65
|
+
|
53
66
|
def width
|
54
67
|
geometry.width
|
55
68
|
end
|
56
69
|
|
57
70
|
def geometry
|
58
|
-
|
71
|
+
interface.geometry
|
72
|
+
end
|
73
|
+
|
74
|
+
def colour
|
75
|
+
interface.colour
|
59
76
|
end
|
60
77
|
|
61
78
|
def output
|
@@ -63,11 +80,6 @@ module Vedeu
|
|
63
80
|
@output
|
64
81
|
end
|
65
82
|
|
66
|
-
def target_interface
|
67
|
-
raise UndefinedInterface if interface.nil?
|
68
|
-
interface
|
69
|
-
end
|
70
|
-
|
71
83
|
def interface
|
72
84
|
@_interface ||= InterfaceRepository.find_by_name(@interface)
|
73
85
|
end
|
@@ -17,17 +17,13 @@ module Vedeu
|
|
17
17
|
private
|
18
18
|
|
19
19
|
def result
|
20
|
-
@result ||= command.execute(*args)
|
20
|
+
@result ||= command.execute(*args) if command
|
21
21
|
end
|
22
22
|
|
23
23
|
def no_result?
|
24
24
|
result.nil? || result.empty?
|
25
25
|
end
|
26
26
|
|
27
|
-
def not_found?
|
28
|
-
command.nil?
|
29
|
-
end
|
30
|
-
|
31
27
|
def command
|
32
28
|
@command ||= find_by_keypress || find_by_keyword
|
33
29
|
end
|
@@ -29,4 +29,16 @@ module Vedeu
|
|
29
29
|
Proc.new { |*args| attributes[:klass].dispatch(*args) }
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
module ClassMethods
|
34
|
+
def command(name, klass, options = {})
|
35
|
+
command_name = name.is_a?(Symbol) ? name.to_s : name
|
36
|
+
|
37
|
+
Command.create({ name: command_name, klass: klass, options: options })
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.included(receiver)
|
42
|
+
receiver.extend(ClassMethods)
|
43
|
+
end
|
32
44
|
end
|
@@ -4,11 +4,19 @@ module Vedeu
|
|
4
4
|
|
5
5
|
class << self
|
6
6
|
def by_keypress(input)
|
7
|
-
query(klass, :keypress, input)
|
7
|
+
command = query(klass, :keypress, input)
|
8
|
+
|
9
|
+
return nil if command.nil? || command.is_a?(Hash)
|
10
|
+
|
11
|
+
command
|
8
12
|
end
|
9
13
|
|
10
14
|
def by_keyword(input)
|
11
|
-
query(klass, :keyword, input)
|
15
|
+
command = query(klass, :keyword, input)
|
16
|
+
|
17
|
+
return nil if command.nil? || command.is_a?(Hash)
|
18
|
+
|
19
|
+
command
|
12
20
|
end
|
13
21
|
|
14
22
|
def klass
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Vedeu
|
2
2
|
class Interface
|
3
|
-
attr_accessor :id, :attributes, :active, :
|
3
|
+
attr_accessor :id, :attributes, :active, :name
|
4
4
|
|
5
5
|
class << self
|
6
6
|
def create(attributes = {})
|
@@ -12,7 +12,6 @@ module Vedeu
|
|
12
12
|
@attributes = attributes || {}
|
13
13
|
|
14
14
|
@active = false
|
15
|
-
@geometry = attributes[:geometry]
|
16
15
|
@name = attributes[:name]
|
17
16
|
end
|
18
17
|
|
@@ -24,10 +23,38 @@ module Vedeu
|
|
24
23
|
self
|
25
24
|
end
|
26
25
|
|
27
|
-
def initial_state
|
26
|
+
def initial_state
|
27
|
+
Compositor.arrange([Array.new(geometry.height) { '' }], name)
|
28
|
+
end
|
28
29
|
|
29
30
|
def geometry
|
30
|
-
Geometry.new(
|
31
|
+
@geometry ||= Geometry.new(attributes)
|
32
|
+
end
|
33
|
+
|
34
|
+
def colour
|
35
|
+
@colour ||= Colour.new([foreground, background])
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def foreground
|
41
|
+
attributes[:fg] || attributes[:foreground]
|
42
|
+
end
|
43
|
+
|
44
|
+
def background
|
45
|
+
attributes[:bg] || attributes[:background]
|
31
46
|
end
|
32
47
|
end
|
48
|
+
|
49
|
+
module ClassMethods
|
50
|
+
def interface(name, options = {})
|
51
|
+
interface_name = name.is_a?(Symbol) ? name.to_s : name
|
52
|
+
|
53
|
+
Interface.create({ name: interface_name }.merge!(options))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.included(receiver)
|
58
|
+
receiver.extend(ClassMethods)
|
59
|
+
end
|
33
60
|
end
|
@@ -27,7 +27,10 @@ module Vedeu
|
|
27
27
|
|
28
28
|
def close
|
29
29
|
show_cursor
|
30
|
-
|
30
|
+
|
31
|
+
reset_colours
|
32
|
+
|
33
|
+
reset_position
|
31
34
|
end
|
32
35
|
|
33
36
|
def cooked(instance, &block)
|
@@ -58,8 +61,7 @@ module Vedeu
|
|
58
61
|
end
|
59
62
|
|
60
63
|
def clear_line(index)
|
61
|
-
output(Position.set(index,
|
62
|
-
output(" " * width)
|
64
|
+
output(Position.set(index, 1) + (" " * width) + Position.set(index, 1))
|
63
65
|
end
|
64
66
|
|
65
67
|
def show_cursor
|
@@ -69,6 +71,14 @@ module Vedeu
|
|
69
71
|
def hide_cursor
|
70
72
|
output(Esc.hide_cursor)
|
71
73
|
end
|
74
|
+
|
75
|
+
def reset_colours
|
76
|
+
output(Esc.reset)
|
77
|
+
end
|
78
|
+
|
79
|
+
def reset_position
|
80
|
+
clear_line(height - 1)
|
81
|
+
end
|
72
82
|
end
|
73
83
|
|
74
84
|
def initialize(options = {}, &block)
|
data/lib/vedeu/version.rb
CHANGED
@@ -6,7 +6,9 @@ module Vedeu
|
|
6
6
|
let(:described_instance) { described_class.new(options) }
|
7
7
|
let(:options) { {} }
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'returns an Application instance' do
|
10
|
+
described_instance.must_be_instance_of(Application)
|
11
|
+
end
|
10
12
|
|
11
13
|
describe '.start' do
|
12
14
|
let(:subject) { described_class.start(options) }
|
@@ -18,7 +20,9 @@ module Vedeu
|
|
18
20
|
Terminal.stubs(:close)
|
19
21
|
end
|
20
22
|
|
21
|
-
it
|
23
|
+
it 'returns a NilClass' do
|
24
|
+
subject.must_be_instance_of(NilClass)
|
25
|
+
end
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
@@ -8,7 +8,9 @@ module Vedeu
|
|
8
8
|
|
9
9
|
before { Application.stubs(:start) }
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'returns a Launcher instance' do
|
12
|
+
described_instance.must_be_instance_of(Launcher)
|
13
|
+
end
|
12
14
|
|
13
15
|
describe '#execute!' do
|
14
16
|
let(:subject) { described_instance.execute! }
|
@@ -6,41 +6,61 @@ module Vedeu
|
|
6
6
|
let(:described_instance) { described_class.new(colour) }
|
7
7
|
let(:colour) {}
|
8
8
|
|
9
|
-
it
|
9
|
+
it 'returns a Background instance' do
|
10
|
+
described_instance.must_be_instance_of(Background)
|
11
|
+
end
|
10
12
|
|
11
13
|
describe '#escape_sequence' do
|
12
14
|
let(:subject) { described_instance.escape_sequence }
|
13
15
|
|
14
|
-
it
|
16
|
+
it 'returns a String' do
|
17
|
+
subject.must_be_instance_of(String)
|
18
|
+
end
|
15
19
|
|
16
20
|
context 'with no colour' do
|
17
|
-
it
|
21
|
+
it 'returns a String' do
|
22
|
+
subject.must_be_instance_of(String)
|
23
|
+
end
|
18
24
|
|
19
|
-
it
|
25
|
+
it 'returns an escape sequence' do
|
26
|
+
subject.must_equal("\e[48;5;49m")
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
context 'with a named colour' do
|
23
31
|
let(:colour) { :red }
|
24
32
|
|
25
|
-
it
|
33
|
+
it 'returns a String' do
|
34
|
+
subject.must_be_instance_of(String)
|
35
|
+
end
|
26
36
|
|
27
|
-
it
|
37
|
+
it 'returns an escape sequence' do
|
38
|
+
subject.must_equal("\e[48;5;41m")
|
39
|
+
end
|
28
40
|
end
|
29
41
|
|
30
42
|
context 'with a html colour' do
|
31
43
|
let(:colour) { '#aadd00' }
|
32
44
|
|
33
|
-
it
|
45
|
+
it 'returns a String' do
|
46
|
+
subject.must_be_instance_of(String)
|
47
|
+
end
|
34
48
|
|
35
|
-
it
|
49
|
+
it 'returns an escape sequence' do
|
50
|
+
subject.must_equal("\e[48;5;148m")
|
51
|
+
end
|
36
52
|
end
|
37
53
|
|
38
54
|
context 'with a default colour' do
|
39
55
|
let(:colour) { :undefined }
|
40
56
|
|
41
|
-
it
|
57
|
+
it 'returns a String' do
|
58
|
+
subject.must_be_instance_of(String)
|
59
|
+
end
|
42
60
|
|
43
|
-
it
|
61
|
+
it 'returns an escape sequence' do
|
62
|
+
subject.must_equal("\e[48;5;49m")
|
63
|
+
end
|
44
64
|
end
|
45
65
|
end
|
46
66
|
end
|
@@ -4,14 +4,23 @@ module Vedeu
|
|
4
4
|
describe Colour do
|
5
5
|
let(:described_class) { Colour }
|
6
6
|
let(:described_instance) { described_class.new }
|
7
|
+
let(:subject) { described_instance }
|
7
8
|
let(:pair) { [] }
|
8
9
|
|
9
|
-
it
|
10
|
+
it 'returns a Colour instance' do
|
11
|
+
subject.must_be_instance_of(Colour)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'sets an instance variable' do
|
15
|
+
subject.instance_variable_get("@pair").must_equal([])
|
16
|
+
end
|
10
17
|
|
11
18
|
describe '.set' do
|
12
19
|
let(:subject) { described_class.set(pair) }
|
13
20
|
|
14
|
-
it
|
21
|
+
it 'returns a String' do
|
22
|
+
subject.must_be_instance_of(String)
|
23
|
+
end
|
15
24
|
|
16
25
|
context 'when the foreground and background are specified as symbols' do
|
17
26
|
context 'when both the foreground and background is specified' do
|
@@ -63,5 +72,33 @@ module Vedeu
|
|
63
72
|
end
|
64
73
|
end
|
65
74
|
end
|
75
|
+
|
76
|
+
describe '.reset' do
|
77
|
+
let(:subject) { described_class.reset }
|
78
|
+
|
79
|
+
it 'returns a String' do
|
80
|
+
subject.must_be_instance_of(String)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'returns an escape sequence' do
|
84
|
+
subject.must_equal("\e[38;5;39m\e[48;5;49m")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#foreground' do
|
89
|
+
let(:subject) { described_instance.foreground }
|
90
|
+
|
91
|
+
it 'returns a String' do
|
92
|
+
subject.must_be_instance_of(String)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#background' do
|
97
|
+
let(:subject) { described_instance.background }
|
98
|
+
|
99
|
+
it 'returns a String' do
|
100
|
+
subject.must_be_instance_of(String)
|
101
|
+
end
|
102
|
+
end
|
66
103
|
end
|
67
104
|
end
|