vedeu 0.0.36 → 0.0.37

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +38 -3
  3. data/deps.md +269 -0
  4. data/lib/vedeu/application.rb +8 -2
  5. data/lib/vedeu/configuration.rb +8 -0
  6. data/lib/vedeu/models/interface.rb +4 -11
  7. data/lib/vedeu/output/{interface_renderer.rb → clear_interface.rb} +4 -23
  8. data/lib/vedeu/output/render_interface.rb +27 -0
  9. data/lib/vedeu/{support/parsing → parsing}/hash_parser.rb +1 -1
  10. data/lib/vedeu/{support/parsing → parsing}/json_parser.rb +0 -0
  11. data/lib/vedeu/{support → parsing}/parser.rb +3 -3
  12. data/lib/vedeu/{output → parsing}/text_adaptor.rb +0 -0
  13. data/lib/vedeu/process/process.rb +1 -1
  14. data/lib/vedeu/repository/event_repository.rb +2 -4
  15. data/lib/vedeu/support/esc.rb +0 -5
  16. data/lib/vedeu/support/terminal.rb +5 -11
  17. data/test/example_app/bin/app +1 -1
  18. data/test/example_app/lib/app.rb +3 -2
  19. data/test/lib/vedeu/configuration_test.rb +10 -0
  20. data/test/lib/vedeu/models/attributes/collection_test.rb +3 -13
  21. data/test/lib/vedeu/models/attributes/line_collection_test.rb +2 -0
  22. data/test/lib/vedeu/models/stream_test.rb +11 -17
  23. data/test/lib/vedeu/output/{interface_renderer_test.rb → clear_interface_test.rb} +7 -19
  24. data/test/lib/vedeu/output/render_interface_test.rb +27 -0
  25. data/test/lib/vedeu/{support/parsing → parsing}/hash_parser_test.rb +2 -2
  26. data/test/lib/vedeu/{support/parsing → parsing}/json_parser_test.rb +2 -2
  27. data/test/lib/vedeu/{support → parsing}/parser_test.rb +1 -1
  28. data/test/lib/vedeu/{output → parsing}/text_adaptor_test.rb +1 -1
  29. data/test/lib/vedeu/process/process_test.rb +5 -7
  30. data/test/lib/vedeu/{support → repository}/event_repository_test.rb +0 -0
  31. data/test/lib/vedeu/support/esc_test.rb +0 -8
  32. data/test/lib/vedeu/support/queue_test.rb +2 -12
  33. data/test/lib/vedeu/support/terminal_test.rb +10 -6
  34. data/test/stats.sh +29 -0
  35. data/vedeu.gemspec +1 -1
  36. metadata +25 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f601ff87eda4c07701dfc42940bbed9c30879fc3
4
- data.tar.gz: cbf134f3d4aa31bacec4dbc26ac059e4cec15f1b
3
+ metadata.gz: 30086255eba975054c131f5aa42aeff7e4ab4d4c
4
+ data.tar.gz: 338f9940b945d89ee8bc4e21cb068d8e5eccc3b6
5
5
  SHA512:
6
- metadata.gz: 3c4d5ef111d1f43f66c3fa1a4acc31a7066405fa5aed113b7b9fabed117290757d42d7972f847eeb2c009262b2c50a7504ca0f28e8741ec7f27c72ed1754b336
7
- data.tar.gz: 1d663a4f0a1d69cca7abf7aa1f91346bc47be0578fdba37e7627e0df5a8e9109980fc5bc01bd31493f29f9e2ba20ecdbc8adfab4a7cf8581b1ad80060c4c6275
6
+ metadata.gz: df5e8b21200f6197027e7a8430729fea7e1dcf5cfdc757119aedbff3a6179b6a6754fdd4088063980f6881dd650bbd30eeb42f0a732c27e2602fc65725b37f9e
7
+ data.tar.gz: 0bd5207420d3d37e1383d44a8fd88e5dc97bb1f07450f162eee30e0bb0cabd98ece969c59536651ed29f624ab412aa1490faed55399063d920a12997715b2417
data/README.md CHANGED
@@ -29,9 +29,28 @@ Expect proper documentation soon!
29
29
 
30
30
  interface :main, { }
31
31
 
32
- command :exit, { entity: SomeClass,
33
- keypress: 'q',
34
- keyword: 'quit' }
32
+ command :thing, { entity: SomeClass,
33
+ keypress: 't',
34
+ keyword: 'thing' }
35
+
36
+ event :some_event do
37
+ # ...
38
+ end
39
+
40
+ event :other_event do |hash_args, array_args, args|
41
+ # ...
42
+ end
43
+
44
+ event :key do |key|
45
+ case key
46
+ when 'a' then puts "Apple"
47
+ when 'b' then puts "Banana"
48
+ # ...
49
+ when :f1 then run(:some_event)
50
+ when :f2 then
51
+ run(:other_event, { args: here }, [:or, :here], :etc)
52
+ end
53
+ end
35
54
  end
36
55
 
37
56
 
@@ -91,6 +110,22 @@ Referring to the above example, interfaces have a name, and various default attr
91
110
  As above, commands have a name, a class which performs the action
92
111
  (you define this), and they can be invoked with a keypress or a keyword. At this time, Vedeu will call the `.dispatch` method on your class, passing any arguments you originally defined in the command. In the future, both the method called and the arguments could be dynamic.
93
112
 
113
+ ### On Defining Events
114
+
115
+ event :event_name do |arg1, arg2|
116
+
117
+ end
118
+
119
+ One can define events which perform work or trigger other events. Vedeu has 3 built-in events which are namespaced with underscores as to hopefully not cause a collision with events you wish to create:
120
+
121
+ - `:_exit_` when triggered, Vedeu will attempt to exit.
122
+
123
+ - `:_keypress_` triggering this event will cause the triggering of the `key` event; which you should define to 'do things'. If the `escape` key is pressed, then `key` is triggered with the argument `:escape`, also an internal event `_mode_switch_` is triggered.
124
+
125
+ - `:_mode_switch_` when triggered (after the user presses `escape`), Vedeu switches from a "raw mode" terminal to a "cooked mode" terminal. The idea here being that the raw mode is for single keypress actions, whilst cooked mode allows the user to enter more elaborate commands- such as commands with arguments.
126
+
127
+ Note: Overriding or adding additional events to the Vedeu event namespace may cause unpredictable results.
128
+
94
129
 
95
130
  ### Geometry
96
131
 
data/deps.md ADDED
@@ -0,0 +1,269 @@
1
+ ----------------------------------------------------------------------
2
+ By class
3
+ ----------------------------------------------------------------------
4
+
5
+ Application
6
+ Input
7
+ Output
8
+ Process
9
+ Terminal
10
+
11
+ ClearInterface
12
+
13
+ Collection
14
+
15
+ Colour
16
+ Esc
17
+
18
+ Command
19
+
20
+ CommandRepository
21
+ Command
22
+ Repository
23
+
24
+ Composition
25
+ InterfaceCollection
26
+
27
+ Compositor
28
+ Composition
29
+
30
+ Configuration
31
+
32
+ Coordinate
33
+ Esc
34
+ Terminal
35
+
36
+ Esc
37
+ Translator
38
+
39
+ EventRepository
40
+
41
+ Exit
42
+ EventRepository
43
+
44
+ HashParser
45
+ TextAdaptor
46
+
47
+ Input
48
+ EventRepository
49
+ Queue
50
+ Terminal
51
+
52
+ Interface
53
+ ClearInterface
54
+ Coordinate
55
+ LineCollection
56
+ Presentation
57
+ Queue
58
+ RenderInterface
59
+ Style
60
+ Terminal
61
+
62
+ InterfaceCollection
63
+ InterfaceRepository
64
+
65
+ InterfaceRepository
66
+ Interface
67
+ Repository
68
+
69
+ JSONParser
70
+
71
+ Launcher
72
+ Application
73
+ Configuration
74
+
75
+ Line
76
+ Presentation
77
+ StreamCollection
78
+ Style
79
+
80
+ LineCollection
81
+ Collection
82
+ Line
83
+
84
+ Menu
85
+
86
+ Output
87
+ InterfaceRepository
88
+ Terminal
89
+
90
+ Parser
91
+ Compositor
92
+ HashParser
93
+ JSONParser
94
+
95
+ Presentation
96
+ Colour
97
+
98
+ Process
99
+ CommandRepository
100
+ Parser
101
+ Queue
102
+
103
+ Queue
104
+
105
+ RenderInterface
106
+ ClearInterface
107
+
108
+ Repository
109
+ Storage
110
+
111
+ Storage
112
+
113
+ Stream
114
+ Presentation
115
+ Style
116
+
117
+ StreamCollection
118
+ Collection
119
+ Stream
120
+
121
+ Style
122
+ Esc
123
+
124
+ Template
125
+
126
+ Terminal
127
+ Esc
128
+ Application
129
+
130
+ TextAdaptor
131
+
132
+ Translator
133
+
134
+ Wordwrap
135
+
136
+
137
+ ----------------------------------------------------------------------
138
+ Orphans
139
+ ----------------------------------------------------------------------
140
+
141
+ Template - orphaned
142
+ Wordwrap - orphaned
143
+ Menu - orphaned
144
+
145
+ Exit - orphaned
146
+ EventRepository
147
+
148
+
149
+ ----------------------------------------------------------------------
150
+ Grouped
151
+ ----------------------------------------------------------------------
152
+
153
+ Launcher
154
+ Application
155
+ Input
156
+ EventRepository
157
+ Queue
158
+ Terminal
159
+ Esc
160
+ Translator
161
+ Output
162
+ InterfaceRepository
163
+ Interface
164
+ ClearInterface
165
+ Coordinate
166
+ Esc
167
+ Translator
168
+ Terminal
169
+ Esc
170
+ Translator
171
+ LineCollection
172
+ Collection
173
+ Line
174
+ Presentation
175
+ Colour
176
+ Esc
177
+ Translator
178
+ StreamCollection
179
+ Collection
180
+ Stream
181
+ Presentation
182
+ Colour
183
+ Esc
184
+ Translator
185
+ Style
186
+ Esc
187
+ Translator
188
+ Style
189
+ Esc
190
+ Translator
191
+ Presentation
192
+ Colour
193
+ Esc
194
+ Translator
195
+ Queue
196
+ RenderInterface
197
+ ClearInterface
198
+ Style
199
+ Esc
200
+ Translator
201
+ Terminal
202
+ Esc
203
+ Translator
204
+ Repository
205
+ Storage
206
+ Terminal
207
+ Esc
208
+ Translator
209
+ Process
210
+ CommandRepository
211
+ Command
212
+ Repository
213
+ Storage
214
+ Parser
215
+ Compositor
216
+ Composition
217
+ InterfaceCollection
218
+ InterfaceRepository
219
+ Interface
220
+ ClearInterface
221
+ Coordinate
222
+ Esc
223
+ Translator
224
+ Terminal
225
+ Esc
226
+ Translator
227
+ LineCollection
228
+ Collection
229
+ Line
230
+ Presentation
231
+ Colour
232
+ Esc
233
+ Translator
234
+ StreamCollection
235
+ Collection
236
+ Stream
237
+ Presentation
238
+ Colour
239
+ Esc
240
+ Translator
241
+ Style
242
+ Esc
243
+ Translator
244
+ Style
245
+ Esc
246
+ Translator
247
+ Presentation
248
+ Colour
249
+ Esc
250
+ Translator
251
+ Queue
252
+ RenderInterface
253
+ ClearInterface
254
+ Style
255
+ Esc
256
+ Translator
257
+ Terminal
258
+ Esc
259
+ Translator
260
+ Repository
261
+ Storage
262
+ HashParser
263
+ TextAdaptor
264
+ JSONParser
265
+ Queue
266
+ Terminal
267
+ Esc
268
+ Translator
269
+ Configuration
@@ -54,9 +54,15 @@ module Vedeu
54
54
 
55
55
  def interactive
56
56
  loop { yield }
57
- rescue StopIteration
57
+
58
58
  rescue ModeSwitch
59
- Terminal.mode_switch
59
+ if Terminal.raw_mode?
60
+ Application.start({ mode: :cooked })
61
+
62
+ else
63
+ Application.start({ mode: :raw })
64
+
65
+ end
60
66
  end
61
67
 
62
68
  def run_once
@@ -18,6 +18,14 @@ module Vedeu
18
18
  opts.on('-1', '--run-once', 'Run application once.') do
19
19
  @options[:interactive] = false
20
20
  end
21
+
22
+ opts.on('-c', '--cooked', 'Run application in cooked mode.') do
23
+ @options[:mode] = :cooked
24
+ end
25
+
26
+ opts.on('-r', '--raw', 'Run application in raw mode (default).') do
27
+ @options[:mode] = :raw
28
+ end
21
29
  end
22
30
  parser.parse!(args)
23
31
 
@@ -4,7 +4,8 @@ require 'virtus'
4
4
  require_relative 'attributes/line_collection'
5
5
  require_relative 'presentation'
6
6
  require_relative 'style'
7
- require_relative '../output/interface_renderer'
7
+ require_relative '../output/clear_interface'
8
+ require_relative '../output/render_interface'
8
9
  require_relative '../support/coordinate'
9
10
  require_relative '../support/queue'
10
11
  require_relative '../support/terminal'
@@ -40,7 +41,7 @@ module Vedeu
40
41
  self.current = dequeue
41
42
 
42
43
  elsif no_content?
43
- self.current = clear_interface
44
+ self.current = ClearInterface.call(self)
44
45
 
45
46
  else
46
47
  self.current
@@ -64,7 +65,7 @@ module Vedeu
64
65
  end
65
66
 
66
67
  def to_s
67
- clear_interface + render_content
68
+ RenderInterface.call(self)
68
69
  end
69
70
 
70
71
  private
@@ -73,14 +74,6 @@ module Vedeu
73
74
  self.current.nil? || self.current.empty?
74
75
  end
75
76
 
76
- def render_content
77
- InterfaceRenderer.render(self)
78
- end
79
-
80
- def clear_interface
81
- InterfaceRenderer.clear(self)
82
- end
83
-
84
77
  def geometry
85
78
  @_geometry ||= Coordinate.new(attributes)
86
79
  end
@@ -1,13 +1,9 @@
1
1
  module Vedeu
2
- class InterfaceRenderer
3
- def self.clear(interface)
2
+ class ClearInterface
3
+ def self.call(interface)
4
4
  new(interface).clear
5
5
  end
6
6
 
7
- def self.render(interface)
8
- new(interface).render
9
- end
10
-
11
7
  def initialize(interface)
12
8
  @interface = interface
13
9
  end
@@ -16,23 +12,10 @@ module Vedeu
16
12
  set_colour + clear_lines
17
13
  end
18
14
 
19
- def render
20
- out = []
21
- content_lines.each_with_index do |line, index|
22
- out << origin(index)
23
- out << line.to_s
24
- end
25
- out.join
26
- end
27
-
28
15
  private
29
16
 
30
17
  attr_reader :interface
31
18
 
32
- def content_lines
33
- interface.lines
34
- end
35
-
36
19
  def set_colour
37
20
  interface.colour.to_s
38
21
  end
@@ -44,10 +27,8 @@ module Vedeu
44
27
  end
45
28
 
46
29
  def clear_line(index)
47
- origin(index) + (' ' * interface.width) + origin(index)
48
- end
49
-
50
- def origin(index)
30
+ interface.origin(index) +
31
+ (' ' * interface.width) +
51
32
  interface.origin(index)
52
33
  end
53
34
  end
@@ -0,0 +1,27 @@
1
+ require_relative 'clear_interface'
2
+
3
+ module Vedeu
4
+ class RenderInterface
5
+ def self.call(interface)
6
+ new(interface).render
7
+ end
8
+
9
+ def initialize(interface)
10
+ @interface = interface
11
+ end
12
+
13
+ def render
14
+ out = []
15
+ out << ClearInterface.call(interface)
16
+ interface.lines.each_with_index do |line, index|
17
+ out << interface.origin(index)
18
+ out << line.to_s
19
+ end
20
+ out.join
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :interface
26
+ end
27
+ end
@@ -1,4 +1,4 @@
1
- require_relative '../../output/text_adaptor'
1
+ require_relative 'text_adaptor'
2
2
 
3
3
  module Vedeu
4
4
  class HashParser
@@ -1,6 +1,6 @@
1
- require_relative 'compositor'
2
- require_relative 'parsing/hash_parser'
3
- require_relative 'parsing/json_parser'
1
+ require_relative '../support/compositor'
2
+ require_relative 'hash_parser'
3
+ require_relative 'json_parser'
4
4
 
5
5
  module Vedeu
6
6
  class ParseError < StandardError; end
File without changes
@@ -1,6 +1,6 @@
1
1
  require_relative '../repository/command_repository'
2
2
  require_relative '../support/queue'
3
- require_relative '../support/parser'
3
+ require_relative '../parsing/parser'
4
4
 
5
5
  module Vedeu
6
6
  class Process
@@ -1,5 +1,3 @@
1
- require_relative '../support/terminal'
2
-
3
1
  module Vedeu
4
2
  module EventRepository
5
3
  extend self
@@ -29,9 +27,9 @@ module Vedeu
29
27
  end
30
28
 
31
29
  def keypress(key)
32
- trigger(:_mode_switch_) if key == :escape
33
-
34
30
  trigger(:key, key)
31
+
32
+ trigger(:_mode_switch_) if key == :escape
35
33
  end
36
34
  end
37
35
  end
@@ -1,4 +1,3 @@
1
- require_relative 'terminal'
2
1
  require_relative 'translator'
3
2
 
4
3
  module Vedeu
@@ -11,10 +10,6 @@ module Vedeu
11
10
  ["\e[48;5;", colour_translator(value), 'm'].join
12
11
  end
13
12
 
14
- def clear_last_line
15
- set_position((Terminal.height - 1), 1) + "\e[2K"
16
- end
17
-
18
13
  def foreground_colour(value = '#ffffff')
19
14
  return '' if value.empty?
20
15
 
@@ -56,28 +56,22 @@ module Vedeu
56
56
  def restore_screen
57
57
  output Esc.string 'show_cursor'
58
58
  output Esc.string 'reset'
59
- output Esc.clear_last_line
59
+ output clear_last_line
60
60
  end
61
61
 
62
62
  def set_cursor_mode
63
63
  output Esc.string 'show_cursor' unless raw_mode?
64
64
  end
65
65
 
66
- def mode_switch
67
- if raw_mode?
68
- Application.start({ mode: :cooked })
69
-
70
- else
71
- Application.start({ mode: :raw })
72
-
73
- end
74
- end
75
-
76
66
  def raw_mode?
77
67
  @mode == :raw
78
68
  end
79
69
  # :nocov:
80
70
 
71
+ def clear_last_line
72
+ Esc.set_position((height - 1), 1) + "\e[2K"
73
+ end
74
+
81
75
  def centre
82
76
  [(height / 2), (width / 2)]
83
77
  end
@@ -6,4 +6,4 @@ trap('INT') { exit! }
6
6
 
7
7
  require_relative '../lib/app'
8
8
 
9
- Example::App.start
9
+ Example::App.start(ARGV.dup)
@@ -78,12 +78,13 @@ module Example
78
78
  when 'v' then puts "v was pressed."
79
79
  when :f1 then puts "F1 was pressed."
80
80
  when :f2 then run(:some_event, [:args, :go, :here])
81
+ when 'x' then run(:_exit_)
81
82
  else
82
83
  end
83
84
  end
84
85
 
85
- def self.start
86
- Vedeu::Launcher.new([]).execute!
86
+ def self.start(args = [])
87
+ Vedeu::Launcher.new(args).execute!
87
88
  end
88
89
  end
89
90
  end
@@ -12,6 +12,16 @@ module Vedeu
12
12
  Configuration.configure(['--run-once'])
13
13
  .must_equal({ interactive: false })
14
14
  end
15
+
16
+ it 'returns the options which instructs Vedeu to run in cooked mode' do
17
+ Configuration.configure(['--cooked'])
18
+ .must_equal({ mode: :cooked })
19
+ end
20
+
21
+ it 'returns the options which instructs Vedeu to run in raw mode' do
22
+ Configuration.configure(['--raw'])
23
+ .must_equal({ mode: :raw })
24
+ end
15
25
  end
16
26
  end
17
27
  end
@@ -11,19 +11,9 @@ module Vedeu
11
11
  describe Collection do
12
12
  describe '#coercer' do
13
13
  it 'returns an empty collection when nil or empty' do
14
- Collection.coercer(nil, TestClass, :key).must_equal([])
15
- end
16
-
17
- it 'returns an empty collection when nil or empty' do
18
- Collection.coercer('', TestClass, :key).must_equal([])
19
- end
20
-
21
- it 'returns an empty collection when nil or empty' do
22
- Collection.coercer([], TestClass, :key).must_equal([])
23
- end
24
-
25
- it 'returns an empty collection when nil or empty' do
26
- Collection.coercer({}, TestClass, :key).must_equal([])
14
+ [nil, '', [], {}].each do |empty_value|
15
+ Collection.coercer(empty_value, TestClass, :key).must_equal([])
16
+ end
27
17
  end
28
18
 
29
19
  it 'returns a single model in a collection when a String' do
@@ -4,6 +4,8 @@ require_relative '../../../../../lib/vedeu/models/interface'
4
4
 
5
5
  module Vedeu
6
6
  describe LineCollection do
7
+ let(:interface) { Interface.new(attributes) }
8
+
7
9
  describe '#coerce' do
8
10
  it 'returns an empty collection when there are no lines' do
9
11
  Interface.new({ lines: {} }).lines.must_equal([])
@@ -3,31 +3,31 @@ require_relative '../../../../lib/vedeu/models/stream'
3
3
 
4
4
  module Vedeu
5
5
  describe Stream do
6
- it 'has a colour attribute' do
7
- stream = Stream.new({
8
- colour: { foreground: '#ff0000', background: '#000000' }
6
+ let(:stream) {
7
+ Stream.new({
8
+ colour: {
9
+ foreground: '#ff0000',
10
+ background: '#000000'
11
+ },
12
+ text: 'Some text',
13
+ style: 'normal'
9
14
  })
15
+ }
16
+
17
+ it 'has a colour attribute' do
10
18
  stream.colour.must_be_instance_of(Colour)
11
19
  end
12
20
 
13
21
  it 'has a text attribute' do
14
- stream = Stream.new({ text: 'Some text' })
15
22
  stream.text.must_equal('Some text')
16
23
  end
17
24
 
18
25
  it 'has a style attribute' do
19
- stream = Stream.new({ style: 'normal' })
20
26
  stream.style.must_equal("\e[24m\e[21m\e[27m")
21
27
  end
22
28
 
23
29
  describe '#to_s' do
24
30
  it 'returns a String' do
25
- stream = Stream.new({
26
- colour: { foreground: '#ff0000', background: '#000000' },
27
- style: 'normal',
28
- text: 'Some text'
29
- })
30
-
31
31
  stream.to_s.must_equal(
32
32
  "\e[38;5;196m\e[48;5;16m" \
33
33
  "\e[24m\e[21m\e[27m" \
@@ -38,12 +38,6 @@ module Vedeu
38
38
 
39
39
  describe '#to_json' do
40
40
  it 'returns a String' do
41
- stream = Stream.new({
42
- colour: { foreground: '#ff0000', background: '#000000' },
43
- style: 'normal',
44
- text: 'Some text'
45
- })
46
-
47
41
  stream.to_json.must_equal("{\"colour\":{\"foreground\":\"#ff0000\",\"background\":\"#000000\"},\"style\":[\"normal\"],\"text\":\"Some text\"}")
48
42
  end
49
43
  end
@@ -1,20 +1,20 @@
1
1
  require_relative '../../../test_helper'
2
2
  require_relative '../../../../lib/vedeu/repository/interface_repository'
3
- require_relative '../../../../lib/vedeu/output/interface_renderer'
3
+ require_relative '../../../../lib/vedeu/output/clear_interface'
4
4
  require_relative '../../../../lib/vedeu/models/interface'
5
5
 
6
6
  module Vedeu
7
- describe InterfaceRenderer do
7
+ describe ClearInterface do
8
8
  before { InterfaceRepository.reset }
9
9
 
10
- describe '.clear' do
10
+ describe '.call' do
11
11
  it 'returns the escape sequence to clear the whole interface' do
12
12
  interface = Interface.new({
13
- name: '.clear',
13
+ name: 'ClearInterface.call',
14
14
  width: 5,
15
15
  height: 2
16
16
  })
17
- InterfaceRenderer.clear(interface).must_equal(
17
+ ClearInterface.call(interface).must_equal(
18
18
  "\e[1;1H \e[1;1H" \
19
19
  "\e[2;1H \e[2;1H"
20
20
  )
@@ -22,7 +22,7 @@ module Vedeu
22
22
 
23
23
  it 'returns the escape sequence to clear the whole interface with specified colours' do
24
24
  interface = Interface.new({
25
- name: '.clear',
25
+ name: 'ClearInterface.call',
26
26
  width: 5,
27
27
  height: 2,
28
28
  colour: {
@@ -30,24 +30,12 @@ module Vedeu
30
30
  background: '#ffff00'
31
31
  }
32
32
  })
33
- InterfaceRenderer.clear(interface).must_equal(
33
+ ClearInterface.call(interface).must_equal(
34
34
  "\e[38;5;46m\e[48;5;226m" \
35
35
  "\e[1;1H \e[1;1H" \
36
36
  "\e[2;1H \e[2;1H"
37
37
  )
38
38
  end
39
39
  end
40
-
41
- describe '.render' do
42
- it 'returns the content for the interface' do
43
- interface = Interface.new({
44
- name: '.render',
45
- width: 5,
46
- height: 2,
47
- lines: 'InterfaceRenderer.render'
48
- })
49
- InterfaceRenderer.render(interface).must_equal("\e[1;1HInterfaceRenderer.render")
50
- end
51
- end
52
40
  end
53
41
  end
@@ -0,0 +1,27 @@
1
+ require_relative '../../../test_helper'
2
+ require_relative '../../../../lib/vedeu/repository/interface_repository'
3
+ require_relative '../../../../lib/vedeu/output/clear_interface'
4
+ require_relative '../../../../lib/vedeu/output/render_interface'
5
+ require_relative '../../../../lib/vedeu/models/interface'
6
+
7
+ module Vedeu
8
+ describe RenderInterface do
9
+ before { InterfaceRepository.reset }
10
+
11
+ describe '.call' do
12
+ it 'returns the content for the interface' do
13
+ interface = Interface.new({
14
+ name: '.call',
15
+ width: 5,
16
+ height: 2,
17
+ lines: 'RenderInterface.call'
18
+ })
19
+ RenderInterface.call(interface).must_equal(
20
+ "\e[1;1H \e[1;1H" \
21
+ "\e[2;1H \e[2;1H" \
22
+ "\e[1;1HRenderInterface.call"
23
+ )
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
- require_relative '../../../../test_helper'
2
- require_relative '../../../../../lib/vedeu/support/parsing/hash_parser'
1
+ require_relative '../../../test_helper'
2
+ require_relative '../../../../lib/vedeu/parsing/hash_parser'
3
3
 
4
4
  module Vedeu
5
5
  describe HashParser do
@@ -1,5 +1,5 @@
1
- require_relative '../../../../test_helper'
2
- require_relative '../../../../../lib/vedeu/support/parsing/json_parser'
1
+ require_relative '../../../test_helper'
2
+ require_relative '../../../../lib/vedeu/parsing/json_parser'
3
3
 
4
4
  module Vedeu
5
5
  describe JSONParser do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../../test_helper'
2
- require_relative '../../../../lib/vedeu/support/parser'
2
+ require_relative '../../../../lib/vedeu/parsing/parser'
3
3
 
4
4
  module Vedeu
5
5
  describe Parser do
@@ -1,5 +1,5 @@
1
1
  require_relative '../../../test_helper'
2
- require_relative '../../../../lib/vedeu/output/text_adaptor'
2
+ require_relative '../../../../lib/vedeu/parsing/text_adaptor'
3
3
 
4
4
  module Vedeu
5
5
  describe TextAdaptor do
@@ -25,31 +25,31 @@ module Vedeu
25
25
 
26
26
  describe Process do
27
27
  describe '.evaluate' do
28
- it 'returns false when there is no input' do
28
+ before do
29
+ CommandRepository.reset
29
30
  Queue.reset
31
+ end
32
+
33
+ it 'returns false when there is no input' do
30
34
  Process.evaluate.must_be_instance_of(FalseClass)
31
35
  end
32
36
 
33
37
  it 'raises an exception when the result is :stop' do
34
- CommandRepository.reset
35
38
  CommandRepository.create({
36
39
  name: 'quit',
37
40
  entity: QuitCommand,
38
41
  keypress: 'q'
39
42
  })
40
- Queue.reset
41
43
  Queue.enqueue('q')
42
44
  proc { Process.evaluate }.must_raise(StopIteration)
43
45
  end
44
46
 
45
47
  it 'returns a collection of interfaces when there is a result' do
46
- CommandRepository.reset
47
48
  CommandRepository.create({
48
49
  name: 'test',
49
50
  entity: TestCommand,
50
51
  keypress: 't'
51
52
  })
52
- Queue.reset
53
53
  Queue.enqueue('t')
54
54
  evaluation = Process.evaluate
55
55
 
@@ -58,13 +58,11 @@ module Vedeu
58
58
  end
59
59
 
60
60
  it 'returns a NilClass when there is no result' do
61
- CommandRepository.reset
62
61
  CommandRepository.create({
63
62
  name: 'no_result',
64
63
  entity: NoResultCommand,
65
64
  keypress: 'n'
66
65
  })
67
- Queue.reset
68
66
  Queue.enqueue('n')
69
67
  Process.evaluate.must_be_instance_of(NilClass)
70
68
  end
@@ -13,14 +13,6 @@ module Vedeu
13
13
  end
14
14
  end
15
15
 
16
- describe '.clear_last_line' do
17
- it 'returns an escape sequence to clear the last line' do
18
- IO.console.stub :winsize, [25, 25] do
19
- Esc.clear_last_line.must_equal("\e[24;1H\e[2K")
20
- end
21
- end
22
- end
23
-
24
16
  describe '.foreground_colour' do
25
17
  it 'returns an escape sequence' do
26
18
  Esc.foreground_colour.must_equal("\e[38;5;231m")
@@ -3,14 +3,14 @@ require_relative '../../../../lib/vedeu/support/queue'
3
3
 
4
4
  module Vedeu
5
5
  describe Queue do
6
+ before { Queue.reset }
7
+
6
8
  describe '.dequeue' do
7
9
  it 'returns a NilClass when the queue is empty' do
8
- Queue.reset
9
10
  Queue.dequeue.must_be_instance_of(NilClass)
10
11
  end
11
12
 
12
13
  it 'returns the first entry added when the queue is not empty' do
13
- Queue.reset
14
14
  Queue.enqueue(:result)
15
15
  Queue.dequeue.must_be_instance_of(Symbol)
16
16
  end
@@ -18,32 +18,27 @@ module Vedeu
18
18
 
19
19
  describe '.enqueue' do
20
20
  it 'contains the enqueued item' do
21
- Queue.reset
22
21
  Queue.enqueue(:result).size.must_equal(1)
23
22
  end
24
23
  end
25
24
 
26
25
  describe '.enqueued?' do
27
26
  it 'returns true when the queue is not empty' do
28
- Queue.reset
29
27
  Queue.enqueue(:result)
30
28
  Queue.enqueued?.must_be_instance_of(TrueClass)
31
29
  end
32
30
 
33
31
  it 'returns false when the queue is empty' do
34
- Queue.reset
35
32
  Queue.enqueued?.must_be_instance_of(FalseClass)
36
33
  end
37
34
  end
38
35
 
39
36
  describe '.entries' do
40
37
  it 'returns an empty collection when the queue is empty' do
41
- Queue.reset
42
38
  Queue.entries.must_equal([])
43
39
  end
44
40
 
45
41
  it 'returns all the enqueue items when the queue is not empty' do
46
- Queue.reset
47
42
  Queue.enqueue(:queued_entry)
48
43
  Queue.entries.must_equal([:queued_entry])
49
44
  end
@@ -51,12 +46,10 @@ module Vedeu
51
46
 
52
47
  describe '.size' do
53
48
  it 'returns the size of the queue when the queue is empty' do
54
- Queue.reset
55
49
  Queue.size.must_equal(0)
56
50
  end
57
51
 
58
52
  it 'returns the size of the queue when the queue is not empty' do
59
- Queue.reset
60
53
  Queue.enqueue(:result).enqueue(:result)
61
54
  Queue.size.must_equal(2)
62
55
  end
@@ -64,7 +57,6 @@ module Vedeu
64
57
 
65
58
  describe '.clear' do
66
59
  it 'returns an empty array' do
67
- Queue.reset
68
60
  Queue.enqueue(:result)
69
61
  Queue.reset.must_be_empty
70
62
  end
@@ -72,12 +64,10 @@ module Vedeu
72
64
 
73
65
  describe '.view' do
74
66
  it 'returns the queue as a String when the queue is empty' do
75
- Queue.reset
76
67
  Queue.view.must_equal('[]')
77
68
  end
78
69
 
79
70
  it 'returns the queue as a String when the queue is not empty' do
80
- Queue.reset
81
71
  Queue.enqueue(:result)
82
72
  Queue.view.must_equal('[:result]')
83
73
  end
@@ -3,9 +3,10 @@ require_relative '../../../../lib/vedeu/support/terminal'
3
3
 
4
4
  module Vedeu
5
5
  describe Terminal do
6
+ let(:console) { IO.console }
7
+
6
8
  describe '.input' do
7
9
  it 'returns the entered string' do
8
- console = IO.console
9
10
  console.stub :gets, "test\n" do
10
11
  Terminal.input.must_equal('test')
11
12
  end
@@ -18,9 +19,16 @@ module Vedeu
18
19
  end
19
20
  end
20
21
 
22
+ describe '.clear_last_line' do
23
+ it 'returns an escape sequence to clear the last line' do
24
+ console.stub :winsize, [25, 25] do
25
+ Terminal.clear_last_line.must_equal("\e[24;1H\e[2K")
26
+ end
27
+ end
28
+ end
29
+
21
30
  describe '.centre' do
22
31
  it 'returns the centre point on the terminal' do
23
- console = IO.console
24
32
  console.stub :winsize, [25, 80] do
25
33
  Terminal.centre.must_equal([12, 40])
26
34
  end
@@ -29,7 +37,6 @@ module Vedeu
29
37
 
30
38
  describe '.width' do
31
39
  it 'returns the width of the terminal' do
32
- console = IO.console
33
40
  console.stub :winsize, [25, 80] do
34
41
  Terminal.width.must_equal(80)
35
42
  end
@@ -38,7 +45,6 @@ module Vedeu
38
45
 
39
46
  describe '.height' do
40
47
  it 'returns the height of the terminal' do
41
- console = IO.console
42
48
  console.stub :winsize, [25, 80] do
43
49
  Terminal.height.must_equal(25)
44
50
  end
@@ -47,7 +53,6 @@ module Vedeu
47
53
 
48
54
  describe '.size' do
49
55
  it 'returns the width and height of the terminal' do
50
- console = IO.console
51
56
  console.stub :winsize, [25, 80] do
52
57
  Terminal.size.must_equal([25, 80])
53
58
  end
@@ -56,7 +61,6 @@ module Vedeu
56
61
 
57
62
  describe '.console' do
58
63
  it 'returns the console' do
59
- console = IO.console
60
64
  Terminal.console.must_equal(console)
61
65
  end
62
66
  end
data/test/stats.sh ADDED
@@ -0,0 +1,29 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ function main {
6
+ for rev in `revisions`; do
7
+ echo "`number_of_lines ^lib` `number_of_lines ^test` `commit_description`"
8
+ done
9
+ }
10
+
11
+ function revisions {
12
+ git rev-list --reverse HEAD
13
+ }
14
+
15
+ function commit_description {
16
+ git log --oneline -1 $rev
17
+ }
18
+
19
+ function number_of_lines () {
20
+ git ls-tree -r $rev |
21
+ awk '{print $4, $3}' |
22
+ grep "$1" |
23
+ grep "\.rb" |
24
+ awk '{print $2}' |
25
+ xargs git show |
26
+ wc -l
27
+ }
28
+
29
+ main
data/vedeu.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'vedeu'
7
- spec.version = '0.0.36'
7
+ spec.version = '0.0.37'
8
8
  spec.authors = ['Gavin Laking']
9
9
  spec.email = ['gavinlaking@gmail.com']
10
10
  spec.summary = %q{A terminal case of wonderland.}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.36
4
+ version: 0.0.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-21 00:00:00.000000000 Z
11
+ date: 2014-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -167,6 +167,7 @@ files:
167
167
  - README.md
168
168
  - Rakefile
169
169
  - bin/vedeu
170
+ - deps.md
170
171
  - lib/vedeu.rb
171
172
  - lib/vedeu/application.rb
172
173
  - lib/vedeu/configuration.rb
@@ -184,10 +185,14 @@ files:
184
185
  - lib/vedeu/models/presentation.rb
185
186
  - lib/vedeu/models/stream.rb
186
187
  - lib/vedeu/models/style.rb
187
- - lib/vedeu/output/interface_renderer.rb
188
+ - lib/vedeu/output/clear_interface.rb
188
189
  - lib/vedeu/output/output.rb
190
+ - lib/vedeu/output/render_interface.rb
189
191
  - lib/vedeu/output/template.rb
190
- - lib/vedeu/output/text_adaptor.rb
192
+ - lib/vedeu/parsing/hash_parser.rb
193
+ - lib/vedeu/parsing/json_parser.rb
194
+ - lib/vedeu/parsing/parser.rb
195
+ - lib/vedeu/parsing/text_adaptor.rb
191
196
  - lib/vedeu/process/process.rb
192
197
  - lib/vedeu/repository/command_repository.rb
193
198
  - lib/vedeu/repository/event_repository.rb
@@ -199,9 +204,6 @@ files:
199
204
  - lib/vedeu/support/esc.rb
200
205
  - lib/vedeu/support/exit.rb
201
206
  - lib/vedeu/support/menu.rb
202
- - lib/vedeu/support/parser.rb
203
- - lib/vedeu/support/parsing/hash_parser.rb
204
- - lib/vedeu/support/parsing/json_parser.rb
205
207
  - lib/vedeu/support/queue.rb
206
208
  - lib/vedeu/support/terminal.rb
207
209
  - lib/vedeu/support/translator.rb
@@ -225,29 +227,31 @@ files:
225
227
  - test/lib/vedeu/models/presentation_test.rb
226
228
  - test/lib/vedeu/models/stream_test.rb
227
229
  - test/lib/vedeu/models/style_test.rb
228
- - test/lib/vedeu/output/interface_renderer_test.rb
230
+ - test/lib/vedeu/output/clear_interface_test.rb
229
231
  - test/lib/vedeu/output/output_test.rb
232
+ - test/lib/vedeu/output/render_interface_test.rb
230
233
  - test/lib/vedeu/output/template.rb
231
- - test/lib/vedeu/output/text_adaptor_test.rb
234
+ - test/lib/vedeu/parsing/hash_parser_test.rb
235
+ - test/lib/vedeu/parsing/json_parser_test.rb
236
+ - test/lib/vedeu/parsing/parser_test.rb
237
+ - test/lib/vedeu/parsing/text_adaptor_test.rb
232
238
  - test/lib/vedeu/process/process_test.rb
233
239
  - test/lib/vedeu/repository/command_repository_test.rb
240
+ - test/lib/vedeu/repository/event_repository_test.rb
234
241
  - test/lib/vedeu/repository/interface_repository_test.rb
235
242
  - test/lib/vedeu/repository/repository_test.rb
236
243
  - test/lib/vedeu/repository/storage_test.rb
237
244
  - test/lib/vedeu/support/compositor_test.rb
238
245
  - test/lib/vedeu/support/coordinate_test.rb
239
246
  - test/lib/vedeu/support/esc_test.rb
240
- - test/lib/vedeu/support/event_repository_test.rb
241
247
  - test/lib/vedeu/support/exit_test.rb
242
248
  - test/lib/vedeu/support/menu_test.rb
243
- - test/lib/vedeu/support/parser_test.rb
244
- - test/lib/vedeu/support/parsing/hash_parser_test.rb
245
- - test/lib/vedeu/support/parsing/json_parser_test.rb
246
249
  - test/lib/vedeu/support/queue_test.rb
247
250
  - test/lib/vedeu/support/terminal_test.rb
248
251
  - test/lib/vedeu/support/translator_test.rb
249
252
  - test/lib/vedeu/support/wordwrap_test.rb
250
253
  - test/lib/vedeu_test.rb
254
+ - test/stats.sh
251
255
  - test/support/colours.rb
252
256
  - test/support/dummy_command.rb
253
257
  - test/support/dummy_interface.rb
@@ -307,29 +311,31 @@ test_files:
307
311
  - test/lib/vedeu/models/presentation_test.rb
308
312
  - test/lib/vedeu/models/stream_test.rb
309
313
  - test/lib/vedeu/models/style_test.rb
310
- - test/lib/vedeu/output/interface_renderer_test.rb
314
+ - test/lib/vedeu/output/clear_interface_test.rb
311
315
  - test/lib/vedeu/output/output_test.rb
316
+ - test/lib/vedeu/output/render_interface_test.rb
312
317
  - test/lib/vedeu/output/template.rb
313
- - test/lib/vedeu/output/text_adaptor_test.rb
318
+ - test/lib/vedeu/parsing/hash_parser_test.rb
319
+ - test/lib/vedeu/parsing/json_parser_test.rb
320
+ - test/lib/vedeu/parsing/parser_test.rb
321
+ - test/lib/vedeu/parsing/text_adaptor_test.rb
314
322
  - test/lib/vedeu/process/process_test.rb
315
323
  - test/lib/vedeu/repository/command_repository_test.rb
324
+ - test/lib/vedeu/repository/event_repository_test.rb
316
325
  - test/lib/vedeu/repository/interface_repository_test.rb
317
326
  - test/lib/vedeu/repository/repository_test.rb
318
327
  - test/lib/vedeu/repository/storage_test.rb
319
328
  - test/lib/vedeu/support/compositor_test.rb
320
329
  - test/lib/vedeu/support/coordinate_test.rb
321
330
  - test/lib/vedeu/support/esc_test.rb
322
- - test/lib/vedeu/support/event_repository_test.rb
323
331
  - test/lib/vedeu/support/exit_test.rb
324
332
  - test/lib/vedeu/support/menu_test.rb
325
- - test/lib/vedeu/support/parser_test.rb
326
- - test/lib/vedeu/support/parsing/hash_parser_test.rb
327
- - test/lib/vedeu/support/parsing/json_parser_test.rb
328
333
  - test/lib/vedeu/support/queue_test.rb
329
334
  - test/lib/vedeu/support/terminal_test.rb
330
335
  - test/lib/vedeu/support/translator_test.rb
331
336
  - test/lib/vedeu/support/wordwrap_test.rb
332
337
  - test/lib/vedeu_test.rb
338
+ - test/stats.sh
333
339
  - test/support/colours.rb
334
340
  - test/support/dummy_command.rb
335
341
  - test/support/dummy_interface.rb