vedeu 0.2.10 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/events.md +6 -0
- data/examples/{cursor_app/cursor_app.rb → cursor_app.rb} +1 -1
- data/examples/{lines_app/lines_app.rb → lines_app.rb} +1 -1
- data/lib/vedeu.rb +48 -28
- data/lib/vedeu/api/api.rb +8 -95
- data/lib/vedeu/application.rb +6 -2
- data/lib/vedeu/{models → colours}/background.rb +1 -1
- data/lib/vedeu/{models → colours}/colour.rb +0 -0
- data/lib/vedeu/{models → colours}/foreground.rb +2 -2
- data/lib/vedeu/{support/colour_translator.rb → colours/translator.rb} +7 -7
- data/lib/vedeu/input/input.rb +13 -5
- data/lib/vedeu/models/geometry.rb +30 -2
- data/lib/vedeu/models/key.rb +39 -0
- data/lib/vedeu/output/compositor.rb +30 -76
- data/lib/vedeu/output/output.rb +74 -0
- data/lib/vedeu/output/viewport.rb +36 -44
- data/lib/vedeu/repositories/buffers.rb +5 -18
- data/lib/vedeu/repositories/cursors.rb +16 -8
- data/lib/vedeu/repositories/events.rb +96 -9
- data/lib/vedeu/repositories/focus.rb +21 -20
- data/lib/vedeu/repositories/groups.rb +3 -11
- data/lib/vedeu/repositories/interfaces.rb +6 -9
- data/lib/vedeu/repositories/keymaps.rb +8 -3
- data/lib/vedeu/repositories/menus.rb +6 -21
- data/lib/vedeu/{models → repositories/models}/buffer.rb +62 -28
- data/lib/vedeu/{models → repositories/models}/cursor.rb +8 -2
- data/lib/vedeu/{models → repositories/models}/event.rb +7 -0
- data/lib/vedeu/repositories/models/group.rb +56 -0
- data/lib/vedeu/{models → repositories/models}/interface.rb +6 -0
- data/lib/vedeu/{models → repositories/models}/keymap.rb +7 -1
- data/lib/vedeu/{models → repositories/models}/menu.rb +9 -0
- data/lib/vedeu/{models → repositories/models}/offset.rb +8 -1
- data/lib/vedeu/repositories/offsets.rb +17 -12
- data/lib/vedeu/support/bounding_area.rb +127 -0
- data/lib/vedeu/support/common.rb +8 -0
- data/lib/vedeu/support/exceptions.rb +2 -12
- data/lib/vedeu/support/model.rb +14 -0
- data/lib/vedeu/support/refresh.rb +8 -7
- data/lib/vedeu/support/registrar.rb +7 -1
- data/lib/vedeu/support/repository.rb +31 -10
- data/lib/vedeu/support/sentence.rb +67 -0
- data/lib/vedeu/support/terminal.rb +19 -0
- data/lib/vedeu/support/trace.rb +2 -5
- data/test/integration/api/api_test.rb +97 -0
- data/test/integration/api_dsl/dsl_api_test.rb +4 -0
- data/test/integration/api_dsl/dsl_composition_test.rb +4 -0
- data/test/integration/api_dsl/dsl_defined_test.rb +4 -0
- data/test/integration/api_dsl/dsl_helpers_test.rb +4 -0
- data/test/integration/api_dsl/dsl_interface_test.rb +4 -0
- data/test/integration/api_dsl/dsl_keymap.rb +4 -0
- data/test/integration/api_dsl/dsl_line_test.rb +4 -0
- data/test/integration/api_dsl/dsl_menu_test.rb +4 -0
- data/test/integration/api_dsl/dsl_stream_test.rb +138 -0
- data/test/lib/vedeu/api/api_test.rb +1 -25
- data/test/lib/vedeu/api/helpers_test.rb +0 -10
- data/test/lib/vedeu/{models → colours}/background_test.rb +0 -0
- data/test/lib/vedeu/{models → colours}/colour_test.rb +0 -0
- data/test/lib/vedeu/{models → colours}/foreground_test.rb +0 -0
- data/test/lib/vedeu/{support/colour_translator_test.rb → colours/translator_test.rb} +3 -3
- data/test/lib/vedeu/input/input_test.rb +16 -47
- data/test/lib/vedeu/models/geometry_test.rb +46 -0
- data/test/lib/vedeu/models/group_test.rb +99 -0
- data/test/lib/vedeu/models/key_test.rb +41 -0
- data/test/lib/vedeu/output/compositor_test.rb +25 -101
- data/test/lib/vedeu/output/output_test.rb +108 -0
- data/test/lib/vedeu/repositories/buffers_test.rb +0 -8
- data/test/lib/vedeu/repositories/cursors_test.rb +34 -0
- data/test/lib/vedeu/repositories/focus_test.rb +37 -28
- data/test/lib/vedeu/repositories/interfaces_test.rb +1 -1
- data/test/lib/vedeu/repositories/keymaps_test.rb +6 -20
- data/test/lib/vedeu/repositories/menus_test.rb +0 -6
- data/test/lib/vedeu/{models → repositories/models}/buffer_test.rb +24 -27
- data/test/lib/vedeu/{models → repositories/models}/cursor_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/event_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/interface_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/keymap_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/menu_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/offset_test.rb +0 -0
- data/test/lib/vedeu/support/bounding_area_test.rb +139 -0
- data/test/lib/vedeu/support/coercions_test.rb +6 -17
- data/test/lib/vedeu/support/grid_test.rb +1 -1
- data/test/lib/vedeu/support/model_test.rb +23 -0
- data/test/lib/vedeu/support/presentation_test.rb +0 -10
- data/test/lib/vedeu/support/refresh_test.rb +2 -2
- data/test/lib/vedeu/support/repository_test.rb +63 -64
- data/test/lib/vedeu/support/sentence_test.rb +48 -0
- data/test/lib/vedeu/support/terminal_test.rb +86 -6
- data/test/support/test_classes/all.rb +5 -0
- data/test/support/test_classes/coercions.rb +16 -0
- data/test/support/test_classes/helpers.rb +19 -0
- data/test/support/test_classes/model.rb +23 -0
- data/test/support/test_classes/presentation.rb +16 -0
- data/test/support/test_classes/repositories.rb +26 -0
- data/test/support/test_modules/all.rb +1 -0
- data/test/support/test_modules/repository.rb +16 -0
- data/test/test_helper.rb +4 -0
- data/vedeu.gemspec +3 -3
- metadata +95 -50
- data/lib/vedeu/output/clear.rb +0 -88
- data/lib/vedeu/output/render.rb +0 -50
- data/lib/vedeu/repositories/positional.rb +0 -23
- data/test/lib/vedeu/output/clear_test.rb +0 -56
- data/test/lib/vedeu/output/render_test.rb +0 -100
- data/test/lib/vedeu/repositories/positional_test.rb +0 -50
@@ -6,6 +6,7 @@ module Vedeu
|
|
6
6
|
# @api private
|
7
7
|
class Cursor
|
8
8
|
|
9
|
+
include Model
|
9
10
|
extend Forwardable
|
10
11
|
|
11
12
|
def_delegators :interface, :top, :right, :bottom, :left
|
@@ -94,7 +95,7 @@ module Vedeu
|
|
94
95
|
def show
|
95
96
|
@state = :show
|
96
97
|
|
97
|
-
|
98
|
+
store
|
98
99
|
end
|
99
100
|
|
100
101
|
# Make the cursor invisible.
|
@@ -103,7 +104,7 @@ module Vedeu
|
|
103
104
|
def hide
|
104
105
|
@state = :hide
|
105
106
|
|
106
|
-
|
107
|
+
store
|
107
108
|
end
|
108
109
|
|
109
110
|
# Returns an escape sequence to position the cursor and set its visibility.
|
@@ -124,6 +125,11 @@ module Vedeu
|
|
124
125
|
|
125
126
|
private
|
126
127
|
|
128
|
+
# @return [Class] The repository class for this model.
|
129
|
+
def repository
|
130
|
+
Vedeu::Cursors
|
131
|
+
end
|
132
|
+
|
127
133
|
# Returns the escape sequence to position the cursor and set its visibility.
|
128
134
|
#
|
129
135
|
# @return [String]
|
@@ -5,6 +5,8 @@ module Vedeu
|
|
5
5
|
# @api private
|
6
6
|
class Event
|
7
7
|
|
8
|
+
include Model
|
9
|
+
|
8
10
|
# Returns a new instance of Event.
|
9
11
|
#
|
10
12
|
# @param name [Symbol]
|
@@ -37,6 +39,11 @@ module Vedeu
|
|
37
39
|
attr_reader :closure, :name
|
38
40
|
attr_accessor :deadline, :executed_at, :now
|
39
41
|
|
42
|
+
# @return [Class] The repository class for this model.
|
43
|
+
def repository
|
44
|
+
Vedeu::Events
|
45
|
+
end
|
46
|
+
|
40
47
|
# Execute the code stored in the event closure.
|
41
48
|
#
|
42
49
|
# @param args []
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
# Interfaces can be associated with one another by being members of the same
|
4
|
+
# Group. A Group is a collection of interface names.
|
5
|
+
#
|
6
|
+
class Group
|
7
|
+
|
8
|
+
attr_reader :name
|
9
|
+
|
10
|
+
# Return a new instance of Group.
|
11
|
+
#
|
12
|
+
# @param name [String] The name of the group.
|
13
|
+
# @param members [String]
|
14
|
+
# @return [Group]
|
15
|
+
def initialize(name, *members)
|
16
|
+
@members = members.to_set
|
17
|
+
@name = name
|
18
|
+
end
|
19
|
+
|
20
|
+
# Add a member to the group by name.
|
21
|
+
#
|
22
|
+
# @param member [String]
|
23
|
+
# @return [Group]
|
24
|
+
def add(member)
|
25
|
+
new_members = @members.add(member)
|
26
|
+
|
27
|
+
Group.new(name, *new_members)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns the members as a collection.
|
31
|
+
#
|
32
|
+
# @return [Array]
|
33
|
+
def members
|
34
|
+
@members.to_a
|
35
|
+
end
|
36
|
+
|
37
|
+
# Remove a member from the group by name.
|
38
|
+
#
|
39
|
+
# @param member [String]
|
40
|
+
# @return [Group]
|
41
|
+
def remove(member)
|
42
|
+
new_members = @members.delete(member)
|
43
|
+
|
44
|
+
Group.new(name, *new_members)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Remove all members from the group.
|
48
|
+
#
|
49
|
+
# @return [Group]
|
50
|
+
def reset
|
51
|
+
Group.new(name)
|
52
|
+
end
|
53
|
+
|
54
|
+
end # Group
|
55
|
+
|
56
|
+
end # Vedeu
|
@@ -9,6 +9,7 @@ module Vedeu
|
|
9
9
|
|
10
10
|
include Coercions
|
11
11
|
include Common
|
12
|
+
include Model
|
12
13
|
include Presentation
|
13
14
|
|
14
15
|
extend Forwardable
|
@@ -117,6 +118,11 @@ module Vedeu
|
|
117
118
|
|
118
119
|
private
|
119
120
|
|
121
|
+
# @return [Class] The repository class for this model.
|
122
|
+
def repository
|
123
|
+
Vedeu::Interfaces
|
124
|
+
end
|
125
|
+
|
120
126
|
# The default values for a new instance of Interface.
|
121
127
|
#
|
122
128
|
# @return [Hash]
|
@@ -7,6 +7,7 @@ module Vedeu
|
|
7
7
|
class Keymap
|
8
8
|
|
9
9
|
include Common
|
10
|
+
include Model
|
10
11
|
|
11
12
|
attr_reader :attributes
|
12
13
|
|
@@ -73,13 +74,18 @@ module Vedeu
|
|
73
74
|
instance_eval(&block)
|
74
75
|
end
|
75
76
|
|
76
|
-
|
77
|
+
repository.add(attributes)
|
77
78
|
|
78
79
|
self
|
79
80
|
end
|
80
81
|
|
81
82
|
private
|
82
83
|
|
84
|
+
# @return [Class] The repository class for this model.
|
85
|
+
def repository
|
86
|
+
Vedeu::Keymaps
|
87
|
+
end
|
88
|
+
|
83
89
|
# The default attributes of the Keymap model.
|
84
90
|
#
|
85
91
|
# @return [Hash]
|
@@ -6,6 +6,8 @@ module Vedeu
|
|
6
6
|
# @api private
|
7
7
|
class Menu
|
8
8
|
|
9
|
+
include Model
|
10
|
+
|
9
11
|
# Returns a new instance of Menu.
|
10
12
|
#
|
11
13
|
# @param collection [Array]
|
@@ -157,6 +159,13 @@ module Vedeu
|
|
157
159
|
@collection.size
|
158
160
|
end
|
159
161
|
|
162
|
+
private
|
163
|
+
|
164
|
+
# @return [Class] The repository class for this model.
|
165
|
+
def repository
|
166
|
+
Vedeu::Menus
|
167
|
+
end
|
168
|
+
|
160
169
|
end # Menu
|
161
170
|
|
162
171
|
end # Vedeu
|
@@ -11,6 +11,8 @@ module Vedeu
|
|
11
11
|
# @api private
|
12
12
|
class Offset
|
13
13
|
|
14
|
+
include Model
|
15
|
+
|
14
16
|
attr_reader :name
|
15
17
|
|
16
18
|
# Returns a new instance of Offset.
|
@@ -45,7 +47,7 @@ module Vedeu
|
|
45
47
|
@y += relative_y
|
46
48
|
@x += relative_x
|
47
49
|
|
48
|
-
|
50
|
+
store
|
49
51
|
end
|
50
52
|
|
51
53
|
# Returns the current x offset, correcting to 0 if less than 0.
|
@@ -68,6 +70,11 @@ module Vedeu
|
|
68
70
|
|
69
71
|
private
|
70
72
|
|
73
|
+
# @return [Class] The repository class for this model.
|
74
|
+
def repository
|
75
|
+
Vedeu::Offsets
|
76
|
+
end
|
77
|
+
|
71
78
|
# Return the default values for an instance of Offset.
|
72
79
|
#
|
73
80
|
# @return [Hash]
|
@@ -7,9 +7,22 @@ module Vedeu
|
|
7
7
|
module Offsets
|
8
8
|
|
9
9
|
include Repository
|
10
|
-
include Positional
|
11
10
|
extend self
|
12
11
|
|
12
|
+
# Add or update the offset coordinates.
|
13
|
+
#
|
14
|
+
# @param attributes [Hash]
|
15
|
+
# @return [Offset]
|
16
|
+
def add(attributes)
|
17
|
+
validate_attributes!(attributes)
|
18
|
+
|
19
|
+
Vedeu.log("#{action(__callee__)} positional (#{model}): " \
|
20
|
+
"'#{attributes[:name]}'")
|
21
|
+
|
22
|
+
model.new(attributes).store
|
23
|
+
end
|
24
|
+
alias_method :update, :add
|
25
|
+
|
13
26
|
# @return [Array]
|
14
27
|
def down
|
15
28
|
move(1, 0)
|
@@ -41,9 +54,9 @@ module Vedeu
|
|
41
54
|
Focus.refresh
|
42
55
|
end
|
43
56
|
|
44
|
-
# @return [Class]
|
45
|
-
def
|
46
|
-
Offset
|
57
|
+
# @return [Class] The model class for this repository.
|
58
|
+
def model
|
59
|
+
Vedeu::Offset
|
47
60
|
end
|
48
61
|
|
49
62
|
# @return [Hash]
|
@@ -51,14 +64,6 @@ module Vedeu
|
|
51
64
|
{}
|
52
65
|
end
|
53
66
|
|
54
|
-
# System events which when called will move in the direction specified;
|
55
|
-
# these will update the cursor position or content offset (scrolling)
|
56
|
-
# according to the interface in focus.
|
57
|
-
Vedeu.event(:_cursor_up_) { up }
|
58
|
-
Vedeu.event(:_cursor_right_) { right }
|
59
|
-
Vedeu.event(:_cursor_down_) { down }
|
60
|
-
Vedeu.event(:_cursor_left_) { left }
|
61
|
-
|
62
67
|
end # Offsets
|
63
68
|
|
64
69
|
end # Vedeu
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
class BoundingArea
|
4
|
+
|
5
|
+
attr_reader :height, :width
|
6
|
+
|
7
|
+
# Returns an instance of BoundingArea.
|
8
|
+
#
|
9
|
+
# @param height [Fixnum]
|
10
|
+
# @param width [Fixnum]
|
11
|
+
# @return [ConsoleGeometry]
|
12
|
+
def initialize(height, width)
|
13
|
+
@height = height
|
14
|
+
@width = width
|
15
|
+
end
|
16
|
+
|
17
|
+
# Returns the top line (y) coordinate for the console.
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# # height = 20
|
21
|
+
#
|
22
|
+
# top # => 1
|
23
|
+
# top(5) # => 6
|
24
|
+
# top(-5) # => 1
|
25
|
+
# top(25) # => 20
|
26
|
+
#
|
27
|
+
# @param offset [Fixnum] When provided, returns the top coordinate plus
|
28
|
+
# the offset.
|
29
|
+
# @return [Fixnum]
|
30
|
+
def top(offset = 0)
|
31
|
+
if offset >= height
|
32
|
+
height
|
33
|
+
|
34
|
+
elsif offset <= 1
|
35
|
+
1
|
36
|
+
|
37
|
+
else
|
38
|
+
1 + offset
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
alias_method :y, :top
|
43
|
+
|
44
|
+
# Returns the bottom line (yn) coordinate for the console.
|
45
|
+
#
|
46
|
+
# @example
|
47
|
+
# # height = 20
|
48
|
+
#
|
49
|
+
# bottom # => 20
|
50
|
+
# bottom(5) # => 15
|
51
|
+
# bottom(-5) # => 20
|
52
|
+
# bottom(25) # => 1
|
53
|
+
#
|
54
|
+
# @param offset [Fixnum] When provided, returns the bottom coordinate minus
|
55
|
+
# the offset.
|
56
|
+
# @return [Fixnum]
|
57
|
+
def bottom(offset = 0)
|
58
|
+
if offset >= height
|
59
|
+
1
|
60
|
+
|
61
|
+
elsif offset < 0
|
62
|
+
height
|
63
|
+
|
64
|
+
else
|
65
|
+
height - offset
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
alias_method :yn, :bottom
|
70
|
+
|
71
|
+
# Returns the leftmost column (x) coordinate for the console.
|
72
|
+
#
|
73
|
+
# @example
|
74
|
+
# # width = 40
|
75
|
+
#
|
76
|
+
# left # => 1
|
77
|
+
# left(5) # => 6
|
78
|
+
# left(-5) # => 1
|
79
|
+
# left(45) # => 40
|
80
|
+
#
|
81
|
+
# @param offset [Fixnum] When provided, returns the left coordinate plus
|
82
|
+
# the offset.
|
83
|
+
# @return [Fixnum]
|
84
|
+
def left(offset = 0)
|
85
|
+
if offset >= width
|
86
|
+
width
|
87
|
+
|
88
|
+
elsif offset <= 1
|
89
|
+
1
|
90
|
+
|
91
|
+
else
|
92
|
+
1 + offset
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
alias_method :x, :left
|
97
|
+
|
98
|
+
# Returns the rightmost column (yn) coordinate for the console.
|
99
|
+
#
|
100
|
+
# @example
|
101
|
+
# # width = 40
|
102
|
+
#
|
103
|
+
# right # => 40
|
104
|
+
# right(5) # => 35
|
105
|
+
# right(-5) # => 40
|
106
|
+
# right(45) # => 1
|
107
|
+
#
|
108
|
+
# @param offset [Fixnum] When provided, returns the right coordinate minus
|
109
|
+
# the offset.
|
110
|
+
# @return [Fixnum]
|
111
|
+
def right(offset = 0)
|
112
|
+
if offset >= width
|
113
|
+
1
|
114
|
+
|
115
|
+
elsif offset < 0
|
116
|
+
width
|
117
|
+
|
118
|
+
else
|
119
|
+
width - offset
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
alias_method :xn, :right
|
124
|
+
|
125
|
+
end # BoundingArea
|
126
|
+
|
127
|
+
end # Vedeu
|
data/lib/vedeu/support/common.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
# Raised
|
4
|
-
|
5
|
-
|
6
|
-
# Raised when trying to access a group of interfaces which do not exist by
|
7
|
-
# this name.
|
8
|
-
GroupNotFound = Class.new(StandardError)
|
9
|
-
|
10
|
-
# Raised when an interface cannot be found by name.
|
11
|
-
InterfaceNotFound = Class.new(StandardError)
|
3
|
+
# Raised with Vedeu attempts to access a named model that does not exist.
|
4
|
+
ModelNotFound = Class.new(StandardError)
|
12
5
|
|
13
6
|
# Raised when Vedeu attempts to parse a {Vedeu.view} or {Vedeu.interface} and
|
14
7
|
# encounters a problem.
|
@@ -17,9 +10,6 @@ module Vedeu
|
|
17
10
|
# Raised when attempting to assign a key which is already in use.
|
18
11
|
KeyInUse = Class.new(StandardError)
|
19
12
|
|
20
|
-
# Raised when a menu cannot be found by name.
|
21
|
-
MenuNotFound = Class.new(StandardError)
|
22
|
-
|
23
13
|
# Raised when the attributes argument to {Vedeu::Registrar} does not contain
|
24
14
|
# a required key or the value to that key is nil or empty.
|
25
15
|
MissingRequired = Class.new(StandardError)
|