vedeu 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu.rb +0 -18
  3. data/lib/vedeu/output/colour.rb +18 -7
  4. data/lib/vedeu/output/compositor.rb +20 -8
  5. data/lib/vedeu/process/process.rb +1 -5
  6. data/lib/vedeu/repository/command.rb +12 -0
  7. data/lib/vedeu/repository/command_repository.rb +10 -2
  8. data/lib/vedeu/repository/dummy_command.rb +2 -0
  9. data/lib/vedeu/repository/dummy_interface.rb +3 -1
  10. data/lib/vedeu/repository/interface.rb +31 -4
  11. data/lib/vedeu/repository/interface_repository.rb +5 -1
  12. data/lib/vedeu/repository/storage.rb +1 -1
  13. data/lib/vedeu/support/terminal.rb +13 -3
  14. data/lib/vedeu/version.rb +1 -1
  15. data/test/lib/vedeu/application_test.rb +6 -2
  16. data/test/lib/vedeu/launcher_test.rb +3 -1
  17. data/test/lib/vedeu/output/background_test.rb +30 -10
  18. data/test/lib/vedeu/output/colour_test.rb +39 -2
  19. data/test/lib/vedeu/output/compositor_test.rb +48 -14
  20. data/test/lib/vedeu/output/directive_test.rb +24 -8
  21. data/test/lib/vedeu/output/esc_test.rb +48 -16
  22. data/test/lib/vedeu/output/foreground_test.rb +30 -10
  23. data/test/lib/vedeu/output/geometry_test.rb +78 -28
  24. data/test/lib/vedeu/output/position_test.rb +9 -3
  25. data/test/lib/vedeu/output/renderer_test.rb +15 -5
  26. data/test/lib/vedeu/output/style_test.rb +30 -10
  27. data/test/lib/vedeu/output/translator_test.rb +3 -1
  28. data/test/lib/vedeu/process/event_loop_test.rb +12 -4
  29. data/test/lib/vedeu/process/exit_test.rb +6 -2
  30. data/test/lib/vedeu/process/input_test.rb +9 -3
  31. data/test/lib/vedeu/process/output_test.rb +12 -4
  32. data/test/lib/vedeu/process/process_test.rb +24 -8
  33. data/test/lib/vedeu/process/queue_test.rb +32 -8
  34. data/test/lib/vedeu/repository/command_repository_test.rb +27 -9
  35. data/test/lib/vedeu/repository/command_test.rb +33 -9
  36. data/test/lib/vedeu/repository/dummy_command_test.rb +9 -3
  37. data/test/lib/vedeu/repository/interface_repository_test.rb +18 -6
  38. data/test/lib/vedeu/repository/interface_test.rb +39 -11
  39. data/test/lib/vedeu/repository/repository_test.rb +24 -8
  40. data/test/lib/vedeu/repository/storage_test.rb +39 -2
  41. data/test/lib/vedeu/support/terminal_test.rb +68 -16
  42. data/test/lib/vedeu/version_test.rb +3 -1
  43. data/test/test_helper.rb +3 -0
  44. data/vedeu.gemspec +13 -12
  45. metadata +45 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5988a18730b25eaf5cf4d1d81eb2adc7dd5823ce
4
- data.tar.gz: 607c8b139e80f23ae5f5c0af7cbd883d07c46358
3
+ metadata.gz: 9004c0f8249a525a00f5eb27c74e1d7c72be119f
4
+ data.tar.gz: de9a255d0e475877fadfe2c755a5f726d4bb1d80
5
5
  SHA512:
6
- metadata.gz: 822d36a8a6d63c97b6525a5718dfa7216052d56fca170e5a07d3d8b90378afa3cf937792991aa78cd8126c5b39203ab14d323dacbe2de90729d708714a696a23
7
- data.tar.gz: 51d17fa0372246e206f870fad75ac3c3075b14a7d996dd46c477190e8cacefd478ab5f40faf1c2699e8bd714d1a11e8a951844f0bf5ba3be1ddc81f4de5bc8b1
6
+ metadata.gz: 23dccec8e0aea41ba6a14ef913d38ed03107b114410ab72515c09df036f9aa380262a713a194738bc7a0eec9d6221f7761b44d1edc9f27838f83419dd54d490f
7
+ data.tar.gz: e10078ccce18521f6780ead1606ce58893ac724cbf029bdfe10a8a76cfd91c2dcd066603219950a5385a74f5dd5367507561ba4eb8fb54b37ee55ac777fd3ee2
@@ -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|
@@ -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
- private
21
-
22
- attr_reader :pair
25
+ def reset
26
+ [foreground(:default), background(:default)].join
27
+ end
23
28
 
24
- def foreground
25
- Foreground.escape_sequence(pair[0])
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(pair[1])
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
- output.map do |line|
33
- line.each_with_index do |stream, index|
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
- target_interface.geometry
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) unless not_found?
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,5 +1,7 @@
1
1
  module Vedeu
2
2
  class DummyCommand
3
+ attr_accessor :id
4
+
3
5
  def self.dispatch(value = :dummy)
4
6
  value || :dummy
5
7
  end
@@ -1,3 +1,5 @@
1
1
  module Vedeu
2
- class DummyInterface; end
2
+ class DummyInterface
3
+ attr_accessor :id
4
+ end
3
5
  end
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
  class Interface
3
- attr_accessor :id, :attributes, :active, :geometry, :name
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; end
26
+ def initial_state
27
+ Compositor.arrange([Array.new(geometry.height) { '' }], name)
28
+ end
28
29
 
29
30
  def geometry
30
- Geometry.new(@geometry)
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
@@ -20,7 +20,11 @@ module Vedeu
20
20
  end
21
21
 
22
22
  def find_by_name(value)
23
- query(klass, :name, value)
23
+ interface = query(klass, :name, value)
24
+
25
+ raise UndefinedInterface if interface.nil? || interface.is_a?(Hash)
26
+
27
+ interface
24
28
  end
25
29
 
26
30
  def initial_state
@@ -20,7 +20,7 @@ module Vedeu
20
20
  end
21
21
 
22
22
  def find(klass, id)
23
- map_for_class(klass).fetch(id)
23
+ map_for_class(klass).fetch(id, nil)
24
24
  end
25
25
 
26
26
  def all(klass)
@@ -27,7 +27,10 @@ module Vedeu
27
27
 
28
28
  def close
29
29
  show_cursor
30
- output(Position.set(height - 1, 1))
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, 0))
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)
@@ -1,3 +1,3 @@
1
1
  module Vedeu
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
@@ -6,7 +6,9 @@ module Vedeu
6
6
  let(:described_instance) { described_class.new(options) }
7
7
  let(:options) { {} }
8
8
 
9
- it { described_instance.must_be_instance_of(Application) }
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 { subject.must_be_instance_of(NilClass) }
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 { described_instance.must_be_instance_of(Launcher) }
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 { described_instance.must_be_instance_of(Background) }
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 { subject.must_be_instance_of(String) }
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 { subject.must_be_instance_of(String) }
21
+ it 'returns a String' do
22
+ subject.must_be_instance_of(String)
23
+ end
18
24
 
19
- it { subject.must_equal("\e[48;5;49m") }
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 { subject.must_be_instance_of(String) }
33
+ it 'returns a String' do
34
+ subject.must_be_instance_of(String)
35
+ end
26
36
 
27
- it { subject.must_equal("\e[48;5;41m") }
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 { subject.must_be_instance_of(String) }
45
+ it 'returns a String' do
46
+ subject.must_be_instance_of(String)
47
+ end
34
48
 
35
- it { subject.must_equal("\e[48;5;148m") }
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 { subject.must_be_instance_of(String) }
57
+ it 'returns a String' do
58
+ subject.must_be_instance_of(String)
59
+ end
42
60
 
43
- it { subject.must_equal("\e[48;5;49m") }
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 { described_instance.must_be_instance_of(Colour) }
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 { subject.must_be_instance_of(String) }
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