vedeu 0.7.0 → 0.7.1

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/docs/borders.md +2 -2
  3. data/examples/284_slow_rendering.rb +2 -2
  4. data/examples/dsl_alignment.rb +9 -9
  5. data/examples/dsl_colours.rb +13 -13
  6. data/examples/dsl_editor.rb +10 -10
  7. data/lib/vedeu/borders/dsl.rb +84 -0
  8. data/lib/vedeu/buffers/empty.rb +3 -3
  9. data/lib/vedeu/buffers/terminal.rb +1 -1
  10. data/lib/vedeu/buffers/view.rb +1 -1
  11. data/lib/vedeu/cells/borders/all.rb +1 -0
  12. data/lib/vedeu/cells/borders/bottom_left.rb +1 -6
  13. data/lib/vedeu/cells/borders/bottom_right.rb +1 -6
  14. data/lib/vedeu/cells/borders/corner.rb +20 -0
  15. data/lib/vedeu/cells/borders/top_left.rb +1 -6
  16. data/lib/vedeu/cells/borders/top_right.rb +1 -6
  17. data/lib/vedeu/cells/empty.rb +22 -0
  18. data/lib/vedeu/cells/escape.rb +47 -0
  19. data/lib/vedeu/cursors/cursor.rb +6 -6
  20. data/lib/vedeu/dsl/text.rb +12 -1
  21. data/lib/vedeu/events/trigger.rb +4 -2
  22. data/lib/vedeu/input/capture.rb +1 -1
  23. data/lib/vedeu/input/mouse.rb +3 -2
  24. data/lib/vedeu/models/all.rb +0 -2
  25. data/lib/vedeu/models/row.rb +1 -1
  26. data/lib/vedeu/output/output.rb +8 -8
  27. data/lib/vedeu/output/text.rb +23 -2
  28. data/lib/vedeu/renderers/html.rb +4 -4
  29. data/lib/vedeu/runtime/launcher.rb +1 -1
  30. data/lib/vedeu/version.rb +1 -1
  31. data/test/lib/vedeu/borders/dsl_test.rb +40 -0
  32. data/test/lib/vedeu/buffers/empty_test.rb +1 -1
  33. data/test/lib/vedeu/cells/borders/bottom_left_test.rb +0 -14
  34. data/test/lib/vedeu/cells/borders/bottom_right_test.rb +0 -14
  35. data/test/lib/vedeu/cells/borders/corner_test.rb +57 -0
  36. data/test/lib/vedeu/cells/borders/top_left_test.rb +0 -14
  37. data/test/lib/vedeu/cells/borders/top_right_test.rb +0 -14
  38. data/test/lib/vedeu/cells/empty_test.rb +33 -0
  39. data/test/lib/vedeu/cells/escape_test.rb +74 -0
  40. data/test/lib/vedeu/cursors/cursor_test.rb +17 -11
  41. data/test/lib/vedeu/dsl/text_test.rb +1 -0
  42. data/test/lib/vedeu/models/row_test.rb +1 -1
  43. data/test/lib/vedeu/output/compressor_test.rb +2 -2
  44. data/test/lib/vedeu/output/output_test.rb +2 -2
  45. data/test/lib/vedeu/renderers/all_test.rb +2 -2
  46. data/test/lib/vedeu/renderers/terminal_test.rb +6 -6
  47. data/test/support/examples/material_colours_app.rb +13 -10
  48. metadata +4 -7
  49. data/lib/vedeu/models/cell.rb +0 -91
  50. data/lib/vedeu/models/escape.rb +0 -90
  51. data/test/lib/vedeu/models/cell_test.rb +0 -117
  52. data/test/lib/vedeu/models/escape_test.rb +0 -87
@@ -9,20 +9,6 @@ module Vedeu
9
9
  let(:described) { Vedeu::Cells::BottomRight }
10
10
  let(:instance) { described.new }
11
11
 
12
- describe '#position' do
13
- let(:geometry) {
14
- Vedeu::Geometries::Geometry.new(x: 5, xn: 15, y: 3, yn: 9)
15
- }
16
-
17
- subject { instance.position }
18
-
19
- before { Vedeu.geometries.stubs(:by_name).returns(geometry) }
20
-
21
- it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
22
- it { subject.x.must_equal(15) }
23
- it { subject.y.must_equal(9) }
24
- end
25
-
26
12
  describe '#type' do
27
13
  subject { instance.type }
28
14
 
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Cells
6
+
7
+ describe Corner do
8
+
9
+ let(:described) { Vedeu::Cells::Corner }
10
+
11
+ describe '#position' do
12
+ let(:geometry) {
13
+ Vedeu::Geometries::Geometry.new(x: 5, xn: 15, y: 3, yn: 9)
14
+ }
15
+
16
+ before { instance.stubs(:geometry).returns(geometry) }
17
+
18
+ subject { instance.position }
19
+
20
+ context 'when providing the position for the bottom left corner' do
21
+ let(:instance) { Vedeu::Cells::BottomLeft.new }
22
+
23
+ it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
24
+ it { subject.x.must_equal(5) }
25
+ it { subject.y.must_equal(9) }
26
+ end
27
+
28
+ context 'when providing the position for the bottom right corner' do
29
+ let(:instance) { Vedeu::Cells::BottomRight.new }
30
+
31
+ it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
32
+ it { subject.x.must_equal(15) }
33
+ it { subject.y.must_equal(9) }
34
+ end
35
+
36
+ context 'when providing the position for the top left corner' do
37
+ let(:instance) { Vedeu::Cells::TopLeft.new }
38
+
39
+ it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
40
+ it { subject.x.must_equal(5) }
41
+ it { subject.y.must_equal(3) }
42
+ end
43
+
44
+ context 'when providing the position for the top right corner' do
45
+ let(:instance) { Vedeu::Cells::TopRight.new }
46
+
47
+ it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
48
+ it { subject.x.must_equal(15) }
49
+ it { subject.y.must_equal(3) }
50
+ end
51
+ end
52
+
53
+ end # Corner
54
+
55
+ end # Cells
56
+
57
+ end # Vedeu
@@ -9,20 +9,6 @@ module Vedeu
9
9
  let(:described) { Vedeu::Cells::TopLeft }
10
10
  let(:instance) { described.new }
11
11
 
12
- describe '#position' do
13
- let(:geometry) {
14
- Vedeu::Geometries::Geometry.new(x: 5, xn: 15, y: 3, yn: 9)
15
- }
16
-
17
- subject { instance.position }
18
-
19
- before { Vedeu.geometries.stubs(:by_name).returns(geometry) }
20
-
21
- it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
22
- it { subject.x.must_equal(5) }
23
- it { subject.y.must_equal(3) }
24
- end
25
-
26
12
  describe '#type' do
27
13
  subject { instance.type }
28
14
 
@@ -9,20 +9,6 @@ module Vedeu
9
9
  let(:described) { Vedeu::Cells::TopRight }
10
10
  let(:instance) { described.new }
11
11
 
12
- describe '#position' do
13
- let(:geometry) {
14
- Vedeu::Geometries::Geometry.new(x: 5, xn: 15, y: 3, yn: 9)
15
- }
16
-
17
- subject { instance.position }
18
-
19
- before { Vedeu.geometries.stubs(:by_name).returns(geometry) }
20
-
21
- it { subject.must_be_instance_of(Vedeu::Geometries::Position) }
22
- it { subject.x.must_equal(15) }
23
- it { subject.y.must_equal(3) }
24
- end
25
-
26
12
  describe '#type' do
27
13
  subject { instance.type }
28
14
 
@@ -48,6 +48,39 @@ module Vedeu
48
48
  end
49
49
  end
50
50
 
51
+ describe '#to_hash' do
52
+ let(:position) { [1, 1] }
53
+ let(:colour) { Vedeu::Colours::Colour.new(background: '#000000') }
54
+ let(:expected) {
55
+ {
56
+ colour: "\e[48;2;0;0;0m",
57
+ style: '',
58
+ value: '',
59
+ position: "\e[1;1H",
60
+ }
61
+ }
62
+
63
+ subject { instance.to_hash }
64
+
65
+ it { subject.must_be_instance_of(Hash) }
66
+ it { subject.must_equal(expected) }
67
+ end
68
+
69
+ describe '#to_html' do
70
+ subject { instance.to_html }
71
+
72
+ it { subject.must_be_instance_of(String) }
73
+ it { subject.must_equal('') }
74
+ end
75
+
76
+ describe '#to_s' do
77
+ subject { instance.to_s }
78
+
79
+ it { instance.must_respond_to(:to_str) }
80
+ it { subject.must_be_instance_of(String) }
81
+ it { subject.must_equal('') }
82
+ end
83
+
51
84
  end # Empty
52
85
 
53
86
  end # Cells
@@ -6,6 +6,80 @@ module Vedeu
6
6
 
7
7
  describe Escape do
8
8
 
9
+ let(:described) { Vedeu::Cells::Escape }
10
+ let(:instance) { described.new(attributes) }
11
+ let(:attributes) {
12
+ {
13
+ position: position,
14
+ value: _value,
15
+ }
16
+ }
17
+ let(:position) { [2, 6] }
18
+ let(:_value) { "\e[?25h" }
19
+
20
+ describe '#initialize' do
21
+ it { instance.must_be_instance_of(described) }
22
+ it { instance.instance_variable_get('@position').must_equal(position) }
23
+ it { instance.instance_variable_get('@value').must_equal(_value) }
24
+ end
25
+
26
+ describe '#cell?' do
27
+ it { instance.cell?.must_equal(false) }
28
+ end
29
+
30
+ describe '#null' do
31
+ it { instance.null.must_equal(nil) }
32
+ it { instance.background.must_equal(nil) }
33
+ it { instance.colour.must_equal(nil) }
34
+ it { instance.foreground.must_equal(nil) }
35
+ it { instance.style.must_equal(nil) }
36
+ end
37
+
38
+ # describe '#eql?' do
39
+ # let(:other) { instance }
40
+
41
+ # subject { instance.eql?(other) }
42
+
43
+ # it { subject.must_equal(true) }
44
+
45
+ # context 'when different to other' do
46
+ # let(:other) { described.new(value: 'b') }
47
+
48
+ # it { subject.must_equal(false) }
49
+ # end
50
+
51
+ # it { instance.must_respond_to(:==) }
52
+ # end
53
+
54
+ describe '#value' do
55
+ subject { instance.value }
56
+
57
+ it { subject.must_be_instance_of(String) }
58
+ it { subject.must_equal("\e[?25h") }
59
+ end
60
+
61
+ describe '#to_hash' do
62
+ subject { instance.to_hash }
63
+
64
+ it { subject.must_be_instance_of(Hash) }
65
+ it { subject.must_equal({}) }
66
+ end
67
+
68
+ describe '#to_html' do
69
+ subject { instance.to_html }
70
+
71
+ it { subject.must_be_instance_of(String) }
72
+ it { subject.must_equal('') }
73
+ end
74
+
75
+ describe '#to_s' do
76
+ subject { instance.to_s }
77
+
78
+ it { subject.must_be_instance_of(String) }
79
+ it { subject.must_equal("\e[2;6H\e[?25h") }
80
+ it { instance.must_respond_to(:to_str) }
81
+ end
82
+
9
83
  end # Escape
10
84
 
11
85
  end # Cells
@@ -102,19 +102,22 @@ module Vedeu
102
102
  end
103
103
 
104
104
  describe '#hide' do
105
- let(:visible) { true }
106
- let(:hide_cursor) {
107
- Vedeu::Models::Escape
108
- .new(value: Vedeu::EscapeSequences::Esc.hide_cursor)
105
+ let(:visible) { true }
106
+ let(:escape) {
107
+ Vedeu::Cells::Escape.
108
+ new(value: Vedeu::EscapeSequences::Esc.hide_cursor)
109
109
  }
110
110
 
111
111
  before do
112
- Vedeu.stubs(:render_output).with(hide_cursor).returns(hide_cursor)
112
+ Vedeu::Cells::Escape.stubs(:new).returns(escape)
113
113
  end
114
114
 
115
115
  subject { instance.hide }
116
116
 
117
- it { subject.must_be_instance_of(Vedeu::Models::Escape) }
117
+ it {
118
+ Vedeu.expects(:render_output).with(escape)
119
+ subject
120
+ }
118
121
  end
119
122
 
120
123
  describe '#inspect' do
@@ -241,18 +244,21 @@ module Vedeu
241
244
 
242
245
  describe '#show' do
243
246
  let(:visible) { false }
244
- let(:show_cursor) {
245
- Vedeu::Models::Escape
246
- .new(value: Vedeu::EscapeSequences::Esc.show_cursor)
247
+ let(:escape) {
248
+ Vedeu::Cells::Escape.
249
+ new(value: Vedeu::EscapeSequences::Esc.show_cursor)
247
250
  }
248
251
 
249
252
  before do
250
- Vedeu.stubs(:render_output).with(show_cursor).returns(show_cursor)
253
+ Vedeu::Cells::Escape.stubs(:new).returns(escape)
251
254
  end
252
255
 
253
256
  subject { instance.show }
254
257
 
255
- it { subject.must_be_instance_of(Vedeu::Models::Escape) }
258
+ it {
259
+ Vedeu.expects(:render_output).with(escape)
260
+ subject
261
+ }
256
262
  end
257
263
 
258
264
  describe '#to_a' do
@@ -13,6 +13,7 @@ module Vedeu
13
13
  {
14
14
  anchor: anchor,
15
15
  model: model,
16
+ name: model.name,
16
17
  client: nil,
17
18
  }
18
19
  }
@@ -11,7 +11,7 @@ module Vedeu
11
11
  let(:cells) {
12
12
  [
13
13
  Vedeu::Views::Char.new(value: 'A'),
14
- Vedeu::Models::Cell.new(value: 'B'),
14
+ Vedeu::Cells::Empty.new(value: 'B'),
15
15
  Vedeu::Views::Char.new(value: 'C'),
16
16
  ]
17
17
  }
@@ -91,7 +91,7 @@ module Vedeu
91
91
  let(:output) {
92
92
  Vedeu::Models::Page.coerce([
93
93
  Vedeu::Views::Char.new(name: _name, value: 'N', position: [1, 1]),
94
- Vedeu::Models::Escape.new(value: "\e[?25l"),
94
+ Vedeu::Cells::Escape.new(value: "\e[?25l"),
95
95
  Vedeu::Views::Char.new(name: _name, value: 't', position: [1, 3]),
96
96
  ])
97
97
  }
@@ -164,7 +164,7 @@ module Vedeu
164
164
  let(:output) {
165
165
  Vedeu::Models::Page.coerce([
166
166
  Vedeu::Views::Char.new(name: _name, value: 'N'),
167
- Vedeu::Models::Escape.new(value: "\e[?25l"),
167
+ Vedeu::Cells::Escape.new(value: "\e[?25l"),
168
168
  Vedeu::Views::Char.new(name: _name, value: 't'),
169
169
  ])
170
170
  }
@@ -42,7 +42,7 @@ module Vedeu
42
42
 
43
43
  context 'when the output is not empty' do
44
44
  let(:output) {
45
- Vedeu::Models::Escape.new(value: "\e[?25h", position: [1, 1])
45
+ Vedeu::Cells::Escape.new(value: "\e[?25h", position: [1, 1])
46
46
  }
47
47
 
48
48
  it do
@@ -62,7 +62,7 @@ module Vedeu
62
62
  context 'when the output is not empty' do
63
63
  context 'and the output is an escape sequence' do
64
64
  let(:output) {
65
- Vedeu::Models::Escape.new(value: "\e[?25h", position: [1, 1])
65
+ Vedeu::Cells::Escape.new(value: "\e[?25h", position: [1, 1])
66
66
  }
67
67
 
68
68
  it do
@@ -78,7 +78,7 @@ module Vedeu
78
78
 
79
79
  context 'when there is content' do
80
80
  let(:output) {
81
- Vedeu::Models::Escape
81
+ Vedeu::Cells::Escape
82
82
  .new(value: Vedeu::EscapeSequences::Esc.hide_cursor)
83
83
  }
84
84
 
@@ -93,7 +93,7 @@ module Vedeu
93
93
  subject
94
94
  end
95
95
 
96
- it { subject.must_be_instance_of(Vedeu::Models::Escape) }
96
+ it { subject.must_be_instance_of(Vedeu::Cells::Escape) }
97
97
  end
98
98
 
99
99
  context 'when there is no content' do
@@ -13,17 +13,17 @@ module Vedeu
13
13
  let(:output) {
14
14
  Vedeu::Models::Page.coerce([
15
15
  [
16
- Vedeu::Models::Cell.new(position: [1, 1]),
16
+ Vedeu::Cells::Empty.new(position: [1, 1]),
17
17
  Vedeu::Views::Char.new(name: _name, value: 'a', position: [1, 2]),
18
- Vedeu::Models::Cell.new(position: [1, 3]),
18
+ Vedeu::Cells::Empty.new(position: [1, 3]),
19
19
  ], [
20
- Vedeu::Models::Cell.new(position: [2, 1]),
20
+ Vedeu::Cells::Empty.new(position: [2, 1]),
21
21
  Vedeu::Views::Char.new(name: _name, value: 'b', position: [2, 2]),
22
- Vedeu::Models::Cell.new(position: [2, 3]),
22
+ Vedeu::Cells::Empty.new(position: [2, 3]),
23
23
  ], [
24
- Vedeu::Models::Cell.new(position: [3, 1]),
24
+ Vedeu::Cells::Empty.new(position: [3, 1]),
25
25
  Vedeu::Views::Char.new(name: _name, value: 'c', position: [3, 2]),
26
- Vedeu::Models::Cell.new(position: [3, 3]),
26
+ Vedeu::Cells::Empty.new(position: [3, 3]),
27
27
  ],
28
28
  ])
29
29
  }
@@ -329,10 +329,10 @@ class VedeuMaterialColoursApp
329
329
 
330
330
  Vedeu.renders do
331
331
  view 'main_interface' do
332
- line { centre 'Red', width: 20, background: '#f44336' }
333
- line { centre 'Pink', width: 20, background: '#e91e63' }
334
- line { centre 'Purple', width: 20, background: '#9c27b0' }
335
- line { centre 'Deep Purple', width: 20, background: '#673ab7' }
332
+ line { left 'Left', background: '#f44336' }
333
+ line { centre 'Centre', background: '#e91e63' }
334
+ line { center 'Center', background: '#9c27b0' }
335
+ line { right 'Right', background: '#673ab7' }
336
336
  line { centre 'Indigo', width: 20, background: '#3f51b5' }
337
337
  line { centre 'Blue', width: 20, background: '#2196f3' }
338
338
  line { centre 'Light Blue', width: 20, background: '#03a9f4' }
@@ -516,10 +516,10 @@ class VedeuMaterialColoursApp
516
516
  view('custom_corners') do
517
517
  border do
518
518
  foreground '#000000'
519
- top_right 'B'
520
- top_left 'A'
521
- bottom_right 'D'
522
- bottom_left 'C'
519
+ top_left 'A', colour: { background: '#ff5722' }
520
+ top_right 'B', colour: { background: '#0000ff', foreground: '#ffffff' }
521
+ bottom_left 'C', colour: { background: '#ffff00', foreground: '#000000' }
522
+ bottom_right 'D', colour: { background: '#ffffff' }
523
523
  end
524
524
  lines do
525
525
  line 'custom'
@@ -529,8 +529,11 @@ class VedeuMaterialColoursApp
529
529
  view('custom_sides') do
530
530
  border do
531
531
  background '#ff5722'
532
- horizontal '*'
533
- vertical '$'
532
+
533
+ top_horizontal '*', colour: { background: '#000000', foreground: '#ffffff' }
534
+ left_vertical '$', colour: { background: '#0000ff', foreground: '#ffffff' }
535
+ right_vertical '%', colour: { background: '#ffff00', foreground: '#000000' }
536
+ bottom_horizontal '&', colour: { background: '#ffffff' }
534
537
  end
535
538
  lines do
536
539
  line 'custom'