vedeu 0.0.25 → 0.0.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -9
  3. data/Rakefile +0 -10
  4. data/bin/composition +1 -1
  5. data/examples/single_interface_app.rb +7 -4
  6. data/lib/vedeu.rb +19 -48
  7. data/lib/vedeu/application.rb +8 -7
  8. data/lib/vedeu/configuration.rb +4 -4
  9. data/lib/vedeu/input/input.rb +3 -0
  10. data/lib/vedeu/launcher.rb +3 -0
  11. data/lib/vedeu/models/background.rb +13 -0
  12. data/lib/vedeu/models/coercions.rb +21 -0
  13. data/lib/vedeu/models/colour.rb +22 -0
  14. data/lib/vedeu/{repository → models}/command.rb +2 -0
  15. data/lib/vedeu/models/composition.rb +30 -0
  16. data/lib/vedeu/models/foreground.rb +13 -0
  17. data/lib/vedeu/models/interface.rb +62 -0
  18. data/lib/vedeu/models/interface_collection.rb +24 -0
  19. data/lib/vedeu/models/line.rb +22 -0
  20. data/lib/vedeu/models/line_collection.rb +27 -0
  21. data/lib/vedeu/models/presentation.rb +13 -0
  22. data/lib/vedeu/models/stream.rb +21 -0
  23. data/lib/vedeu/models/stream_collection.rb +27 -0
  24. data/lib/vedeu/models/style_collection.rb +23 -0
  25. data/lib/vedeu/output/interface_renderer.rb +62 -0
  26. data/lib/vedeu/output/output.rb +6 -5
  27. data/lib/vedeu/process/process.rb +15 -31
  28. data/lib/vedeu/repository/command_repository.rb +13 -14
  29. data/lib/vedeu/repository/interface_repository.rb +12 -13
  30. data/lib/vedeu/repository/repository.rb +2 -0
  31. data/lib/vedeu/{output → support}/cursor.rb +2 -0
  32. data/lib/vedeu/support/esc.rb +112 -0
  33. data/lib/vedeu/support/events.rb +21 -0
  34. data/lib/vedeu/support/geometry.rb +66 -0
  35. data/lib/vedeu/support/parser.rb +27 -0
  36. data/lib/vedeu/support/terminal.rb +31 -134
  37. data/lib/vedeu/{output → support}/translator.rb +12 -8
  38. data/lib/vedeu/{output → support}/wordwrap.rb +2 -4
  39. data/lib/vedeu/version.rb +1 -1
  40. data/test/lib/vedeu/application_test.rb +7 -2
  41. data/test/lib/vedeu/configuration_test.rb +13 -8
  42. data/test/lib/vedeu/input/input_test.rb +2 -1
  43. data/test/lib/vedeu/launcher_test.rb +7 -2
  44. data/test/lib/vedeu/models/background_test.rb +35 -0
  45. data/test/lib/vedeu/models/colour_test.rb +71 -0
  46. data/test/lib/vedeu/models/command_test.rb +109 -0
  47. data/test/lib/vedeu/models/composition_test.rb +187 -0
  48. data/test/lib/vedeu/models/foreground_test.rb +35 -0
  49. data/test/lib/vedeu/models/interface_collection_test.rb +57 -0
  50. data/test/lib/vedeu/models/interface_test.rb +220 -0
  51. data/test/lib/vedeu/models/line_collection_test.rb +69 -0
  52. data/test/lib/vedeu/models/line_test.rb +76 -0
  53. data/test/lib/vedeu/models/presentation_test.rb +8 -0
  54. data/test/lib/vedeu/models/stream_collection_test.rb +57 -0
  55. data/test/lib/vedeu/models/stream_test.rb +76 -0
  56. data/test/lib/vedeu/models/style_collection_test.rb +22 -0
  57. data/test/lib/vedeu/output/interface_renderer_test.rb +12 -0
  58. data/test/lib/vedeu/output/output_test.rb +15 -30
  59. data/test/lib/vedeu/process/process_test.rb +22 -44
  60. data/test/lib/vedeu/repository/command_repository_test.rb +22 -16
  61. data/test/lib/vedeu/repository/interface_repository_test.rb +62 -14
  62. data/test/lib/vedeu/repository/repository_test.rb +1 -0
  63. data/test/lib/vedeu/repository/storage_test.rb +13 -6
  64. data/test/lib/vedeu/{output → support}/cursor_test.rb +1 -0
  65. data/test/lib/vedeu/support/esc_test.rb +348 -0
  66. data/test/lib/vedeu/support/events_test.rb +37 -0
  67. data/test/lib/vedeu/support/exit_test.rb +1 -0
  68. data/test/lib/vedeu/support/geometry_test.rb +131 -0
  69. data/test/lib/vedeu/support/parser_test.rb +56 -0
  70. data/test/lib/vedeu/support/queue_test.rb +1 -0
  71. data/test/lib/vedeu/support/terminal_test.rb +1 -119
  72. data/test/lib/vedeu/{output → support}/translator_test.rb +17 -12
  73. data/test/lib/vedeu/{output → support}/wordwrap_test.rb +1 -0
  74. data/test/lib/vedeu/version_test.rb +1 -0
  75. data/test/lib/vedeu_test.rb +1 -0
  76. data/{lib/vedeu/repository → test/support}/dummy_command.rb +0 -0
  77. data/{lib/vedeu/repository → test/support}/dummy_interface.rb +0 -0
  78. data/test/support/json/int1_lin1_str1.json +10 -0
  79. data/test/support/json/int1_lin1_str3.json +18 -0
  80. data/test/support/json/int1_lin2_str1.json +17 -0
  81. data/test/support/json/int1_lin2_str3.json +33 -0
  82. data/test/support/json/int1_lin2_str3_styles.json +43 -0
  83. data/test/support/json/int2_lin1_str1.json +20 -0
  84. data/test/support/json/int2_lin1_str3.json +36 -0
  85. data/test/support/json/int2_lin2_str1.json +34 -0
  86. data/test/support/json/int2_lin2_str3.json +66 -0
  87. data/test/support/json/int2_lin2_str3_styles.json +158 -0
  88. data/test/support/output_1.json +9 -0
  89. data/test/support/output_1.rb +14 -0
  90. data/test/support/output_2.json +1 -0
  91. data/test/support/output_2.rb +19 -0
  92. data/test/test_helper.rb +0 -2
  93. data/vedeu.gemspec +0 -3
  94. metadata +98 -150
  95. data/config/cucumber.yml +0 -8
  96. data/documentation/composition.ebnf +0 -7
  97. data/documentation/diagram/ColourDirective.png +0 -0
  98. data/documentation/diagram/Directive.png +0 -0
  99. data/documentation/diagram/Interface.png +0 -0
  100. data/documentation/diagram/Output.png +0 -0
  101. data/documentation/diagram/PositionDirective.png +0 -0
  102. data/documentation/diagram/Stream.png +0 -0
  103. data/documentation/diagram/StyleDirective.png +0 -0
  104. data/documentation/diagram/rr-1.35.837.png +0 -0
  105. data/documentation/index.html +0 -325
  106. data/features/getting_started.feature +0 -10
  107. data/features/step_definitions/vedeu_steps.rb +0 -11
  108. data/features/support/env.rb +0 -12
  109. data/lib/vedeu/output/background.rb +0 -27
  110. data/lib/vedeu/output/base.rb +0 -57
  111. data/lib/vedeu/output/buffer/composition.rb +0 -24
  112. data/lib/vedeu/output/buffer/formatting.rb +0 -25
  113. data/lib/vedeu/output/buffer/interface.rb +0 -14
  114. data/lib/vedeu/output/buffer/line.rb +0 -14
  115. data/lib/vedeu/output/buffer/stream.rb +0 -14
  116. data/lib/vedeu/output/buffer/style.rb +0 -11
  117. data/lib/vedeu/output/colour.rb +0 -39
  118. data/lib/vedeu/output/compositor.rb +0 -72
  119. data/lib/vedeu/output/directive.rb +0 -63
  120. data/lib/vedeu/output/esc.rb +0 -61
  121. data/lib/vedeu/output/foreground.rb +0 -27
  122. data/lib/vedeu/output/geometry.rb +0 -71
  123. data/lib/vedeu/output/layer.rb +0 -9
  124. data/lib/vedeu/output/menu.rb +0 -26
  125. data/lib/vedeu/output/position.rb +0 -35
  126. data/lib/vedeu/output/style.rb +0 -38
  127. data/lib/vedeu/repository/interface.rb +0 -62
  128. data/lib/vedeu/support/json_parser.rb +0 -25
  129. data/lib/vedeu/support/options.rb +0 -4
  130. data/test/lib/vedeu/output/background_test.rb +0 -67
  131. data/test/lib/vedeu/output/base_test.rb +0 -8
  132. data/test/lib/vedeu/output/buffer/composition_test.rb +0 -57
  133. data/test/lib/vedeu/output/buffer/formatting_test.rb +0 -9
  134. data/test/lib/vedeu/output/buffer/interface_test.rb +0 -38
  135. data/test/lib/vedeu/output/buffer/line_test.rb +0 -64
  136. data/test/lib/vedeu/output/buffer/stream_test.rb +0 -61
  137. data/test/lib/vedeu/output/buffer/style_test.rb +0 -8
  138. data/test/lib/vedeu/output/colour_test.rb +0 -104
  139. data/test/lib/vedeu/output/compositor_test.rb +0 -247
  140. data/test/lib/vedeu/output/directive_test.rb +0 -82
  141. data/test/lib/vedeu/output/esc_test.rb +0 -175
  142. data/test/lib/vedeu/output/foreground_test.rb +0 -67
  143. data/test/lib/vedeu/output/geometry_test.rb +0 -190
  144. data/test/lib/vedeu/output/layer_test.rb +0 -35
  145. data/test/lib/vedeu/output/menu_test.rb +0 -13
  146. data/test/lib/vedeu/output/position_test.rb +0 -48
  147. data/test/lib/vedeu/output/style_test.rb +0 -132
  148. data/test/lib/vedeu/repository/command_test.rb +0 -73
  149. data/test/lib/vedeu/repository/dummy_command_test.rb +0 -27
  150. data/test/lib/vedeu/repository/dummy_interface_test.rb +0 -7
  151. data/test/lib/vedeu/repository/interface_test.rb +0 -79
  152. data/test/lib/vedeu/support/json_parser_test.rb +0 -45
  153. data/test/support/composition.json +0 -47
  154. data/test/support/composition.rb +0 -5
  155. data/test/support/composition.xml +0 -36
  156. data/test/support/multi_interface.json +0 -34
  157. data/test/support/single_interface.json +0 -19
@@ -1,27 +0,0 @@
1
- module Vedeu
2
- class Foreground < Base
3
- private
4
-
5
- def custom
6
- '38;5;'
7
- end
8
-
9
- def normal
10
- '38;2;'
11
- end
12
-
13
- def codes
14
- {
15
- black: 30,
16
- red: 31,
17
- green: 32,
18
- yellow: 33,
19
- blue: 34,
20
- magenta: 35,
21
- cyan: 36,
22
- white: 37,
23
- default: 39,
24
- }
25
- end
26
- end
27
- end
@@ -1,71 +0,0 @@
1
- module Vedeu
2
- class Geometry
3
- def initialize(values = {})
4
- @values = values || {}
5
- end
6
-
7
- def origin(index = 0)
8
- Position.set(vy(index), vx)
9
- end
10
-
11
- def y
12
- values[:y]
13
- end
14
-
15
- def x
16
- values[:x]
17
- end
18
-
19
- def width
20
- values[:width]
21
- end
22
-
23
- def height
24
- values[:height]
25
- end
26
-
27
- def dy
28
- clip_y? ? defaults[:height] : (y + height)
29
- end
30
-
31
- def dx
32
- clip_x? ? defaults[:width] : (x + width)
33
- end
34
-
35
- def vx(index = 0) # virtual x position
36
- ((x..dx).to_a)[index]
37
- end
38
-
39
- def vy(index = 0) # virtual y position
40
- ((y..dy).to_a)[index]
41
- end
42
-
43
- private
44
-
45
- def clip_y?
46
- ((y + height) > defaults[:height])
47
- end
48
-
49
- def clip_x?
50
- ((x + width) > defaults[:width])
51
- end
52
-
53
- def values
54
- defaults.merge!(auto)
55
- end
56
-
57
- def auto
58
- @values.delete_if { |k, v| k == :width && v == :auto }
59
- @values.delete_if { |k, v| k == :height && v == :auto }
60
- end
61
-
62
- def defaults
63
- {
64
- width: Terminal.width,
65
- height: Terminal.height,
66
- y: 1,
67
- x: 1
68
- }
69
- end
70
- end
71
- end
@@ -1,9 +0,0 @@
1
- module Vedeu
2
- class Layer
3
- attr_reader :index
4
-
5
- def initialize(index = 0)
6
- @index = index || 0
7
- end
8
- end
9
- end
@@ -1,26 +0,0 @@
1
- module Vedeu
2
- class Menu
3
- attr_accessor :label, :value
4
-
5
- def initialize(attributes = {})
6
- @attributes = attributes || {}
7
- end
8
-
9
- def label
10
- attributes[:label] || defaults[:label]
11
- end
12
-
13
- def value
14
- attributes[:value] || defaults[:value]
15
- end
16
-
17
- private
18
-
19
- def defaults
20
- {
21
- label: '',
22
- value: ''
23
- }
24
- end
25
- end
26
- end
@@ -1,35 +0,0 @@
1
- module Vedeu
2
- class Position
3
- class << self
4
- def set(y = nil, x = nil)
5
- return '' if y.nil? || x.nil?
6
-
7
- new(y, x).set
8
- end
9
-
10
- def reset
11
- new(1, 1).set
12
- end
13
- end
14
-
15
- def initialize(y = 1, x = 1)
16
- @y, @x = y, x
17
- end
18
-
19
- def set
20
- [Esc.esc, y, ';', x, 'H'].join
21
- end
22
-
23
- private
24
-
25
- attr_accessor :y, :x
26
-
27
- def y
28
- @y == 0 ? 1 : @y
29
- end
30
-
31
- def x
32
- @x == 0 ? 1 : @x
33
- end
34
- end
35
- end
@@ -1,38 +0,0 @@
1
- module Vedeu
2
- class Style
3
- class << self
4
- def set(style)
5
- new(style).set
6
- end
7
- end
8
-
9
- def initialize(style)
10
- @style = style
11
- end
12
-
13
- def set
14
- case style
15
- when :blink then Esc.blink
16
- when :blink_off then Esc.blink_off
17
- when :bold then Esc.bold
18
- when :bold_off then Esc.bold_off
19
- when :clear then Esc.clear
20
- when :hide_cursor then Cursor.hide
21
- when :negative then Esc.negative
22
- when :positive then Esc.positive
23
- when :reset then Esc.reset
24
- when :normal then Esc.normal
25
- when :dim then Esc.dim
26
- when :show_cursor then Cursor.show
27
- when :underline then Esc.underline
28
- when :underline_off then Esc.underline_off
29
- else
30
- ''
31
- end
32
- end
33
-
34
- private
35
-
36
- attr_reader :style
37
- end
38
- end
@@ -1,62 +0,0 @@
1
- module Vedeu
2
- class Interface
3
- include Queue
4
-
5
- attr_accessor :attributes, :name, :cursor, :current
6
-
7
- def initialize(attributes = {})
8
- @attributes = attributes || {}
9
- @name = attributes[:name]
10
- @cursor = attributes.fetch(:cursor, true)
11
- @current = []
12
- end
13
-
14
- # :nocov:
15
- def refresh
16
- if enqueued?
17
- @current = dequeue
18
- elsif @current.empty?
19
- Compositor.arrange(initial_state)
20
-
21
- @current = dequeue
22
- else
23
- @current
24
- end
25
- end
26
- # :nocov:
27
-
28
- def geometry
29
- @geometry ||= Geometry.new(attributes)
30
- end
31
-
32
- def colour
33
- @colour ||= Colour.new([foreground, background])
34
- end
35
-
36
- def cursor
37
- @cursor ? Cursor.show : Cursor.hide
38
- end
39
-
40
- def layer
41
- @layer ||= Layer.new(layer_attr).index
42
- end
43
-
44
- private
45
-
46
- def initial_state
47
- { name => Array.new(geometry.height) { [{ text: '' }] } }
48
- end
49
-
50
- def layer_attr
51
- attributes.fetch(:layer, 0)
52
- end
53
-
54
- def foreground
55
- attributes[:fg] || attributes[:foreground]
56
- end
57
-
58
- def background
59
- attributes[:bg] || attributes[:background]
60
- end
61
- end
62
- end
@@ -1,25 +0,0 @@
1
- module Vedeu
2
- class JSONParser
3
- class << self
4
- def parse(json = '')
5
- new(json).parse
6
- end
7
- end
8
-
9
- def initialize(json = '')
10
- @json = json || ''
11
- end
12
-
13
- def parse
14
- Buffer::Composition.new(as_hash)
15
- end
16
-
17
- private
18
-
19
- attr_reader :json
20
-
21
- def as_hash
22
- Oj.load(json)
23
- end
24
- end
25
- end
@@ -1,4 +0,0 @@
1
- module Vedeu
2
- class Options
3
- end
4
- end
@@ -1,67 +0,0 @@
1
- require_relative '../../../test_helper'
2
-
3
- module Vedeu
4
- describe Background do
5
- let(:described_class) { Background }
6
- let(:described_instance) { described_class.new(colour) }
7
- let(:colour) {}
8
-
9
- it 'returns a Background instance' do
10
- described_instance.must_be_instance_of(Background)
11
- end
12
-
13
- describe '#escape_sequence' do
14
- let(:subject) { described_instance.escape_sequence }
15
-
16
- it 'returns a String' do
17
- subject.must_be_instance_of(String)
18
- end
19
-
20
- context 'with no colour' do
21
- it 'returns a String' do
22
- subject.must_be_instance_of(String)
23
- end
24
-
25
- it 'returns an escape sequence' do
26
- subject.must_equal("\e[48;2;49m")
27
- end
28
- end
29
-
30
- context 'with a named colour' do
31
- let(:colour) { :red }
32
-
33
- it 'returns a String' do
34
- subject.must_be_instance_of(String)
35
- end
36
-
37
- it 'returns an escape sequence' do
38
- subject.must_equal("\e[48;2;41m")
39
- end
40
- end
41
-
42
- context 'with a html colour' do
43
- let(:colour) { '#aadd00' }
44
-
45
- it 'returns a String' do
46
- subject.must_be_instance_of(String)
47
- end
48
-
49
- it 'returns an escape sequence' do
50
- subject.must_equal("\e[48;5;148m")
51
- end
52
- end
53
-
54
- context 'with a default colour' do
55
- let(:colour) { :undefined }
56
-
57
- it 'returns a String' do
58
- subject.must_be_instance_of(String)
59
- end
60
-
61
- it 'returns an escape sequence' do
62
- subject.must_equal("\e[48;2;49m")
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,8 +0,0 @@
1
- require_relative '../../../test_helper'
2
-
3
- module Vedeu
4
- describe Base do
5
- let(:described_class) { Base }
6
- let(:described_instance) { described_class.new }
7
- end
8
- end
@@ -1,57 +0,0 @@
1
- require_relative '../../../../test_helper'
2
-
3
- module Vedeu
4
- module Buffer
5
- describe Composition do
6
- let(:described_class) { Composition }
7
- let(:described_instance) { described_class.new(attributes) }
8
- let(:subject) { described_instance }
9
- let(:json) { File.read(Vedeu.root_path + '/test/support/single_interface.json') }
10
- let(:attributes) { Oj.load(json) }
11
-
12
- it 'returns a Composition instance' do
13
- subject.must_be_instance_of(Composition)
14
- end
15
-
16
- it 'has an interface attribute' do
17
- subject.interface.must_be_instance_of(Array)
18
- end
19
-
20
- describe '#to_compositor' do
21
- let(:subject) { described_instance.to_compositor }
22
-
23
- it 'returns a Hash' do
24
- subject.must_be_instance_of(Hash)
25
- end
26
-
27
- it 'returns the composition as a Compositor format' do
28
- subject.must_equal({"dummy"=>[[{:style=>[], :colour=>[]}, {:style=>[:normal], :colour=>[:yellow, :black], :text=>"Some text..."}]]})
29
- end
30
- end
31
-
32
- describe '#to_hash' do
33
- let(:subject) { described_instance.to_hash }
34
-
35
- it 'returns a Hash' do
36
- subject.must_be_instance_of(Hash)
37
- end
38
-
39
- it 'returns the composition as a Hash' do
40
- subject.must_equal({"interface"=>[{"name"=>"dummy", "line"=>[{"style"=>nil, "foreground"=>nil, "background"=>nil, "stream"=>[{"style"=>["normal"], "foreground"=>"yellow", "background"=>"black", "text"=>"Some text..."}]}]}]})
41
- end
42
- end
43
-
44
- describe '#to_json' do
45
- let(:subject) { described_instance.to_json }
46
-
47
- it 'returns a String' do
48
- subject.must_be_instance_of(String)
49
- end
50
-
51
- it 'returns a String' do
52
- subject.must_equal("{\"interface\":[{\"name\":\"dummy\",\"line\":[{\"style\":null,\"foreground\":null,\"background\":null,\"stream\":[{\"style\":[\"normal\"],\"foreground\":\"yellow\",\"background\":\"black\",\"text\":\"Some text...\"}]}]}]}")
53
- end
54
- end
55
- end
56
- end
57
- end