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,10 +0,0 @@
1
- Feature: Getting Started
2
-
3
- Scenario: Hello World
4
- Given the interface "main" is defined
5
- And the command "hello" is defined
6
- When the input "hello" is entered
7
- Then the output should contain:
8
- """
9
- Hello World!
10
- """
@@ -1,11 +0,0 @@
1
- Given(/^the interface "(.*?)" is defined$/) do |interface|
2
- Vedeu::InterfaceRepository.create({ name: interface, entity: Vedeu::DummyInterface, options: {} })
3
- end
4
-
5
- Given(/^the command "(.*?)" is defined$/) do |command|
6
- Vedeu::CommandRepository.create({ name: command, entity: Vedeu::DummyCommand, options: { keyword: command } })
7
- end
8
-
9
- When(/^the input "(.*?)" is entered$/) do |input|
10
- pending
11
- end
@@ -1,12 +0,0 @@
1
- require 'simplecov'
2
- require 'aruba'
3
- require 'aruba/cucumber'
4
- require 'aruba/in_process'
5
- require 'mocha/api'
6
-
7
- require_relative '../../lib/vedeu.rb'
8
-
9
- class CucumberError < StandardError; end
10
-
11
- Aruba::InProcess.main_class = Vedeu::Launcher
12
- Aruba.process = Aruba::InProcess
@@ -1,27 +0,0 @@
1
- module Vedeu
2
- class Background < Base
3
- private
4
-
5
- def custom
6
- '48;5;'
7
- end
8
-
9
- def normal
10
- '48;2;'
11
- end
12
-
13
- def codes
14
- {
15
- black: 40,
16
- red: 41,
17
- green: 42,
18
- yellow: 43,
19
- blue: 44,
20
- magenta: 45,
21
- cyan: 46,
22
- white: 47,
23
- default: 49,
24
- }
25
- end
26
- end
27
- end
@@ -1,57 +0,0 @@
1
- module Vedeu
2
- class Base
3
- class << self
4
- def escape_sequence(colour = nil)
5
- new(colour).escape_sequence
6
- end
7
- end
8
-
9
- def initialize(colour = nil)
10
- @colour = colour
11
- end
12
-
13
- def escape_sequence
14
- [Esc.esc, prefix, code, suffix].join
15
- end
16
-
17
- private
18
-
19
- attr_reader :colour
20
-
21
- def prefix
22
- named? || default? ? normal : custom
23
- end
24
-
25
- def code
26
- no_colour || named || html || default
27
- end
28
-
29
- def no_colour
30
- default unless colour
31
- end
32
-
33
- def default?
34
- colour.nil? || colour == :default
35
- end
36
-
37
- def named
38
- codes[colour] || codes[:default] if named?
39
- end
40
-
41
- def named?
42
- colour.is_a?(Symbol)
43
- end
44
-
45
- def html
46
- Translator.translate(colour)
47
- end
48
-
49
- def default
50
- codes[:default]
51
- end
52
-
53
- def suffix
54
- 'm'
55
- end
56
- end
57
- end
@@ -1,24 +0,0 @@
1
- module Vedeu
2
- module Buffer
3
- class Composition
4
- include Virtus.model
5
-
6
- attribute :interface, Array[Buffer::Interface]
7
-
8
- def to_compositor
9
- interface.inject({}) do |acc, interface|
10
- acc[interface.name] = interface.to_compositor
11
- acc
12
- end
13
- end
14
-
15
- def to_hash
16
- Oj.load(to_json)
17
- end
18
-
19
- def to_json
20
- Oj.dump(attributes, mode: :compat, circular: true)
21
- end
22
- end
23
- end
24
- end
@@ -1,25 +0,0 @@
1
- module Vedeu
2
- module Buffer
3
- module Formatting
4
- include Virtus.module
5
-
6
- attribute :style, Vedeu::Buffer::Style
7
- attribute :foreground, Symbol
8
- attribute :background, Symbol
9
-
10
- private
11
-
12
- def colour
13
- return [] if foreground.nil? || background.nil?
14
-
15
- [foreground, background]
16
- end
17
-
18
- def styles
19
- return [] if style.nil?
20
-
21
- style
22
- end
23
- end
24
- end
25
- end
@@ -1,14 +0,0 @@
1
- module Vedeu
2
- module Buffer
3
- class Interface
4
- include Virtus.model
5
-
6
- attribute :name, String
7
- attribute :line, Array[Buffer::Line]
8
-
9
- def to_compositor
10
- line.map(&:to_compositor)
11
- end
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module Vedeu
2
- module Buffer
3
- class Line
4
- include Virtus.model
5
- include Formatting
6
-
7
- attribute :stream, Array[Buffer::Stream]
8
-
9
- def to_compositor
10
- [{ style: styles, colour: colour }, *stream.map(&:to_compositor)]
11
- end
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module Vedeu
2
- module Buffer
3
- class Stream
4
- include Virtus.model
5
- include Formatting
6
-
7
- attribute :text, String, default: ''
8
-
9
- def to_compositor
10
- { style: styles, colour: colour, text: text }
11
- end
12
- end
13
- end
14
- end
@@ -1,11 +0,0 @@
1
- module Vedeu
2
- module Buffer
3
- class Style < Virtus::Attribute
4
- def coerce(value)
5
- if value.is_a?(::String) && !value.empty?
6
- value.split(/ /).map(&:to_sym)
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,39 +0,0 @@
1
- module Vedeu
2
- class Colour
3
- class << self
4
- def set(pair = [])
5
- return '' if pair.empty?
6
-
7
- new(pair).set
8
- end
9
-
10
- def reset
11
- new.reset
12
- end
13
- end
14
-
15
- def initialize(pair = [])
16
- @pair = pair || []
17
- end
18
-
19
- def set
20
- [foreground, background].join
21
- end
22
-
23
- def reset
24
- [foreground(:default), background(:default)].join
25
- end
26
-
27
- def foreground(value = pair[0])
28
- @foreground ||= Foreground.escape_sequence(value)
29
- end
30
-
31
- def background(value = pair[1])
32
- @background ||= Background.escape_sequence(value)
33
- end
34
-
35
- private
36
-
37
- attr_reader :pair
38
- end
39
- end
@@ -1,72 +0,0 @@
1
- module Vedeu
2
- class Compositor
3
- class << self
4
- def arrange(output = {})
5
- output.map do |interface, stream|
6
- new({ interface: interface, stream: stream }).arrange
7
- end
8
- end
9
- end
10
-
11
- def initialize(attributes = {})
12
- @attributes = attributes || {}
13
- @interface = attributes[:interface]
14
- @stream = attributes[:stream]
15
- end
16
-
17
- def arrange
18
- interface.enqueue(composition)
19
- end
20
-
21
- private
22
-
23
- attr_reader :attributes, :stream
24
-
25
- def composition
26
- container = []
27
-
28
- pad_stream
29
-
30
- stream.each_with_index do |lines, index|
31
- line = [interface.colour.set, clear(index)]
32
-
33
- lines.each do |data|
34
- line << Directive.enact(interface, data)
35
- end
36
-
37
- line << interface.colour.reset << interface.cursor
38
-
39
- container << line.join
40
- end
41
-
42
- container
43
- end
44
-
45
- def pad_stream
46
- if stream.size < height
47
- remaining = height - stream.size
48
- remaining.times { |i| stream << [{ text: '' }] }
49
- end
50
- end
51
-
52
- def clear(index)
53
- [origin(index), (' ' * width), origin(index)].join
54
- end
55
-
56
- def origin(index)
57
- interface.geometry.origin(index)
58
- end
59
-
60
- def height
61
- interface.geometry.height
62
- end
63
-
64
- def width
65
- interface.geometry.width
66
- end
67
-
68
- def interface
69
- @_interface ||= InterfaceRepository.find(@interface)
70
- end
71
- end
72
- end
@@ -1,63 +0,0 @@
1
- module Vedeu
2
- class InvalidDirective < StandardError; end
3
-
4
- class Directive
5
- class << self
6
- def enact(interface, directives = {})
7
- new(interface, directives).enact
8
- end
9
- end
10
-
11
- def initialize(interface, directives = {})
12
- @interface = interface
13
- @directives = directives || {}
14
- end
15
-
16
- def enact
17
- [set_position, set_colour, set_style, set_text].join
18
- end
19
-
20
- private
21
-
22
- attr_reader :interface, :directives
23
-
24
- def set_position
25
- Position.set(*position)
26
- end
27
-
28
- def set_colour
29
- Colour.set(colour) unless colour.empty?
30
- end
31
-
32
- def set_style
33
- Array(style).map { |s| Style.set(s) }.join
34
- end
35
-
36
- def set_text
37
- Wordwrap.this(text, options)
38
- end
39
-
40
- def position
41
- directives.fetch(:position, [])
42
- end
43
-
44
- def colour
45
- directives.fetch(:colour, [])
46
- end
47
-
48
- def style
49
- directives.fetch(:style, [])
50
- end
51
-
52
- def text
53
- directives.fetch(:text, '')
54
- end
55
-
56
- def options
57
- {
58
- width: interface.geometry.width,
59
- prune: true
60
- }
61
- end
62
- end
63
- end
@@ -1,61 +0,0 @@
1
- module Vedeu
2
- module Esc
3
- extend self
4
-
5
- def blink
6
- [esc, '5m'].join
7
- end
8
-
9
- def blink_off
10
- [esc, '25m'].join
11
- end
12
-
13
- def bold
14
- [esc, '1m'].join
15
- end
16
-
17
- def bold_off
18
- [esc, '21m'].join
19
- end
20
-
21
- def clear
22
- [esc, '2J'].join
23
- end
24
-
25
- def clear_line
26
- [esc, '2K'].join
27
- end
28
-
29
- def esc
30
- [27.chr, '['].join
31
- end
32
-
33
- def negative
34
- [esc, '7m'].join
35
- end
36
-
37
- def positive
38
- [esc, '27m'].join
39
- end
40
-
41
- def normal
42
- [underline_off, bold_off, positive].join
43
- end
44
-
45
- def dim
46
- [esc, '2m'].join
47
- end
48
-
49
- def reset
50
- [esc, '0m'].join
51
- end
52
-
53
- def underline
54
- [esc, '4m'].join
55
- end
56
-
57
- def underline_off
58
- [esc, '24m'].join
59
- end
60
- end
61
- end