vedeu 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ef9364bd8562905d44a580a1f6b9f0acb3820d6
4
- data.tar.gz: 30849fc7340fbb1ab220e24834580bd0941e8545
3
+ metadata.gz: 19ee0e20e445eeee950b4aaf5be06d25b6e7f5ad
4
+ data.tar.gz: f9dbeb37f02a0491376d1f1ad2e94abbf37c2548
5
5
  SHA512:
6
- metadata.gz: 461240de809a3abd145c22eaea50bc32b5dfe56f41c16c35c407b6e13493f4d16e431d0fb9f2fdbb5111f847287d771f39fb7a239fe8f6c24f47677b930c4f44
7
- data.tar.gz: e823ea6b126ea32dd259fdef8a58c3cd6c59c3a07bcaa8d51cb52bef0847226dbf69890d9b0e4c6ec064c5feffaaee17e48ccd91ea417dff7faf14579c5d2d83
6
+ metadata.gz: f848ddbd4480fd75e76a8a6f4dcef666eaacd4b7de53e9dd8e4b76ce37ca51909436898d1c41d6e159d2c7afde9a4414d6b65dd1c10f57a3416a6fdf8e010814
7
+ data.tar.gz: 96a133c336ccca5f5aa84414aa766f2c5b7666103feabe328de3c9166cda1cba7e13c4f92166025cd4ffa198d5fad9430c98c2bf7f11c161e37f6e29940e9a78
@@ -8,12 +8,15 @@ module Vedeu
8
8
  def initialize(attributes, &block)
9
9
  @attributes = attributes
10
10
 
11
- self.instance_eval(&block) if block_given?
11
+ @self_before_instance_eval = eval 'self', block.binding
12
+
13
+ self.instance_eval(&block)
12
14
  end
13
15
 
14
16
  def colour(*args)
15
17
  if args.is_a?(Array) && args.size == 2
16
- attributes[:colour] = { background: args.first, foreground: args.last }
18
+ attributes[:colour] = { background: args.first,
19
+ foreground: args.last }
17
20
 
18
21
  elsif args.is_a?(Array) && args.size == 1 && args.first.is_a?(Hash)
19
22
  attributes[:colour] = args.first
@@ -31,6 +34,12 @@ module Vedeu
31
34
  [values].flatten.each { |value| attributes[:style] << value }
32
35
  end
33
36
  end
37
+
38
+ # :nocov:
39
+ def method_missing(method, *args, &block)
40
+ @self_before_instance_eval.send method, *args, &block
41
+ end
42
+ # :nocov
34
43
  end
35
44
  end
36
45
  end
@@ -0,0 +1,56 @@
1
+ require 'vedeu/support/terminal'
2
+
3
+ class Fixnum
4
+ # Augment Fixnum to calculate column width in a grid-based layout.
5
+ #
6
+ # The grid system splits the terminal width into 12 equal parts, by dividing
7
+ # the available width by 12. If the terminal width is not a multiple of 12,
8
+ # then Grid chooses the maximum value which will fit.
9
+ #
10
+ # Used primarily at interface creation time:
11
+ #
12
+ # width: 9.columns # (Terminal width / 12) * 9 characters wide; e.g.
13
+ # # Terminal is 92 characters wide, maximum value is
14
+ # # therefore 84, meaning a column is 7 characters wide.
15
+ def columns
16
+ Vedeu::API::Grid.columns(self)
17
+ end
18
+ end
19
+
20
+ module Vedeu
21
+ module API
22
+ OutOfRange = Class.new(StandardError)
23
+
24
+ class Grid
25
+ def self.columns(value)
26
+ new(value).columns
27
+ end
28
+
29
+ def initialize(value)
30
+ @value = value
31
+ end
32
+
33
+ def columns
34
+ fail OutOfRange, 'Valid range is 1..12.' if out_of_range?
35
+
36
+ column * value
37
+ end
38
+
39
+ private
40
+
41
+ attr_reader :value
42
+
43
+ def column
44
+ actual / 12
45
+ end
46
+
47
+ def actual
48
+ Terminal.width
49
+ end
50
+
51
+ def out_of_range?
52
+ value < 1 || value > 12
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,4 +1,5 @@
1
1
  require 'vedeu/models/geometry'
2
+ require 'vedeu/api/grid'
2
3
  require 'vedeu/support/interface_store'
3
4
  require 'vedeu/support/terminal'
4
5
 
@@ -8,11 +8,6 @@ module Vedeu
8
8
  attributes
9
9
  end
10
10
 
11
- def width(value)
12
- #attributes[:streams][:width] = value
13
- #attributes[:streams] << API::Stream.build({ width: value })
14
- end
15
-
16
11
  def align(value)
17
12
  attributes[:align] = value
18
13
  end
@@ -26,15 +21,21 @@ module Vedeu
26
21
  end
27
22
 
28
23
  def foreground(value = '', &block)
29
- attributes[:streams] << API::Stream.build({ colour: { foreground: value } }, &block)
24
+ attributes[:streams] << API::Stream.build({
25
+ colour: { foreground: value }
26
+ }, &block)
30
27
  end
31
28
 
32
29
  def background(value = '', &block)
33
- attributes[:streams] << API::Stream.build({ colour: { background: value } }, &block)
30
+ attributes[:streams] << API::Stream.build({
31
+ colour: { background: value }
32
+ }, &block)
34
33
  end
35
34
 
36
35
  def attributes
37
- @_attributes ||= { colour: {}, style: [], streams: [] }.merge!(@attributes)
36
+ @_attributes ||= { colour: {},
37
+ style: [],
38
+ streams: [] }.merge!(@attributes)
38
39
  end
39
40
  end
40
41
  end
@@ -7,10 +7,18 @@ module Vedeu
7
7
  attributes
8
8
  end
9
9
 
10
+ def align(value)
11
+ attributes[:align] = value
12
+ end
13
+
10
14
  def text(value)
11
15
  attributes[:text] = value
12
16
  end
13
17
 
18
+ def width(value)
19
+ attributes[:width] = value
20
+ end
21
+
14
22
  def attributes
15
23
  @_attributes ||= { colour: {}, style: [], text: '' }.merge!(@attributes)
16
24
  end
@@ -18,6 +18,8 @@ module Vedeu
18
18
  end
19
19
 
20
20
  def build(&block)
21
+ @self_before_instance_eval = eval 'self', block.binding
22
+
21
23
  self.instance_eval(&block) if block_given?
22
24
 
23
25
  attributes
@@ -34,6 +36,12 @@ module Vedeu
34
36
  def name
35
37
  return @name if InterfaceStore.query(@name)
36
38
  end
39
+
40
+ # :nocov:
41
+ def method_missing(method, *args, &block)
42
+ @self_before_instance_eval.send method, *args, &block
43
+ end
44
+ # :nocov
37
45
  end
38
46
  end
39
47
  end
@@ -0,0 +1,19 @@
1
+ module Vedeu
2
+ class DSLParser
3
+ def self.parse(data)
4
+ new(data).parse
5
+ end
6
+
7
+ def initialize(data)
8
+ @data = data
9
+ end
10
+
11
+ def parse
12
+ { interfaces: [ data ] }
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :data
18
+ end
19
+ end
@@ -24,31 +24,29 @@ module Vedeu
24
24
  attr_reader :interface
25
25
 
26
26
  def processed_lines
27
- processed_lines = lines.map do |line|
28
- if line.streams.any?
29
- processed_streams = []
30
- line_length = 0
31
- line.streams.each do |stream|
32
- next if stream.text.empty?
27
+ return [] unless lines.any? { |line| line.streams.any? }
33
28
 
34
- if (line_length += stream.text.size) >= width
35
- remainder = width - line_length
29
+ lines.map do |line|
30
+ line_length = 0
31
+ streams = line.streams.inject([]) do |processed, stream|
32
+ next if stream.text.empty?
36
33
 
37
- processed_streams << Stream.new(
38
- text: truncate(stream.text, remainder),
34
+ if (line_length += stream.text.size) >= width
35
+ remainder = width - line_length
36
+
37
+ processed << Stream.new(text: truncate(stream.text, remainder),
39
38
  style: stream.style,
40
39
  colour: stream.colour)
41
40
 
42
- else
43
- processed_streams << stream
41
+ else
42
+ processed << stream
44
43
 
45
- end
46
44
  end
47
-
48
- Line.new(streams: processed_streams,
49
- style: line.style,
50
- colour: line.colour)
51
45
  end
46
+
47
+ Line.new(streams: streams,
48
+ style: line.style,
49
+ colour: line.colour)
52
50
  end
53
51
  end
54
52
 
@@ -1,4 +1,5 @@
1
1
  require 'vedeu/models/composition'
2
+ require 'vedeu/output/dsl_parser'
2
3
  require 'vedeu/output/erb_parser'
3
4
  require 'vedeu/output/raw_parser'
4
5
  require 'vedeu/output/json_parser'
@@ -29,6 +30,7 @@ module Vedeu
29
30
 
30
31
  def parser
31
32
  {
33
+ dsl: DSLParser,
32
34
  erb: ERBParser,
33
35
  json: JSONParser,
34
36
  hash: RawParser,
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ require 'vedeu/api/grid'
4
+
5
+ module Vedeu
6
+ module API
7
+ describe Grid do
8
+ it 'raises an exception if the value is less than 1' do
9
+ proc { Grid.columns(0) }.must_raise(OutOfRange)
10
+ end
11
+
12
+ it 'raises an exception if the value is greater than 12' do
13
+ proc { Grid.columns(13) }.must_raise(OutOfRange)
14
+ end
15
+
16
+ it 'returns the width if the value is in range' do
17
+ IO.console.stub :winsize, [25, 80] do
18
+ Grid.columns(7).must_equal(42)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -9,8 +9,6 @@ module Vedeu
9
9
  before do
10
10
  InterfaceStore.reset
11
11
  Interface.save('testing_view') do
12
- width 80
13
- height 25
14
12
  x 1
15
13
  y 1
16
14
  colour foreground: '#ffffff', background: '#000000'
@@ -387,11 +385,12 @@ module Vedeu
387
385
  end
388
386
 
389
387
  it 'handles alignment' do
390
- skip
391
388
  Vedeu.view 'testing_view' do
392
389
  line do
393
- width 80
394
- text 'This is aligned left, and padded with spaces.'
390
+ stream do
391
+ width 80
392
+ text 'This is aligned left, and padded with spaces.'
393
+ end
395
394
  end
396
395
  end.must_equal(
397
396
  {
@@ -400,8 +399,10 @@ module Vedeu
400
399
  colour: {},
401
400
  style: [],
402
401
  streams: [{
403
- width: 80,
404
- text: 'This is aligned left, and padded with spaces.'
402
+ colour: {},
403
+ style: [],
404
+ width: 80,
405
+ text: 'This is aligned left, and padded with spaces.'
405
406
  }]
406
407
  }]
407
408
  }
@@ -412,18 +413,24 @@ module Vedeu
412
413
  skip
413
414
  Vedeu.view 'testing_view' do
414
415
  line do
415
- width 80
416
- align :left # explicit
417
- text 'This is aligned left, and padded with spaces.'
416
+ stream do
417
+ width 80
418
+ align :left # explicit
419
+ text 'This is aligned left, and padded with spaces.'
420
+ end
418
421
  end
419
422
  end.must_equal(
420
423
  {
421
424
  name: 'testing_view',
422
425
  lines: [{
426
+ colour: {},
427
+ style: [],
423
428
  streams: [{
424
- width: 80,
425
- align: :left,
426
- text: 'This is aligned left, and padded with spaces.'
429
+ colour: {},
430
+ style: [],
431
+ width: 80,
432
+ align: :left,
433
+ text: 'This is aligned left, and padded with spaces.'
427
434
  }]
428
435
  }]
429
436
  }
@@ -434,18 +441,24 @@ module Vedeu
434
441
  skip
435
442
  Vedeu.view 'testing_view' do
436
443
  line do
437
- width 80
438
- align :centre
439
- text 'This is aligned centrally, and padded with spaces.'
444
+ stream do
445
+ width 80
446
+ align :centre
447
+ text 'This is aligned centrally, and padded with spaces.'
448
+ end
440
449
  end
441
450
  end.must_equal(
442
451
  {
443
452
  name: 'testing_view',
444
453
  lines: [{
454
+ colour: {},
455
+ style: [],
445
456
  streams: [{
446
- width: 80,
447
- align: :centre,
448
- text: 'This is aligned right, and padded with spaces.'
457
+ colour: {},
458
+ style: [],
459
+ width: 80,
460
+ align: :centre,
461
+ text: 'This is aligned right, and padded with spaces.'
449
462
  }]
450
463
  }]
451
464
  }
@@ -456,23 +469,103 @@ module Vedeu
456
469
  skip
457
470
  Vedeu.view 'testing_view' do
458
471
  line do
459
- width 80
460
- align :right
461
- text 'This is aligned right, and padded with spaces.'
472
+ stream do
473
+ width 80
474
+ align :right
475
+ text 'This is aligned right, and padded with spaces.'
476
+ end
462
477
  end
463
478
  end.must_equal(
464
479
  {
465
480
  name: 'testing_view',
466
481
  lines: [{
482
+ colour: {},
483
+ style: [],
467
484
  streams: [{
468
- width: 80,
469
- align: :right,
470
- text: 'This is aligned right, and padded with spaces.'
485
+ colour: {},
486
+ style: [],
487
+ width: 80,
488
+ align: :right,
489
+ text: 'This is aligned right, and padded with spaces.'
471
490
  }]
472
491
  }]
473
492
  }
474
493
  )
475
494
  end
495
+
496
+ it 'handles multiple colour and text statements correctly' do
497
+ Vedeu.view 'testing_view' do
498
+ line do
499
+ foreground('#ffff00') { text "\u{25B2}" }
500
+ text " Prev"
501
+
502
+ foreground('#ffff00') { text "\u{25BC}" }
503
+ text " Next"
504
+
505
+ foreground('#ffff00') { text "\u{21B2}" }
506
+ text " Select"
507
+
508
+ foreground('#ffff00') { text "\u{2395}" }
509
+ text " Pause"
510
+
511
+ foreground('#ffff00') { text "Q" }
512
+ text " Quit"
513
+ end
514
+ end.must_equal(
515
+ {
516
+ name: 'testing_view',
517
+ lines: [
518
+ {
519
+ colour: {},
520
+ style: [],
521
+ streams: [
522
+ {
523
+ colour: {
524
+ foreground: "#ffff00"
525
+ },
526
+ style: [],
527
+ text: "▲"
528
+ }, {
529
+ text: " Prev"
530
+ }, {
531
+ colour: {
532
+ foreground: "#ffff00"
533
+ },
534
+ style: [],
535
+ text: "▼"
536
+ }, {
537
+ text: " Next"
538
+ }, {
539
+ colour: {
540
+ foreground: "#ffff00"
541
+ },
542
+ style: [],
543
+ text: "↲"
544
+ }, {
545
+ text: " Select"
546
+ }, {
547
+ colour: {
548
+ foreground: "#ffff00"
549
+ },
550
+ style: [],
551
+ text: "⎕"
552
+ }, {
553
+ text: " Pause"
554
+ }, {
555
+ colour: {
556
+ foreground: "#ffff00"
557
+ },
558
+ style: [],
559
+ text: "Q"
560
+ }, {
561
+ text: " Quit"
562
+ }
563
+ ]
564
+ }
565
+ ]
566
+ }
567
+ )
568
+ end
476
569
  end
477
570
  end
478
571
  end
@@ -3,5 +3,8 @@ require 'vedeu/application'
3
3
 
4
4
  module Vedeu
5
5
  describe Application do
6
+ it 'returns an instance of Application' do
7
+ Application.new.must_be_instance_of(Application)
8
+ end
6
9
  end
7
10
  end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ require 'vedeu/output/dsl_parser'
4
+
5
+ module Vedeu
6
+ describe DSLParser do
7
+ it 'returns attributes suitable for Composition' do
8
+ DSLParser.parse({ name: 'dummy' }).must_equal(
9
+ {
10
+ interfaces: [
11
+ {
12
+ name: 'dummy'
13
+ }
14
+ ]
15
+ }
16
+ )
17
+ end
18
+ end
19
+ end
@@ -10,12 +10,12 @@ module Vedeu
10
10
  describe '.call' do
11
11
  it 'returns the content for the interface' do
12
12
  interface = Interface.new({
13
- name: '.call',
13
+ name: '.call',
14
14
  geometry: {
15
15
  width: 32,
16
16
  height: 3,
17
17
  },
18
- lines: [
18
+ lines: [
19
19
  {
20
20
  streams: [{ text: 'this is the first' }]
21
21
  }, {
@@ -40,6 +40,55 @@ module Vedeu
40
40
  "\e[3;1Hthis is the third, it is even lo"
41
41
  )
42
42
  end
43
+
44
+ it 'returns a blank interface if there are no streams of text' do
45
+ interface = Interface.new({
46
+ name: '.call',
47
+ geometry: {
48
+ width: 32,
49
+ height: 3,
50
+ },
51
+ lines: []
52
+ })
53
+ RenderInterface.call(interface).must_equal(
54
+ "\e[1;1H \e[1;1H" \
55
+ "\e[2;1H \e[2;1H" \
56
+ "\e[3;1H \e[3;1H"
57
+ )
58
+ end
59
+
60
+ it 'skips lines which have streams with no content' do
61
+ interface = Interface.new({
62
+ name: '.call',
63
+ geometry: {
64
+ width: 32,
65
+ height: 3,
66
+ },
67
+ lines: [
68
+ {
69
+ streams: [{ text: 'this is the first' }]
70
+ }, {
71
+ streams: { text: '' }
72
+ }, {
73
+ streams: [
74
+ { text: 'this is the third, ' },
75
+ { text: 'it is even longer ' },
76
+ { text: 'and still truncated' }
77
+ ]
78
+ }, {
79
+ streams: [{ text: 'this should not render' }]
80
+ }
81
+ ]
82
+ })
83
+ RenderInterface.call(interface).must_equal(
84
+ "\e[1;1H \e[1;1H" \
85
+ "\e[2;1H \e[2;1H" \
86
+ "\e[3;1H \e[3;1H" \
87
+ "\e[1;1Hthis is the first" \
88
+ "\e[2;1H" \
89
+ "\e[3;1Hthis is the third, it is even lo"
90
+ )
91
+ end
43
92
  end
44
93
  end
45
94
  end
@@ -16,8 +16,6 @@ module Vedeu
16
16
  describe '.foreground' do
17
17
  it 'returns an escape sequence for the specified CSS foreground' do
18
18
  TestHelpers.new.foreground('#a5f500').must_equal("\e[38;5;148m")
19
-
20
- TestHelpers.new.fg('#851500').must_equal("\e[38;5;88m")
21
19
  end
22
20
 
23
21
  it 'returns an escape sequence plus interpolation when a block is given' do
@@ -29,8 +27,6 @@ module Vedeu
29
27
  describe '.background' do
30
28
  it 'returns an escape sequence for the specified CSS background' do
31
29
  TestHelpers.new.background('#2f2f2f').must_equal("\e[48;5;16m")
32
-
33
- TestHelpers.new.bg('#ffffff').must_equal("\e[48;5;231m")
34
30
  end
35
31
 
36
32
  it 'returns an escape sequence plus interpolation when a block is given' do
@@ -33,19 +33,16 @@ end
33
33
  describe Vedeu do
34
34
  describe '.events' do
35
35
  it 'creates some system events for the client application' do
36
- skip
37
36
  end
38
37
  end
39
38
 
40
39
  describe '.log' do
41
40
  it 'returns a logger instance for writing debug messages to' do
42
- skip
43
41
  end
44
42
  end
45
43
 
46
44
  describe '.error' do
47
45
  it 'writes an error to the log' do
48
- skip
49
46
  end
50
47
  end
51
48
  end
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.1.5'
7
+ spec.version = '0.1.6'
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.1.5
4
+ version: 0.1.6
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-08-06 00:00:00.000000000 Z
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -186,6 +186,7 @@ files:
186
186
  - deps.md
187
187
  - lib/vedeu.rb
188
188
  - lib/vedeu/api/base.rb
189
+ - lib/vedeu/api/grid.rb
189
190
  - lib/vedeu/api/interface.rb
190
191
  - lib/vedeu/api/line.rb
191
192
  - lib/vedeu/api/stream.rb
@@ -207,6 +208,7 @@ files:
207
208
  - lib/vedeu/models/style.rb
208
209
  - lib/vedeu/output/clear_interface.rb
209
210
  - lib/vedeu/output/colour_translator.rb
211
+ - lib/vedeu/output/dsl_parser.rb
210
212
  - lib/vedeu/output/erb_parser.rb
211
213
  - lib/vedeu/output/json_parser.rb
212
214
  - lib/vedeu/output/menu_parser.rb
@@ -225,6 +227,7 @@ files:
225
227
  - lib/vedeu/support/wordwrap.rb
226
228
  - logs/.gitkeep
227
229
  - test/lib/vedeu/api/base_test.rb
230
+ - test/lib/vedeu/api/grid_test.rb
228
231
  - test/lib/vedeu/api/interface_test.rb
229
232
  - test/lib/vedeu/api/line_test.rb
230
233
  - test/lib/vedeu/api/stream_test.rb
@@ -245,6 +248,7 @@ files:
245
248
  - test/lib/vedeu/models/style_test.rb
246
249
  - test/lib/vedeu/output/clear_interface_test.rb
247
250
  - test/lib/vedeu/output/colour_translator_test.rb
251
+ - test/lib/vedeu/output/dsl_parser_test.rb
248
252
  - test/lib/vedeu/output/erb_parser_test.rb
249
253
  - test/lib/vedeu/output/json_parser_test.rb
250
254
  - test/lib/vedeu/output/menu_parser_test.rb
@@ -312,6 +316,7 @@ specification_version: 4
312
316
  summary: A terminal case of wonderland.
313
317
  test_files:
314
318
  - test/lib/vedeu/api/base_test.rb
319
+ - test/lib/vedeu/api/grid_test.rb
315
320
  - test/lib/vedeu/api/interface_test.rb
316
321
  - test/lib/vedeu/api/line_test.rb
317
322
  - test/lib/vedeu/api/stream_test.rb
@@ -332,6 +337,7 @@ test_files:
332
337
  - test/lib/vedeu/models/style_test.rb
333
338
  - test/lib/vedeu/output/clear_interface_test.rb
334
339
  - test/lib/vedeu/output/colour_translator_test.rb
340
+ - test/lib/vedeu/output/dsl_parser_test.rb
335
341
  - test/lib/vedeu/output/erb_parser_test.rb
336
342
  - test/lib/vedeu/output/json_parser_test.rb
337
343
  - test/lib/vedeu/output/menu_parser_test.rb