vedeu 0.6.12 → 0.6.13
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 +4 -4
- data/lib/vedeu/bindings/application.rb +4 -0
- data/lib/vedeu/bindings/document.rb +4 -0
- data/lib/vedeu/bindings/focus.rb +4 -0
- data/lib/vedeu/bindings/menus.rb +4 -0
- data/lib/vedeu/bindings/movement.rb +4 -0
- data/lib/vedeu/bindings/refresh.rb +4 -0
- data/lib/vedeu/bindings/system.rb +4 -0
- data/lib/vedeu/bindings/visibility.rb +4 -0
- data/lib/vedeu/borders/dsl.rb +2 -3
- data/lib/vedeu/configuration/api.rb +26 -0
- data/lib/vedeu/configuration/configuration.rb +16 -0
- data/lib/vedeu/dsl/composition.rb +2 -3
- data/lib/vedeu/dsl/group.rb +2 -3
- data/lib/vedeu/dsl/interface.rb +2 -4
- data/lib/vedeu/dsl/keymap.rb +24 -21
- data/lib/vedeu/dsl/line.rb +4 -6
- data/lib/vedeu/dsl/presentation.rb +16 -12
- data/lib/vedeu/dsl/shared.rb +18 -14
- data/lib/vedeu/dsl/stream.rb +2 -3
- data/lib/vedeu/dsl/text.rb +6 -4
- data/lib/vedeu/dsl/view.rb +6 -8
- data/lib/vedeu/error.rb +12 -0
- data/lib/vedeu/geometry/area.rb +4 -2
- data/lib/vedeu/geometry/coordinate.rb +4 -4
- data/lib/vedeu/geometry/dimension.rb +6 -4
- data/lib/vedeu/geometry/dsl.rb +55 -43
- data/lib/vedeu/geometry/generic_coordinate.rb +4 -3
- data/lib/vedeu/geometry/geometry.rb +13 -11
- data/lib/vedeu/geometry/grid.rb +6 -5
- data/lib/vedeu/geometry/position.rb +12 -10
- data/lib/vedeu/input/key.rb +2 -3
- data/lib/vedeu/logging/log.rb +1 -1
- data/lib/vedeu/menus/menu.rb +2 -3
- data/lib/vedeu/models/views/view.rb +0 -2
- data/lib/vedeu/output/output.rb +10 -1
- data/lib/vedeu/output/renderers/file.rb +3 -3
- data/lib/vedeu/output/renderers/json.rb +2 -0
- data/lib/vedeu/runtime/main_loop.rb +4 -0
- data/lib/vedeu/templating/helpers.rb +4 -7
- data/lib/vedeu/terminal/buffer.rb +1 -2
- data/lib/vedeu/terminal/terminal.rb +4 -2
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/api/external_test.rb +14 -2
- data/test/lib/vedeu/bindings/visibility_test.rb +15 -0
- data/test/lib/vedeu/dsl/composition_test.rb +1 -1
- data/test/lib/vedeu/dsl/group_test.rb +1 -1
- data/test/lib/vedeu/dsl/interface_test.rb +3 -3
- data/test/lib/vedeu/dsl/line_test.rb +2 -2
- data/test/lib/vedeu/dsl/stream_test.rb +1 -1
- data/test/lib/vedeu/dsl/view_test.rb +3 -3
- data/test/lib/vedeu/error_test.rb +13 -0
- data/test/lib/vedeu/input/key_test.rb +1 -1
- data/test/lib/vedeu/menus/menu_test.rb +1 -1
- data/test/lib/vedeu/models/interface_test.rb +26 -0
- data/test/lib/vedeu/output/renderers/escape_sequence_test.rb +7 -0
- data/test/lib/vedeu/output/renderers/file_test.rb +7 -0
- data/test/lib/vedeu/output/renderers/html_test.rb +7 -0
- data/test/lib/vedeu/output/renderers/json_test.rb +7 -0
- data/test/lib/vedeu/output/renderers/null_test.rb +7 -0
- data/test/lib/vedeu/output/renderers/terminal_test.rb +11 -0
- data/test/lib/vedeu/output/renderers/text_test.rb +7 -0
- data/test/lib/vedeu/terminal/buffer_test.rb +31 -12
- data/test/lib/vedeu/terminal/terminal_test.rb +24 -21
- data/test/support/examples/material_colours_app.rb +2 -0
- data/test/test_helper.rb +2 -2
- metadata +2 -2
@@ -2,12 +2,13 @@ module Vedeu
|
|
2
2
|
|
3
3
|
module Geometry
|
4
4
|
|
5
|
-
# @todo Consider storing the Terminal size at the time of first
|
6
|
-
# this allows us to return the interface to its original
|
7
|
-
# the terminal resizes back to normal size.
|
5
|
+
# @todo Consider storing the Terminal size at the time of first
|
6
|
+
# creation, this allows us to return the interface to its original
|
7
|
+
# dimensions if the terminal resizes back to normal size.
|
8
8
|
#
|
9
|
-
# Calculates and provides interface geometry determined by both
|
10
|
-
# requirements and the terminal's current viewing
|
9
|
+
# Calculates and provides interface geometry determined by both
|
10
|
+
# the client's requirements and the terminal's current viewing
|
11
|
+
# area.
|
11
12
|
#
|
12
13
|
class Geometry
|
13
14
|
|
@@ -93,8 +94,8 @@ module Vedeu
|
|
93
94
|
end
|
94
95
|
end
|
95
96
|
|
96
|
-
# Will maximise the named interface geometry. This means it will
|
97
|
-
# all of the available space on the terminal window.
|
97
|
+
# Will maximise the named interface geometry. This means it will
|
98
|
+
# occupy all of the available space on the terminal window.
|
98
99
|
#
|
99
100
|
# @example
|
100
101
|
# Vedeu.trigger(:_maximise_, name)
|
@@ -226,10 +227,11 @@ module Vedeu
|
|
226
227
|
Vedeu::Geometry::Geometry.new(@attributes).store
|
227
228
|
end
|
228
229
|
|
229
|
-
# Will unmaximise the named interface geometry. Previously, when
|
230
|
-
# geometry was maximised, then triggering the unmaximise event
|
231
|
-
# it to its usual defined size (terminal size
|
232
|
-
# terminal has been resized, then the new
|
230
|
+
# Will unmaximise the named interface geometry. Previously, when
|
231
|
+
# a geometry was maximised, then triggering the unmaximise event
|
232
|
+
# will return it to its usual defined size (terminal size
|
233
|
+
# permitting: when the terminal has been resized, then the new
|
234
|
+
# geometry size should adapt).
|
233
235
|
#
|
234
236
|
# @example
|
235
237
|
# Vedeu.trigger(:_unmaximise_, name)
|
data/lib/vedeu/geometry/grid.rb
CHANGED
@@ -2,10 +2,10 @@ module Vedeu
|
|
2
2
|
|
3
3
|
module Geometry
|
4
4
|
|
5
|
-
# The grid system splits the terminal height and width into 12
|
6
|
-
# by dividing the available height and width by 12.
|
7
|
-
# or width is not a multiple of 12, then
|
8
|
-
# which will fit.
|
5
|
+
# The grid system splits the terminal height and width into 12
|
6
|
+
# equal parts, by dividing the available height and width by 12.
|
7
|
+
# If the terminal height or width is not a multiple of 12, then
|
8
|
+
# Grid chooses the maximum value which will fit.
|
9
9
|
#
|
10
10
|
class Grid
|
11
11
|
|
@@ -58,7 +58,8 @@ module Vedeu
|
|
58
58
|
Vedeu.height / 12
|
59
59
|
end
|
60
60
|
|
61
|
-
# Returns a boolean indicating whether the value is out of
|
61
|
+
# Returns a boolean indicating whether the value is out of
|
62
|
+
# range.
|
62
63
|
#
|
63
64
|
# @return [Boolean]
|
64
65
|
def out_of_range?
|
@@ -2,7 +2,8 @@ module Vedeu
|
|
2
2
|
|
3
3
|
module Geometry
|
4
4
|
|
5
|
-
# Change coordinates into an escape sequence to set the cursor
|
5
|
+
# Change coordinates into an escape sequence to set the cursor
|
6
|
+
# position.
|
6
7
|
#
|
7
8
|
class Position
|
8
9
|
|
@@ -48,8 +49,8 @@ module Vedeu
|
|
48
49
|
@x = (x.nil? || x < 1) ? 1 : x
|
49
50
|
end
|
50
51
|
|
51
|
-
# Converts a position into an index for the terminal. An index
|
52
|
-
# position minus 1.
|
52
|
+
# Converts a position into an index for the terminal. An index
|
53
|
+
# is the position minus 1.
|
53
54
|
#
|
54
55
|
# @return [Array<Fixnum>]
|
55
56
|
def as_indices
|
@@ -92,13 +93,14 @@ module Vedeu
|
|
92
93
|
self
|
93
94
|
end
|
94
95
|
|
95
|
-
# Return the escape sequence required to position the cursor at
|
96
|
-
# particular point on the screen. When passed a block, will do
|
97
|
-
# aforementioned, call the block and then reposition to this
|
96
|
+
# Return the escape sequence required to position the cursor at
|
97
|
+
# a particular point on the screen. When passed a block, will do
|
98
|
+
# the aforementioned, call the block and then reposition to this
|
99
|
+
# location.
|
98
100
|
#
|
99
101
|
# @return [String]
|
100
|
-
# @yieldreturn [String] Returns the block wrapped in position
|
101
|
-
# sequences.
|
102
|
+
# @yieldreturn [String] Returns the block wrapped in position
|
103
|
+
# escape sequences.
|
102
104
|
def to_s
|
103
105
|
return "#{sequence}#{yield}" if block_given?
|
104
106
|
|
@@ -136,8 +138,8 @@ module Vedeu
|
|
136
138
|
|
137
139
|
private
|
138
140
|
|
139
|
-
# Returns the escape sequence to reposition the cursors at the
|
140
|
-
# specified by x and y.
|
141
|
+
# Returns the escape sequence to reposition the cursors at the
|
142
|
+
# coordinates specified by x and y.
|
141
143
|
#
|
142
144
|
# @return [String]
|
143
145
|
def sequence
|
data/lib/vedeu/input/key.rb
CHANGED
@@ -16,11 +16,10 @@ module Vedeu
|
|
16
16
|
#
|
17
17
|
# @param input [String|Symbol]
|
18
18
|
# @param block [Proc]
|
19
|
-
# @raise [Vedeu::Error::
|
20
|
-
# not given.
|
19
|
+
# @raise [Vedeu::Error::RequiresBlock]
|
21
20
|
# @return [Vedeu::Input::Key]
|
22
21
|
def initialize(input = nil, &block)
|
23
|
-
fail Vedeu::Error::
|
22
|
+
fail Vedeu::Error::RequiresBlock unless block_given?
|
24
23
|
|
25
24
|
@input = input
|
26
25
|
@output = block
|
data/lib/vedeu/logging/log.rb
CHANGED
@@ -145,7 +145,7 @@ module Vedeu
|
|
145
145
|
drb: [:light_blue, :blue],
|
146
146
|
event: [:light_magenta, :magenta],
|
147
147
|
info: [:white, :default],
|
148
|
-
input: [:
|
148
|
+
input: [:light_red, :red],
|
149
149
|
output: [:light_green, :green],
|
150
150
|
reset: [:light_cyan, :cyan],
|
151
151
|
store: [:light_cyan, :cyan],
|
data/lib/vedeu/menus/menu.rb
CHANGED
@@ -55,11 +55,10 @@ module Vedeu
|
|
55
55
|
# # ...
|
56
56
|
# end
|
57
57
|
#
|
58
|
-
# @raise [Vedeu::Error::
|
59
|
-
# not given.
|
58
|
+
# @raise [Vedeu::Error::RequiresBlock]
|
60
59
|
# @return [API::Menu]
|
61
60
|
def self.menu(name = '', &block)
|
62
|
-
fail Vedeu::Error::
|
61
|
+
fail Vedeu::Error::RequiresBlock unless block_given?
|
63
62
|
|
64
63
|
build(name: name, &block).store
|
65
64
|
end
|
@@ -74,11 +74,9 @@ module Vedeu
|
|
74
74
|
return [] unless visible?
|
75
75
|
|
76
76
|
output = [
|
77
|
-
Vedeu::Cursors::Cursor.hide_cursor(name),
|
78
77
|
Vedeu::Clear::NamedInterface.render(name),
|
79
78
|
Vedeu::Output::Viewport.render(self),
|
80
79
|
Vedeu.borders.by_name(name).render,
|
81
|
-
Vedeu::Cursors::Cursor.show_cursor(name),
|
82
80
|
]
|
83
81
|
|
84
82
|
output
|
data/lib/vedeu/output/output.rb
CHANGED
@@ -29,13 +29,22 @@ module Vedeu
|
|
29
29
|
#
|
30
30
|
# @return [Array]
|
31
31
|
def render
|
32
|
-
Vedeu::
|
32
|
+
return render_terminal_buffer unless output.is_a?(Vedeu::Models::Escape)
|
33
|
+
|
34
|
+
Vedeu::Output::Direct.write(value: output.value,
|
35
|
+
x: output.position.x,
|
36
|
+
y: output.position.y)
|
33
37
|
end
|
34
38
|
|
35
39
|
# @!attribute [r] output
|
36
40
|
# @return [Array<Array<Vedeu::Views::Char>>]
|
37
41
|
attr_reader :output
|
38
42
|
|
43
|
+
# @return [Array]
|
44
|
+
def render_terminal_buffer
|
45
|
+
Vedeu::Terminal::Buffer.write(output).render
|
46
|
+
end
|
47
|
+
|
39
48
|
end # Output
|
40
49
|
|
41
50
|
end # Output
|
@@ -25,10 +25,10 @@ module Vedeu
|
|
25
25
|
# Render a cleared output.
|
26
26
|
#
|
27
27
|
# @return [String]
|
28
|
-
def clear
|
29
|
-
::File.write(filename,
|
28
|
+
def clear(output = '')
|
29
|
+
::File.write(filename, output) if write_file?
|
30
30
|
|
31
|
-
|
31
|
+
output
|
32
32
|
end
|
33
33
|
|
34
34
|
# @param output [Vedeu::Models::Page]
|
@@ -8,9 +8,8 @@ module Vedeu
|
|
8
8
|
|
9
9
|
# @param value [String] The HTML/CSS colour.
|
10
10
|
# @param block [Proc]
|
11
|
+
# @raise [Vedeu::Error::RequiresBlock]
|
11
12
|
# @return [Vedeu::Views::Stream]
|
12
|
-
# @raise [Vedeu::Error::InvalidSyntax] The required block was
|
13
|
-
# not given.
|
14
13
|
def background(value, &block)
|
15
14
|
define_stream(background: value, &block)
|
16
15
|
end
|
@@ -22,18 +21,16 @@ module Vedeu
|
|
22
21
|
# @option attributes background [String] The HTML/CSS background
|
23
22
|
# colour.
|
24
23
|
# @param block [Proc]
|
24
|
+
# @raise [Vedeu::Error::RequiresBlock]
|
25
25
|
# @return [Vedeu::Views::Stream]
|
26
|
-
# @raise [Vedeu::Error::InvalidSyntax] The required block was
|
27
|
-
# not given.
|
28
26
|
def colour(attributes = {}, &block)
|
29
27
|
define_stream(attributes, &block)
|
30
28
|
end
|
31
29
|
|
32
30
|
# @param value [String] The HTML/CSS colour.
|
33
31
|
# @param block [Proc]
|
32
|
+
# @raise [Vedeu::Error::RequiresBlock]
|
34
33
|
# @return [Vedeu::Views::Stream]
|
35
|
-
# @raise [Vedeu::Error::InvalidSyntax] The required block was
|
36
|
-
# not given.
|
37
34
|
def foreground(value, &block)
|
38
35
|
define_stream(foreground: value, &block)
|
39
36
|
end
|
@@ -50,7 +47,7 @@ module Vedeu
|
|
50
47
|
|
51
48
|
# @see Vedeu::Templating::Helpers#colour
|
52
49
|
def define_stream(attributes = {}, &block)
|
53
|
-
fail Vedeu::Error::
|
50
|
+
fail Vedeu::Error::RequiresBlock unless block_given?
|
54
51
|
|
55
52
|
encode(
|
56
53
|
Vedeu::Views::Stream.build(
|
@@ -130,8 +130,7 @@ module Vedeu
|
|
130
130
|
# @param value [void]
|
131
131
|
# @return [Boolean]
|
132
132
|
def within_terminal_boundary?(value)
|
133
|
-
value.position.y
|
134
|
-
value.position.x > 0 && value.position.x <= Vedeu.width
|
133
|
+
buffer[value.position.y] && buffer[value.position.y][value.position.x]
|
135
134
|
end
|
136
135
|
|
137
136
|
end # Buffer
|
@@ -12,11 +12,11 @@ module Vedeu
|
|
12
12
|
# exit, attempts to restore the screen. See
|
13
13
|
# {Vedeu::Terminal#restore_screen}.
|
14
14
|
#
|
15
|
-
# @raise [Vedeu::Error::
|
15
|
+
# @raise [Vedeu::Error::RequiresBlock] The required block was not
|
16
16
|
# given.
|
17
17
|
# @return [Array]
|
18
18
|
def open
|
19
|
-
fail Vedeu::Error::
|
19
|
+
fail Vedeu::Error::RequiresBlock unless block_given?
|
20
20
|
|
21
21
|
if raw_mode? || fake_mode?
|
22
22
|
console.raw { initialize_screen(mode) { yield } }
|
@@ -155,6 +155,7 @@ module Vedeu
|
|
155
155
|
# @return [Fixnum]
|
156
156
|
def width
|
157
157
|
return Vedeu::Configuration.drb_width if Vedeu::Configuration.drb?
|
158
|
+
return Vedeu::Configuration.width if Vedeu::Configuration.width
|
158
159
|
|
159
160
|
size[-1]
|
160
161
|
end
|
@@ -170,6 +171,7 @@ module Vedeu
|
|
170
171
|
# @return [Fixnum]
|
171
172
|
def height
|
172
173
|
return Vedeu::Configuration.drb_height if Vedeu::Configuration.drb?
|
174
|
+
return Vedeu::Configuration.height if Vedeu::Configuration.height
|
173
175
|
|
174
176
|
size.first
|
175
177
|
end
|
data/lib/vedeu/version.rb
CHANGED
@@ -30,7 +30,14 @@ module Vedeu
|
|
30
30
|
it { Vedeu.must_respond_to(:geometry) }
|
31
31
|
it { Vedeu.must_respond_to(:goto) }
|
32
32
|
it { Vedeu.must_respond_to(:group) }
|
33
|
-
|
33
|
+
|
34
|
+
describe 'Vedeu.height' do
|
35
|
+
before { Terminal.stubs(:size).returns([25, 40]) }
|
36
|
+
|
37
|
+
it { Vedeu.must_respond_to(:height) }
|
38
|
+
it { Vedeu.height.must_equal(25) }
|
39
|
+
end
|
40
|
+
|
34
41
|
it { Vedeu.must_respond_to(:hide_cursor) }
|
35
42
|
it { Vedeu.must_respond_to(:hide_group) }
|
36
43
|
it { Vedeu.must_respond_to(:hide_interface) }
|
@@ -53,8 +60,13 @@ module Vedeu
|
|
53
60
|
it { Vedeu.must_respond_to(:unbind) }
|
54
61
|
it { Vedeu.must_respond_to(:unbind_alias) }
|
55
62
|
it { Vedeu.must_respond_to(:views) }
|
56
|
-
it { Vedeu.must_respond_to(:width) }
|
57
63
|
|
64
|
+
describe 'Vedeu.width' do
|
65
|
+
before { Terminal.stubs(:size).returns([25, 40]) }
|
66
|
+
|
67
|
+
it { Vedeu.must_respond_to(:width) }
|
68
|
+
it { Vedeu.width.must_equal(40) }
|
69
|
+
end
|
58
70
|
end # External
|
59
71
|
|
60
72
|
end
|
@@ -24,6 +24,21 @@ module Vedeu
|
|
24
24
|
it { Vedeu.bound?(:_toggle_interface_).must_equal(true) }
|
25
25
|
end
|
26
26
|
|
27
|
+
# describe ':_some_event_' do
|
28
|
+
# let(:_name) { 'some_name' }
|
29
|
+
#
|
30
|
+
# before do
|
31
|
+
# # stub expectation
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# subject { Vedeu.trigger(:_some_event_, _name) }
|
35
|
+
#
|
36
|
+
# it {
|
37
|
+
# # expectation
|
38
|
+
# subject
|
39
|
+
# }
|
40
|
+
# end
|
41
|
+
|
27
42
|
end # Visibility
|
28
43
|
|
29
44
|
end # Bindings
|
@@ -28,7 +28,7 @@ module Vedeu
|
|
28
28
|
it { subject[0].must_be_instance_of(Vedeu::Views::View) }
|
29
29
|
|
30
30
|
context 'when the block is not given' do
|
31
|
-
it { proc { instance.view }.must_raise(Vedeu::Error::
|
31
|
+
it { proc { instance.view }.must_raise(Vedeu::Error::RequiresBlock) }
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -34,7 +34,7 @@ module Vedeu
|
|
34
34
|
context 'when the block is not given' do
|
35
35
|
subject { described.interface('fluorine') }
|
36
36
|
|
37
|
-
it { proc { subject }.must_raise(Vedeu::Error::
|
37
|
+
it { proc { subject }.must_raise(Vedeu::Error::RequiresBlock) }
|
38
38
|
end
|
39
39
|
|
40
40
|
context 'when the name is not given' do
|
@@ -54,7 +54,7 @@ module Vedeu
|
|
54
54
|
context 'when the block is not given' do
|
55
55
|
subject { instance.border }
|
56
56
|
|
57
|
-
it { proc { subject }.must_raise(Vedeu::Error::
|
57
|
+
it { proc { subject }.must_raise(Vedeu::Error::RequiresBlock) }
|
58
58
|
end
|
59
59
|
|
60
60
|
context 'when the block is given' do
|
@@ -182,7 +182,7 @@ module Vedeu
|
|
182
182
|
context 'when the required block is not provided' do
|
183
183
|
subject { instance.geometry }
|
184
184
|
|
185
|
-
it { proc { subject }.must_raise(Vedeu::Error::
|
185
|
+
it { proc { subject }.must_raise(Vedeu::Error::RequiresBlock) }
|
186
186
|
end
|
187
187
|
|
188
188
|
context 'when the block is given' do
|
@@ -57,7 +57,7 @@ module Vedeu
|
|
57
57
|
|
58
58
|
subject { instance.line(_value) }
|
59
59
|
|
60
|
-
it { proc { subject }.must_raise(Vedeu::Error::
|
60
|
+
it { proc { subject }.must_raise(Vedeu::Error::RequiresBlock) }
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -76,7 +76,7 @@ module Vedeu
|
|
76
76
|
|
77
77
|
context 'when the block is not given' do
|
78
78
|
it {
|
79
|
-
proc { instance.streams }.must_raise(Vedeu::Error::
|
79
|
+
proc { instance.streams }.must_raise(Vedeu::Error::RequiresBlock)
|
80
80
|
}
|
81
81
|
end
|
82
82
|
|