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
@@ -0,0 +1,21 @@
1
+ module Vedeu
2
+ class Events
3
+ def initialize
4
+ @handlers = Hash.new { |h, k| h[k] = [] }
5
+ end
6
+
7
+ def on(event, &block)
8
+ handlers[event] << block
9
+ end
10
+
11
+ def trigger(event, *args)
12
+ handlers[event].each do |handler|
13
+ handler.call(*args)
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ attr_accessor :handlers
20
+ end
21
+ end
@@ -0,0 +1,66 @@
1
+ require_relative 'esc'
2
+ require_relative 'terminal'
3
+
4
+ module Vedeu
5
+ class Geometry
6
+ def self.origin(interface, index = 0)
7
+ new(interface, index).origin
8
+ end
9
+
10
+ def initialize(interface, index = 0)
11
+ @interface, @index = interface, index
12
+ end
13
+
14
+ def origin
15
+ Esc.set_position(virtual_y(index), virtual_x)
16
+ end
17
+
18
+ def virtual_x(index = 0)
19
+ ((x..max_x).to_a)[index]
20
+ end
21
+
22
+ def virtual_y(index = 0)
23
+ ((y..max_y).to_a)[index]
24
+ end
25
+
26
+ def max_y
27
+ if ((y + height) > Terminal.height)
28
+ Terminal.height
29
+
30
+ else
31
+ (y + height)
32
+
33
+ end
34
+ end
35
+
36
+ def max_x
37
+ if ((x + width) > Terminal.width)
38
+ Terminal.width
39
+
40
+ else
41
+ (x + width)
42
+
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ attr_reader :interface, :index
49
+
50
+ def height
51
+ interface.height
52
+ end
53
+
54
+ def width
55
+ interface.width
56
+ end
57
+
58
+ def x
59
+ interface.x
60
+ end
61
+
62
+ def y
63
+ interface.y
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,27 @@
1
+ require 'oj'
2
+
3
+ require_relative '../models/composition'
4
+
5
+ module Vedeu
6
+ class Parser
7
+ def self.parse(output)
8
+ new(output).parse
9
+ end
10
+
11
+ def initialize(output)
12
+ @output = output || ''
13
+ end
14
+
15
+ def parse
16
+ Composition.new(as_hash)
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :output
22
+
23
+ def as_hash
24
+ Oj.load(output, symbol_keys: true)
25
+ end
26
+ end
27
+ end
@@ -1,154 +1,51 @@
1
- module Vedeu
2
- class Terminal
3
- class << self
4
- def input
5
- console.gets.chomp
6
- end
7
-
8
- def output(stream = '')
9
- console.print(stream)
10
-
11
- stream
12
- end
13
-
14
- def width
15
- size.last
16
- end
17
-
18
- def height
19
- size.first
20
- end
21
-
22
- def size
23
- console.winsize
24
- end
25
-
26
- def open(options = {}, &block)
27
- new(options).open(&block)
28
- end
29
-
30
- def close
31
- show_cursor
32
-
33
- reset_colours
34
-
35
- reset_position
36
- end
37
-
38
- # :nocov:
39
- def cooked(instance, &block)
40
- console.cooked do
41
- instance.initial_setup!
42
-
43
- yield instance
44
- end if block_given?
45
- end
46
-
47
- def raw(instance, &block)
48
- console.raw do
49
- instance.initial_setup!
50
-
51
- yield instance
52
- end if block_given?
53
- end
54
- # :nocov:
55
-
56
- def console
57
- IO.console
58
- end
59
-
60
- def clear_screen
61
- output(Esc.reset)
62
- output(Esc.clear)
63
- end
64
-
65
- def clear_line(index)
66
- output(Position.set(index, 1) + (' ' * width) + Position.set(index, 1))
67
- end
68
-
69
- def show_cursor
70
- output(Cursor.show)
71
- end
1
+ require 'io/console'
72
2
 
73
- def hide_cursor
74
- output(Cursor.hide)
75
- end
76
-
77
- def reset_colours
78
- output(Esc.reset)
79
- end
80
-
81
- def reset_position
82
- puts
83
-
84
- clear_line(height - 1)
85
- end
86
- end
87
-
88
- def initialize(options = {}, &block)
89
- @options = options || {}
90
-
91
- yield self if block_given?
92
- end
93
-
94
- def open(&block)
95
- terminal_mode(&block).fetch(mode, noop).call
96
- end
97
-
98
- def initial_setup!
99
- Terminal.clear_screen if clear_screen?
100
- set_cursor
101
- Terminal.output(Position.reset)
102
- end
103
-
104
- private
3
+ require_relative '../support/cursor'
4
+ require_relative '../support/esc'
105
5
 
6
+ module Vedeu
7
+ module Terminal
8
+ extend self
106
9
  # :nocov:
107
- def terminal_mode(&block)
108
- {
109
- cooked: proc { Terminal.cooked(self, &block) },
110
- raw: proc { Terminal.raw(self, &block) }
111
- }
112
- end
113
-
114
- def cursor_mode
115
- {
116
- show: proc { Terminal.show_cursor },
117
- hide: proc { Terminal.hide_cursor }
118
- }
10
+ def open(&block)
11
+ console.cooked do
12
+ output Esc.reset
13
+ output Esc.clear
14
+ output Cursor.hide
15
+
16
+ yield
17
+ end if block_given?
18
+ ensure
19
+ output Cursor.show
20
+ output Esc.reset
21
+ output Esc.clear_last_line
119
22
  end
120
23
  # :nocov:
121
24
 
122
- def set_cursor
123
- cursor_mode.fetch(cursor).call
25
+ def input
26
+ console.gets.chomp
124
27
  end
125
28
 
126
- def cursor
127
- options.fetch(:cursor)
128
- end
29
+ def output(stream = '')
30
+ console.print(stream)
129
31
 
130
- def mode
131
- options.fetch(:mode)
32
+ stream
132
33
  end
133
34
 
134
- def clear_screen?
135
- options.fetch(:clear)
35
+ def width
36
+ size.last
136
37
  end
137
38
 
138
- def noop
139
- proc {}
39
+ def height
40
+ size.first
140
41
  end
141
42
 
142
- def options
143
- defaults.merge!(@options)
43
+ def size
44
+ console.winsize
144
45
  end
145
46
 
146
- def defaults
147
- {
148
- mode: :cooked, # or :raw
149
- clear: true, # or false (clears the screen if true)
150
- cursor: :show, # or :hide
151
- }
47
+ def console
48
+ IO.console
152
49
  end
153
50
  end
154
51
  end
@@ -1,17 +1,15 @@
1
1
  module Vedeu
2
2
  class Translator
3
- class << self
4
- def translate(html_colour = nil)
5
- new(html_colour).translate
6
- end
3
+ def self.translate(html_colour = '')
4
+ new(html_colour).translate
7
5
  end
8
6
 
9
- def initialize(html_colour = nil)
10
- @html_colour = html_colour
7
+ def initialize(html_colour = '')
8
+ @html_colour = html_colour || ''
11
9
  end
12
10
 
13
11
  def translate
14
- return unless valid?
12
+ return '' unless valid?
15
13
  [16, red, green, blue].inject(:+)
16
14
  end
17
15
 
@@ -32,7 +30,13 @@ module Vedeu
32
30
  end
33
31
 
34
32
  def valid?
35
- html_colour && valid_type? && valid_format?
33
+ present? && valid_type? && valid_format?
34
+ end
35
+
36
+ def present?
37
+ return true unless html_colour.nil? || html_colour.empty?
38
+
39
+ false
36
40
  end
37
41
 
38
42
  def valid_type?
@@ -1,9 +1,7 @@
1
1
  module Vedeu
2
2
  class Wordwrap
3
- class << self
4
- def this(value, options = {})
5
- new(value, options).reformat
6
- end
3
+ def self.this(value, options = {})
4
+ new(value, options).reformat
7
5
  end
8
6
 
9
7
  def initialize(value, options = {})
data/lib/vedeu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vedeu
2
- VERSION = '0.0.25'
2
+ VERSION = '0.0.26'
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require_relative '../../test_helper'
2
+ require_relative '../../../lib/vedeu/application'
2
3
 
3
4
  module Vedeu
4
5
  describe Application do
@@ -6,8 +7,12 @@ module Vedeu
6
7
  let(:described_instance) { described_class.new(options) }
7
8
  let(:options) { {} }
8
9
 
9
- it 'returns an Application instance' do
10
- described_instance.must_be_instance_of(Application)
10
+ describe '#initialize' do
11
+ let(:subject) { described_class.new(options) }
12
+
13
+ it 'returns an Application instance' do
14
+ subject.must_be_instance_of(Application)
15
+ end
11
16
  end
12
17
 
13
18
  describe '.start' do
@@ -1,4 +1,5 @@
1
1
  require_relative '../../test_helper'
2
+ require_relative '../../../lib/vedeu/configuration'
2
3
 
3
4
  module Vedeu
4
5
  describe Configuration do
@@ -7,16 +8,20 @@ module Vedeu
7
8
  let(:args) { [] }
8
9
  let(:subject) { described_instance }
9
10
 
10
- it 'returns a Configuration instance' do
11
- subject.must_be_instance_of(Configuration)
12
- end
11
+ describe '#initialize' do
12
+ let(:subject) { described_instance }
13
13
 
14
- it 'sets an instance variable' do
15
- subject.instance_variable_get('@args').must_equal([])
16
- end
14
+ it 'returns a Configuration instance' do
15
+ subject.must_be_instance_of(Configuration)
16
+ end
17
17
 
18
- it 'sets an instance variable' do
19
- subject.instance_variable_get('@options').must_equal({})
18
+ it 'sets an instance variable' do
19
+ subject.instance_variable_get('@args').must_equal([])
20
+ end
21
+
22
+ it 'sets an instance variable' do
23
+ subject.instance_variable_get('@options').must_equal({})
24
+ end
20
25
  end
21
26
 
22
27
  describe '#configure' do
@@ -1,4 +1,5 @@
1
1
  require_relative '../../../test_helper'
2
+ require_relative '../../../../lib/vedeu/input/input'
2
3
 
3
4
  module Vedeu
4
5
  describe Input do
@@ -17,7 +18,7 @@ module Vedeu
17
18
  subject.must_be_instance_of(Array)
18
19
  end
19
20
 
20
- it 'returns the enqueue input' do
21
+ it 'returns the enqueued input' do
21
22
  subject.must_equal([input])
22
23
  end
23
24
  end
@@ -1,4 +1,5 @@
1
1
  require_relative '../../test_helper'
2
+ require_relative '../../../lib/vedeu/launcher'
2
3
 
3
4
  module Vedeu
4
5
  describe Launcher do
@@ -8,8 +9,12 @@ module Vedeu
8
9
 
9
10
  before { Application.stubs(:start) }
10
11
 
11
- it 'returns a Launcher instance' do
12
- described_instance.must_be_instance_of(Launcher)
12
+ describe '#initialize' do
13
+ let(:subject) { described_class.new(argv) }
14
+
15
+ it 'returns a Launcher instance' do
16
+ subject.must_be_instance_of(Launcher)
17
+ end
13
18
  end
14
19
 
15
20
  describe '#execute!' do