vedeu 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/api.rb +3 -1
  3. data/lib/vedeu/application.rb +1 -1
  4. data/lib/vedeu/bindings.rb +68 -101
  5. data/lib/vedeu/cursor/cursor.rb +1 -1
  6. data/lib/vedeu/cursor/move_cursor.rb +77 -1
  7. data/lib/vedeu/cursor/toggle_cursor.rb +2 -0
  8. data/lib/vedeu/distributed/all.rb +7 -0
  9. data/lib/vedeu/distributed/client.rb +23 -11
  10. data/lib/vedeu/distributed/server.rb +8 -0
  11. data/lib/vedeu/distributed/subprocess.rb +0 -24
  12. data/lib/vedeu/distributed/uri.rb +1 -8
  13. data/lib/vedeu/dsl/all.rb +3 -0
  14. data/lib/vedeu/dsl/components/all.rb +4 -4
  15. data/lib/vedeu/dsl/components/geometry.rb +2 -0
  16. data/lib/vedeu/dsl/components/keymap.rb +14 -3
  17. data/lib/vedeu/dsl/group.rb +69 -0
  18. data/lib/vedeu/dsl/interface.rb +9 -8
  19. data/lib/vedeu/dsl/shared/text.rb +3 -1
  20. data/lib/vedeu/events/event.rb +2 -2
  21. data/lib/vedeu/input/keymap.rb +1 -1
  22. data/lib/vedeu/models/geometry.rb +1 -1
  23. data/lib/vedeu/models/group.rb +24 -10
  24. data/lib/vedeu/models/view/lines.rb +1 -0
  25. data/lib/vedeu/output/all.rb +6 -1
  26. data/lib/vedeu/output/border.rb +1 -1
  27. data/lib/vedeu/{support → output}/esc.rb +0 -0
  28. data/lib/vedeu/output/foreground.rb +1 -1
  29. data/lib/vedeu/output/html_char.rb +2 -0
  30. data/lib/vedeu/output/html_renderer.rb +6 -0
  31. data/lib/vedeu/output/output.rb +21 -0
  32. data/lib/vedeu/{support → output}/refresh.rb +1 -1
  33. data/lib/vedeu/output/renderer.rb +3 -0
  34. data/lib/vedeu/{support → output}/text.rb +0 -0
  35. data/lib/vedeu/output/virtual_terminal.rb +2 -0
  36. data/lib/vedeu/support/all.rb +0 -7
  37. data/lib/vedeu/support/coercions.rb +7 -4
  38. data/lib/vedeu/support/terminal.rb +1 -1
  39. data/lib/vedeu/support/trace.rb +1 -1
  40. data/lib/vedeu/support/visible.rb +1 -1
  41. data/test/lib/vedeu/cursor/move_cursor_test.rb +60 -1
  42. data/test/lib/vedeu/distributed/client_test.rb +21 -2
  43. data/test/lib/vedeu/dsl/group_test.rb +52 -0
  44. data/test/lib/vedeu/models/group_test.rb +11 -4
  45. data/test/lib/vedeu/{support → output}/esc_test.rb +0 -0
  46. data/test/lib/vedeu/{support → output}/refresh_test.rb +0 -0
  47. data/test/lib/vedeu/{support → output}/text_test.rb +0 -0
  48. data/test/test_helper.rb +2 -0
  49. data/vedeu.gemspec +2 -1
  50. metadata +28 -24
  51. data/lib/vedeu/output/writer.rb +0 -44
  52. data/lib/vedeu/support/console.rb +0 -90
  53. data/lib/vedeu/support/node.rb +0 -51
  54. data/lib/vedeu/support/read.rb +0 -66
  55. data/lib/vedeu/support/write.rb +0 -86
  56. data/test/lib/vedeu/output/writer_test.rb +0 -32
  57. data/test/lib/vedeu/support/console_test.rb +0 -138
  58. data/test/lib/vedeu/support/read_test.rb +0 -86
  59. data/test/lib/vedeu/support/write_test.rb +0 -158
@@ -1,86 +0,0 @@
1
- module Vedeu
2
-
3
- # The basis of a fake output device.
4
- #
5
- class Write
6
-
7
- # @see Vedeu::Write#write
8
- def self.to(console, data = nil)
9
- new(console, data).write
10
- end
11
-
12
- # @return [Vedeu::Write]
13
- def initialize(console, data = nil)
14
- @console = console
15
- @data = data
16
- end
17
-
18
- # Provides IO.console emulation of #print.
19
- #
20
- # @return [Array]
21
- def print(string = nil)
22
- @data = string unless string.nil?
23
-
24
- write
25
- end
26
-
27
- # @return [Array<Array>|Array<String>]
28
- def write
29
- streams
30
- end
31
-
32
- private
33
-
34
- attr_reader :console, :data
35
-
36
- # @return [Array<Char>|Array<String>]
37
- def streams
38
- lines.map do |line|
39
- if line.size > visible_columns
40
- line[0, visible_columns]
41
-
42
- else
43
- line
44
-
45
- end
46
- end
47
- end
48
-
49
- # @return [Array<Array>|Array<String>]
50
- def lines
51
- if content.size > visible_lines
52
- content[0, visible_lines]
53
-
54
- else
55
- content
56
-
57
- end
58
- end
59
-
60
- # @return [Array|Array<String>|Array<Array>]
61
- def content
62
- if data.nil? || data.empty?
63
- []
64
-
65
- elsif data.is_a?(String)
66
- data.split(/\n/)
67
-
68
- else
69
- data
70
-
71
- end
72
- end
73
-
74
- # @return [Fixnum]
75
- def visible_columns
76
- console.width #- 1
77
- end
78
-
79
- # @return [Fixnum]
80
- def visible_lines
81
- console.height #- 1
82
- end
83
-
84
- end # Write
85
-
86
- end # Vedeu
@@ -1,32 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- describe Writer do
6
-
7
- describe '.[]' do
8
- it 'returns a new instance of Writer' do
9
- Writer[:null, :file, :screen].must_be_instance_of(Writer)
10
- end
11
- end
12
-
13
- describe '#initialize' do
14
- it 'returns an instance of itself' do
15
- writers = :null
16
-
17
- Writer.new(writers).must_be_instance_of(Writer)
18
- end
19
- end
20
-
21
- describe '#==' do
22
- end
23
-
24
- describe '#+' do
25
- end
26
-
27
- describe '.write' do
28
- end
29
-
30
- end # Writer
31
-
32
- end # Vedeu
@@ -1,138 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- describe Console do
6
-
7
- let(:described) { Vedeu::Console }
8
- let(:instance) { described.new(height, width) }
9
- let(:height) { 24 }
10
- let(:width) { 32 }
11
-
12
- describe 'alias methods' do
13
- it { instance.must_respond_to(:tyn) }
14
- it { instance.must_respond_to(:yn) }
15
- it { instance.must_respond_to(:x) }
16
- it { instance.must_respond_to(:y) }
17
- it { instance.must_respond_to(:tx) }
18
- it { instance.must_respond_to(:ty) }
19
- it { instance.must_respond_to(:txn) }
20
- it { instance.must_respond_to(:xn) }
21
- it { instance.must_respond_to(:read) }
22
- it { instance.must_respond_to(:write) }
23
- it { instance.must_respond_to(:winsize) }
24
- end
25
-
26
- describe '#initialize' do
27
- it { instance.must_be_instance_of(described) }
28
- it { instance.instance_variable_get('@height').must_equal(height) }
29
- it { instance.instance_variable_get('@width').must_equal(width) }
30
-
31
- context 'when the height is not given' do
32
- let(:height) {}
33
-
34
- it { instance.instance_variable_get('@height').must_equal(25) }
35
- end
36
-
37
- context 'when the width is not given' do
38
- let(:width) {}
39
-
40
- it { instance.instance_variable_get('@width').must_equal(80) }
41
- end
42
- end
43
-
44
- describe '#input' do
45
- let(:data) {}
46
-
47
- subject { instance.input(data) }
48
-
49
- it { subject.must_be_instance_of(String) }
50
- end
51
-
52
- describe '#output' do
53
- let(:data) {}
54
-
55
- subject { instance.output(data) }
56
-
57
- it { subject.must_be_instance_of(Array) }
58
- end
59
-
60
- describe '#centre' do
61
- subject { instance.centre }
62
-
63
- it { subject.must_be_instance_of(Array) }
64
- it { subject.must_equal([12, 16]) }
65
- end
66
-
67
- describe '#centre_y' do
68
- subject { instance.centre_y }
69
-
70
- it { subject.must_be_instance_of(Fixnum) }
71
- it { subject.must_equal(12) }
72
- end
73
-
74
- describe '#centre_x' do
75
- subject { instance.centre_x }
76
-
77
- it { subject.must_be_instance_of(Fixnum) }
78
- it { subject.must_equal(16) }
79
- end
80
-
81
- describe '#cooked' do
82
- subject { instance.cooked }
83
-
84
- context 'when the block is not given' do
85
- it { proc { subject }.must_raise(LocalJumpError) }
86
- end
87
- end
88
-
89
- describe '#height' do
90
- subject { instance.height }
91
-
92
- it { subject.must_be_instance_of(Fixnum) }
93
-
94
- it { instance.must_respond_to(:tyn) }
95
- it { instance.must_respond_to(:yn) }
96
- end
97
-
98
- describe '#origin' do
99
- subject { instance.origin }
100
-
101
- it { subject.must_be_instance_of(Fixnum) }
102
- it { subject.must_equal(1) }
103
-
104
- it { instance.must_respond_to(:x) }
105
- it { instance.must_respond_to(:y) }
106
- it { instance.must_respond_to(:tx) }
107
- it { instance.must_respond_to(:ty) }
108
- end
109
-
110
- describe '#raw' do
111
- subject { instance.raw }
112
-
113
- context 'when the block is not given' do
114
- it { proc { subject }.must_raise(LocalJumpError) }
115
- end
116
- end
117
-
118
- describe '#size' do
119
- subject { instance.size }
120
-
121
- it { subject.must_be_instance_of(Array) }
122
- it { subject.must_equal([24, 32]) }
123
-
124
- it { instance.must_respond_to(:winsize) }
125
- end
126
-
127
- describe '#width' do
128
- subject { instance.width }
129
-
130
- it { subject.must_be_instance_of(Fixnum) }
131
-
132
- it { instance.must_respond_to(:txn) }
133
- it { instance.must_respond_to(:xn) }
134
- end
135
-
136
- end # Console
137
-
138
- end # Vedeu
@@ -1,86 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- describe Read do
6
-
7
- let(:described) { Vedeu::Read }
8
- let(:instance) { described.new(console, data) }
9
- let(:console) { Vedeu::Console.new(height, width) }
10
- let(:data) {}
11
- let(:height) { 4 }
12
- let(:width) { 30 }
13
-
14
- describe '#initialize' do
15
- it { instance.must_be_instance_of(described) }
16
- it { instance.instance_variable_get('@console').must_equal(console) }
17
- it { instance.instance_variable_get('@data').must_equal(data) }
18
- end
19
-
20
- describe '.from' do
21
- subject { described.from(console, data) }
22
-
23
- it { subject.must_be_instance_of(String) }
24
-
25
- context 'when no data is given' do
26
- it { subject.must_equal('') }
27
- end
28
-
29
- context 'when data is given' do
30
- let(:data) { 'a' }
31
-
32
- it { subject.must_equal('a') }
33
- end
34
- end
35
-
36
- describe '#getch' do
37
- let(:string) {}
38
-
39
- subject { instance.getch(string) }
40
-
41
- it { subject.must_be_instance_of(String) }
42
-
43
- context 'when no string is given' do
44
- it { subject.must_equal('') }
45
- end
46
-
47
- context 'when a multi-character string is given' do
48
- let(:string) { 'Some text...' }
49
-
50
- it { subject.must_equal('S') }
51
- end
52
-
53
- context 'when a single character string is given' do
54
- let(:string) { 'a' }
55
-
56
- it { subject.must_equal('a') }
57
- end
58
- end
59
-
60
- describe '#gets' do
61
- let(:string) {}
62
-
63
- subject { instance.gets(string) }
64
-
65
- it { subject.must_be_instance_of(String) }
66
-
67
- context 'when no string is given' do
68
- it { subject.must_equal('') }
69
- end
70
-
71
- context 'when a string with line feed is given' do
72
- let(:string) { "Some text...\n" }
73
-
74
- it { subject.must_equal('Some text...') }
75
- end
76
-
77
- context 'when a string without line feed is given' do
78
- let(:string) { 'Some text...' }
79
-
80
- it { subject.must_equal('Some text...') }
81
- end
82
- end
83
-
84
- end # Read
85
-
86
- end # Vedeu
@@ -1,158 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- describe Write do
6
-
7
- let(:described) { Vedeu::Write }
8
- let(:instance) { described.new(console, data) }
9
- let(:console) { Vedeu::Console.new(height, width) }
10
- let(:data) {}
11
- let(:height) { 3 }
12
- let(:width) { 40 }
13
-
14
- describe '#initialize' do
15
- it { instance.must_be_instance_of(described) }
16
- it { instance.instance_variable_get('@console').must_equal(console) }
17
- it { instance.instance_variable_get('@data').must_equal(data) }
18
- end
19
-
20
- describe '.to' do
21
- subject { described.to(console, data) }
22
-
23
- it { subject.must_be_instance_of(Array) }
24
-
25
- context 'when the data is larger than the visible area' do
26
- context 'when the data is a String' do
27
- let(:data) {
28
- "Zinc, in commerce also spelter, is a chemical\n" \
29
- "element with symbol Zn and atomic number 30.\n" \
30
- "It is the first element of group 12 of the\n" \
31
- "periodic table."
32
- }
33
-
34
- it { subject.must_equal(
35
- [
36
- "Zinc, in commerce also spelter, is a che",
37
- "element with symbol Zn and atomic number",
38
- "It is the first element of group 12 of t"
39
- ])
40
- }
41
- end
42
-
43
- context 'when the data is an Array' do
44
- # Zinc...
45
- # -.Zn.12
46
- # Spelter
47
- # ..Metal
48
- let(:data) {
49
- [
50
- [
51
- Vedeu::Char.new({ value: 'Z' }),
52
- Vedeu::Char.new({ value: 'i' }),
53
- Vedeu::Char.new({ value: 'n' }),
54
- Vedeu::Char.new({ value: 'c' }),
55
- Vedeu::Char.new({ value: '.' }),
56
- Vedeu::Char.new({ value: '.' }),
57
- Vedeu::Char.new({ value: '.' })
58
- ],[
59
- Vedeu::Char.new({ value: '-' }),
60
- Vedeu::Char.new({ value: '.' }),
61
- Vedeu::Char.new({ value: 'Z' }),
62
- Vedeu::Char.new({ value: 'n' }),
63
- Vedeu::Char.new({ value: '.' }),
64
- Vedeu::Char.new({ value: '1' }),
65
- Vedeu::Char.new({ value: '2' })
66
- ],[
67
- Vedeu::Char.new({ value: 'S' }),
68
- Vedeu::Char.new({ value: 'p' }),
69
- Vedeu::Char.new({ value: 'e' }),
70
- Vedeu::Char.new({ value: 'l' }),
71
- Vedeu::Char.new({ value: 't' }),
72
- Vedeu::Char.new({ value: 'e' }),
73
- Vedeu::Char.new({ value: 'r' })
74
- ],[
75
- Vedeu::Char.new({ value: '.' }),
76
- Vedeu::Char.new({ value: '.' }),
77
- Vedeu::Char.new({ value: 'M' }),
78
- Vedeu::Char.new({ value: 'e' }),
79
- Vedeu::Char.new({ value: 't' }),
80
- Vedeu::Char.new({ value: 'a' }),
81
- Vedeu::Char.new({ value: 'l' })
82
- ],
83
- ]
84
- }
85
- let(:height) { 3 }
86
- let(:width) { 5 }
87
- let(:expected) {
88
- data[0, height].map { |line| line[0, width] }
89
- }
90
-
91
- it { subject.must_equal(expected) }
92
- end
93
- end
94
-
95
- context 'when the data is not larger than the visible area' do
96
- context 'when the data is a String' do
97
- let(:data) {
98
- "Gallium is a chemical element with\n" \
99
- "symbol Ga and atomic number 31.\n"
100
- }
101
-
102
- it { subject.must_equal(
103
- [
104
- "Gallium is a chemical element with",
105
- "symbol Ga and atomic number 31."
106
- ])
107
- }
108
- end
109
-
110
- context 'when the data is an Array' do
111
- # Gallium
112
- # -.Ga.31
113
- let(:data) {
114
- [
115
- [
116
- Vedeu::Char.new({ value: 'G' }),
117
- Vedeu::Char.new({ value: 'a' }),
118
- Vedeu::Char.new({ value: 'l' }),
119
- Vedeu::Char.new({ value: 'l' }),
120
- Vedeu::Char.new({ value: 'i' }),
121
- Vedeu::Char.new({ value: 'u' }),
122
- Vedeu::Char.new({ value: 'm' })
123
- ], [
124
- Vedeu::Char.new({ value: '-' }),
125
- Vedeu::Char.new({ value: '.' }),
126
- Vedeu::Char.new({ value: 'G' }),
127
- Vedeu::Char.new({ value: 'a' }),
128
- Vedeu::Char.new({ value: '.' }),
129
- Vedeu::Char.new({ value: '3' }),
130
- Vedeu::Char.new({ value: '1' })
131
- ]
132
- ]
133
- }
134
- let(:height) { 3 }
135
- let(:width) { 10 }
136
-
137
- it { subject.must_equal(data) }
138
- end
139
- end
140
-
141
- context 'when there is no data' do
142
- let(:data) {}
143
-
144
- it { subject.must_equal([]) }
145
- end
146
- end
147
-
148
- describe '#print' do
149
- let(:string) {}
150
-
151
- subject { instance.print(string) }
152
-
153
- it { subject.must_be_instance_of(Array) }
154
- end
155
-
156
- end # Write
157
-
158
- end # Vedeu