vedeu 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/api.md +1 -1
- data/docs/events.md +11 -8
- data/lib/vedeu/api/api.rb +19 -43
- data/lib/vedeu/api/composition.rb +13 -8
- data/lib/vedeu/api/defined.rb +14 -4
- data/lib/vedeu/api/helpers.rb +8 -5
- data/lib/vedeu/api/interface.rb +15 -21
- data/lib/vedeu/api/keymap.rb +11 -5
- data/lib/vedeu/api/line.rb +6 -7
- data/lib/vedeu/api/menu.rb +9 -17
- data/lib/vedeu/api/stream.rb +8 -6
- data/lib/vedeu/application.rb +14 -12
- data/lib/vedeu/configuration/api.rb +33 -3
- data/lib/vedeu/configuration/cli.rb +23 -3
- data/lib/vedeu/configuration/configuration.rb +3 -2
- data/lib/vedeu/input/input.rb +6 -2
- data/lib/vedeu/launcher.rb +5 -2
- data/lib/vedeu/models/attributes/background.rb +3 -2
- data/lib/vedeu/models/attributes/coercions.rb +3 -2
- data/lib/vedeu/models/attributes/colour_translator.rb +11 -4
- data/lib/vedeu/models/attributes/foreground.rb +3 -2
- data/lib/vedeu/models/attributes/presentation.rb +3 -2
- data/lib/vedeu/models/colour.rb +3 -2
- data/lib/vedeu/models/composition.rb +5 -2
- data/lib/vedeu/models/cursor.rb +3 -2
- data/lib/vedeu/models/geometry.rb +48 -6
- data/lib/vedeu/models/interface.rb +12 -2
- data/lib/vedeu/models/keymap.rb +4 -2
- data/lib/vedeu/models/line.rb +5 -2
- data/lib/vedeu/models/stream.rb +12 -2
- data/lib/vedeu/models/style.rb +3 -2
- data/lib/vedeu/output/clear.rb +5 -2
- data/lib/vedeu/output/compositor.rb +4 -2
- data/lib/vedeu/output/refresh.rb +4 -6
- data/lib/vedeu/output/render.rb +17 -14
- data/lib/vedeu/output/view.rb +5 -2
- data/lib/vedeu/repositories/buffers.rb +16 -47
- data/lib/vedeu/repositories/cursors.rb +26 -28
- data/lib/vedeu/repositories/events.rb +33 -48
- data/lib/vedeu/repositories/focus.rb +24 -20
- data/lib/vedeu/repositories/groups.rb +17 -52
- data/lib/vedeu/repositories/interfaces.rb +21 -42
- data/lib/vedeu/repositories/keymaps.rb +9 -57
- data/lib/vedeu/repositories/menus.rb +15 -55
- data/lib/vedeu/support/common.rb +2 -2
- data/lib/vedeu/support/esc.rb +35 -2
- data/lib/vedeu/support/event.rb +7 -8
- data/lib/vedeu/support/exceptions.rb +47 -0
- data/lib/vedeu/support/grid.rb +11 -4
- data/lib/vedeu/support/keymap_validator.rb +9 -14
- data/lib/vedeu/support/log.rb +13 -3
- data/lib/vedeu/support/menu.rb +3 -2
- data/lib/vedeu/support/position.rb +3 -2
- data/lib/vedeu/support/registrar.rb +2 -23
- data/lib/vedeu/support/repository.rb +77 -0
- data/lib/vedeu/support/terminal.rb +12 -2
- data/lib/vedeu/support/trace.rb +127 -20
- data/lib/vedeu.rb +11 -46
- data/test/lib/vedeu/api/api_test.rb +14 -18
- data/test/lib/vedeu/api/defined_test.rb +16 -6
- data/test/lib/vedeu/api/interface_test.rb +5 -20
- data/test/lib/vedeu/api/menu_test.rb +1 -1
- data/test/lib/vedeu/models/geometry_test.rb +41 -0
- data/test/lib/vedeu/models/interface_test.rb +14 -0
- data/test/lib/vedeu/repositories/buffers_test.rb +6 -32
- data/test/lib/vedeu/repositories/cursors_test.rb +14 -0
- data/test/lib/vedeu/repositories/events_test.rb +18 -47
- data/test/lib/vedeu/repositories/focus_test.rb +18 -5
- data/test/lib/vedeu/repositories/groups_test.rb +3 -62
- data/test/lib/vedeu/repositories/interfaces_test.rb +13 -49
- data/test/lib/vedeu/repositories/keymaps_test.rb +0 -23
- data/test/lib/vedeu/repositories/menus_test.rb +3 -62
- data/test/lib/vedeu/support/esc_test.rb +24 -0
- data/test/lib/vedeu/support/keymap_validator_test.rb +19 -38
- data/test/lib/vedeu/support/repository_test.rb +70 -0
- data/test/test_helper.rb +2 -0
- data/vedeu.gemspec +3 -3
- metadata +10 -6
@@ -0,0 +1,77 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
module Repository
|
4
|
+
|
5
|
+
# Return the whole repository.
|
6
|
+
#
|
7
|
+
# @return [Hash]
|
8
|
+
def all
|
9
|
+
storage
|
10
|
+
end
|
11
|
+
|
12
|
+
# Find the entity attributes by name.
|
13
|
+
#
|
14
|
+
# @param name [String]
|
15
|
+
# @return [Hash]
|
16
|
+
def find(name)
|
17
|
+
storage.fetch(name) { not_found(name) }
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns a collection of the names of all the registered entities.
|
21
|
+
#
|
22
|
+
# @return [Array]
|
23
|
+
def registered
|
24
|
+
storage.keys
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns a boolean indicating whether the named entity is registered.
|
28
|
+
#
|
29
|
+
# @param name [String]
|
30
|
+
# @return [Boolean]
|
31
|
+
def registered?(name)
|
32
|
+
storage.key?(name)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Reset the repository.
|
36
|
+
#
|
37
|
+
# @return [Hash]
|
38
|
+
def reset
|
39
|
+
@_storage = in_memory
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# Access to the storage for this repository.
|
45
|
+
#
|
46
|
+
# @api private
|
47
|
+
# @return [Hash]
|
48
|
+
def storage
|
49
|
+
@_storage ||= in_memory
|
50
|
+
end
|
51
|
+
|
52
|
+
# At present, validates that attributes has a `:name` key that is not nil or
|
53
|
+
# empty.
|
54
|
+
#
|
55
|
+
# @api private
|
56
|
+
# @param attributes [Hash]
|
57
|
+
# @return [TrueClass|MissingRequired]
|
58
|
+
def validate_attributes!(attributes)
|
59
|
+
return missing_required unless attributes.key?(:name)
|
60
|
+
return missing_required unless defined_value?(attributes[:name])
|
61
|
+
|
62
|
+
true
|
63
|
+
end
|
64
|
+
|
65
|
+
# Raises the MissingRequired exception.
|
66
|
+
#
|
67
|
+
# @param attr [String] A textual representation of the attribute.
|
68
|
+
# @raise [MissingRequired] When an attribute, defined by the attr parameter
|
69
|
+
# is missing.
|
70
|
+
# @return [MissingRequired]
|
71
|
+
def missing_required(attr = 'name')
|
72
|
+
fail MissingRequired, "Cannot store data without a #{attr} attribute."
|
73
|
+
end
|
74
|
+
|
75
|
+
end # Repository
|
76
|
+
|
77
|
+
end # Vedeu
|
@@ -12,14 +12,19 @@ module Vedeu
|
|
12
12
|
# attempts to restore the screen. See {Vedeu::Terminal#restore_screen}.
|
13
13
|
#
|
14
14
|
# @param block [Proc]
|
15
|
+
# @raise [InvalidSyntax] When the required block is not given.
|
15
16
|
# @return [Array]
|
16
17
|
def open(&block)
|
17
18
|
fail InvalidSyntax, '`open` requires a block.' unless block_given?
|
18
19
|
|
19
20
|
if raw_mode?
|
21
|
+
Vedeu.log("Terminal entering 'raw' mode")
|
22
|
+
|
20
23
|
console.raw { initialize_screen { yield } }
|
21
24
|
|
22
25
|
else
|
26
|
+
Vedeu.log("Terminal entering 'cooked' mode")
|
27
|
+
|
23
28
|
console.cooked { initialize_screen { yield } }
|
24
29
|
|
25
30
|
end
|
@@ -128,9 +133,13 @@ module Vedeu
|
|
128
133
|
# @return [Symbol]
|
129
134
|
def switch_mode!
|
130
135
|
if raw_mode?
|
136
|
+
Vedeu.log("Terminal switching to 'cooked' mode")
|
137
|
+
|
131
138
|
cooked_mode!
|
132
139
|
|
133
140
|
else
|
141
|
+
Vedeu.log("Terminal switching to 'raw' mode")
|
142
|
+
|
134
143
|
raw_mode!
|
135
144
|
|
136
145
|
end
|
@@ -196,5 +205,6 @@ module Vedeu
|
|
196
205
|
IO.console
|
197
206
|
end
|
198
207
|
|
199
|
-
end
|
200
|
-
|
208
|
+
end # Terminal
|
209
|
+
|
210
|
+
end # Vedeu
|
data/lib/vedeu/support/trace.rb
CHANGED
@@ -22,24 +22,26 @@ module Vedeu
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# Performs the trace operation. Building strings which include:
|
25
|
-
# - a count of classes registered with Vedeu,
|
26
|
-
# - the class name being traced,
|
27
|
-
# - the method name being traced,
|
28
|
-
# - any local variables belonging to the method.
|
25
|
+
# - (class_count) a count of classes registered with Vedeu,
|
26
|
+
# - (classname) the class name being traced,
|
27
|
+
# - (id) the method name being traced,
|
28
|
+
# - (vars) any local variables belonging to the method.
|
29
|
+
#
|
30
|
+
# @todo Deprecate, and use TracePoint instead.
|
29
31
|
#
|
30
32
|
# @return []
|
31
33
|
def trace
|
32
34
|
set_trace_func proc { |event, file, line, id, binding, classname|
|
33
|
-
if event == watched && classes.include?(classname.to_s)
|
35
|
+
if event == watched && id != :log && classes.include?(classname.to_s)
|
34
36
|
vars = variables(binding)
|
35
37
|
|
36
38
|
if vars.empty?
|
37
|
-
log_this(sprintf("
|
38
|
-
class_count,
|
39
|
+
log_this(sprintf("%s %-25s #%-20s",
|
40
|
+
class_count, classname, id))
|
39
41
|
|
40
42
|
else
|
41
|
-
log_this(sprintf("
|
42
|
-
class_count,
|
43
|
+
log_this(sprintf("%s %-25s #%-20s\n%s\n",
|
44
|
+
class_count, classname, id, vars))
|
43
45
|
|
44
46
|
end
|
45
47
|
end
|
@@ -69,11 +71,15 @@ module Vedeu
|
|
69
71
|
binding.eval('local_variables').each do |var|
|
70
72
|
variable = var.to_s
|
71
73
|
value = binding.local_variable_get(var)
|
74
|
+
valclass = value.class.to_s
|
72
75
|
output = (value.is_a?(Proc)) ? '#<Proc:...' : value.inspect
|
73
76
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
+
content = Esc.send(class_colour.fetch(valclass, :white)) { output }
|
78
|
+
|
79
|
+
entries << sprintf("%33s %-10s = %s %s", " ",
|
80
|
+
Esc.green { variable },
|
81
|
+
Esc.magenta { valclass },
|
82
|
+
content)
|
77
83
|
end
|
78
84
|
entries.join("\n")
|
79
85
|
end
|
@@ -105,24 +111,125 @@ module Vedeu
|
|
105
111
|
}
|
106
112
|
end
|
107
113
|
|
114
|
+
# @return [Hash]
|
115
|
+
def class_colour
|
116
|
+
{
|
117
|
+
'Array' => :yellow,
|
118
|
+
'Fixnum' => :cyan,
|
119
|
+
'Hash' => :blue,
|
120
|
+
'NilClass' => :red,
|
121
|
+
'String' => :green,
|
122
|
+
'Symbol' => :magenta,
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
108
126
|
# Returns the number of Vedeu classes/modules. (Useful for debugging.)
|
109
127
|
#
|
110
|
-
# @
|
111
|
-
# @return [Fixnum]
|
128
|
+
# @return [String]
|
112
129
|
def class_count
|
113
|
-
classes.size.to_s
|
130
|
+
@_count ||= "(#{classes.size.to_s}/#{vedeu_classes.size.to_s})"
|
114
131
|
end
|
115
132
|
|
116
|
-
# Returns
|
133
|
+
# Returns the classes to be traced, without exceptions or ignored classes.
|
117
134
|
#
|
118
135
|
# @api private
|
119
136
|
# @return [Set]
|
120
137
|
def classes
|
121
|
-
@_classes ||=
|
138
|
+
@_classes ||= vedeu_classes - vedeu_exceptions - ignored_classes
|
139
|
+
end
|
140
|
+
|
141
|
+
# Returns all the classes defined within Vedeu.
|
142
|
+
#
|
143
|
+
# @return [Set]
|
144
|
+
def vedeu_classes
|
145
|
+
@_vedeu_classes ||= Vedeu.constants.collect do |c|
|
122
146
|
Vedeu.const_get(c).to_s
|
123
147
|
end.to_set
|
124
148
|
end
|
125
|
-
end
|
126
|
-
# :nocov:
|
127
|
-
end
|
128
149
|
|
150
|
+
# Returns all the exceptions defined within Vedeu.
|
151
|
+
#
|
152
|
+
# @todo Vedeu should produce this set.
|
153
|
+
#
|
154
|
+
# @return [Set]
|
155
|
+
def vedeu_exceptions
|
156
|
+
Set.new [
|
157
|
+
'Vedeu::BufferNotFound',
|
158
|
+
'Vedeu::CursorNotFound',
|
159
|
+
'Vedeu::GroupNotFound',
|
160
|
+
'Vedeu::InterfaceNotFound',
|
161
|
+
'Vedeu::InvalidSyntax',
|
162
|
+
'Vedeu::KeyInUse',
|
163
|
+
'Vedeu::MenuNotFound',
|
164
|
+
'Vedeu::MissingRequired',
|
165
|
+
'Vedeu::ModeSwitch',
|
166
|
+
'Vedeu::NoInterfacesDefined',
|
167
|
+
'Vedeu::NotImplemented',
|
168
|
+
'Vedeu::OutOfRange',
|
169
|
+
]
|
170
|
+
end
|
171
|
+
|
172
|
+
# Returns a set of classes to ignore during tracing.
|
173
|
+
#
|
174
|
+
# @todo Make this configurable at runtime.
|
175
|
+
#
|
176
|
+
# @return [Set]
|
177
|
+
def ignored_classes
|
178
|
+
Set.new [
|
179
|
+
# 'Vedeu::API',
|
180
|
+
# 'Vedeu::Application',
|
181
|
+
# 'Vedeu::Area',
|
182
|
+
# 'Vedeu::Background',
|
183
|
+
# 'Vedeu::Buffers',
|
184
|
+
# 'Vedeu::Clear',
|
185
|
+
'Vedeu::Coercions',
|
186
|
+
'Vedeu::Colour',
|
187
|
+
'Vedeu::ColourTranslator',
|
188
|
+
'Vedeu::Common',
|
189
|
+
# 'Vedeu::Composition',
|
190
|
+
# 'Vedeu::Compositor',
|
191
|
+
'Vedeu::Configuration',
|
192
|
+
# 'Vedeu::Cursor',
|
193
|
+
# 'Vedeu::Cursors',
|
194
|
+
'Vedeu::Esc',
|
195
|
+
'Vedeu::Event',
|
196
|
+
# 'Vedeu::Events',
|
197
|
+
# 'Vedeu::Focus',
|
198
|
+
# 'Vedeu::Foreground',
|
199
|
+
'Vedeu::Geometry',
|
200
|
+
# 'Vedeu::Grid',
|
201
|
+
# 'Vedeu::Groups',
|
202
|
+
# 'Vedeu::Input',
|
203
|
+
# 'Vedeu::Interface',
|
204
|
+
# 'Vedeu::Interfaces',
|
205
|
+
# 'Vedeu::Keymap',
|
206
|
+
# 'Vedeu::Keymaps',
|
207
|
+
# 'Vedeu::KeymapValidator',
|
208
|
+
# 'Vedeu::Launcher',
|
209
|
+
# 'Vedeu::Line',
|
210
|
+
'Vedeu::Log',
|
211
|
+
# 'Vedeu::Menu',
|
212
|
+
# 'Vedeu::Menus',
|
213
|
+
'Vedeu::MonoLogger',
|
214
|
+
# 'Vedeu::Offset',
|
215
|
+
# 'Vedeu::Offsets',
|
216
|
+
'Vedeu::Position',
|
217
|
+
'Vedeu::Presentation',
|
218
|
+
# 'Vedeu::Refresh',
|
219
|
+
# 'Vedeu::Registrar',
|
220
|
+
# 'Vedeu::Render',
|
221
|
+
'Vedeu::Repository',
|
222
|
+
'Vedeu::Stream',
|
223
|
+
'Vedeu::Style',
|
224
|
+
'Vedeu::Terminal',
|
225
|
+
'Vedeu::Trace',
|
226
|
+
# 'Vedeu::View',
|
227
|
+
# 'Vedeu::Viewport',
|
228
|
+
]
|
229
|
+
end
|
230
|
+
|
231
|
+
# :nocov:
|
232
|
+
|
233
|
+
end # Trace
|
234
|
+
|
235
|
+
end # Vedeu
|
data/lib/vedeu.rb
CHANGED
@@ -2,50 +2,6 @@
|
|
2
2
|
#
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
# Raised when Vedeu attempts to access a named buffer that does not exist.
|
6
|
-
BufferNotFound = Class.new(StandardError)
|
7
|
-
|
8
|
-
# Raised when a cursor cannot be found by name.
|
9
|
-
CursorNotFound = Class.new(StandardError)
|
10
|
-
|
11
|
-
# Raised when trying to access a group of interfaces which do not exist by
|
12
|
-
# this name.
|
13
|
-
GroupNotFound = Class.new(StandardError)
|
14
|
-
|
15
|
-
# Raised when an interface cannot be found by name.
|
16
|
-
InterfaceNotFound = Class.new(StandardError)
|
17
|
-
|
18
|
-
# Raised when Vedeu attempts to parse a {Vedeu.view} or {Vedeu.interface} and
|
19
|
-
# encounters a problem.
|
20
|
-
InvalidSyntax = Class.new(StandardError)
|
21
|
-
|
22
|
-
# Raised when attempting to assign a key which is already in use.
|
23
|
-
KeyInUse = Class.new(StandardError)
|
24
|
-
|
25
|
-
# Raised when a menu cannot be found by name.
|
26
|
-
MenuNotFound = Class.new(StandardError)
|
27
|
-
|
28
|
-
# Raised when the attributes argument to {Vedeu::Registrar} does not contain
|
29
|
-
# a required key or the value to that key is nil or empty.
|
30
|
-
MissingRequired = Class.new(StandardError)
|
31
|
-
|
32
|
-
# Raised intentionally when the client application wishes to switch between
|
33
|
-
# cooked and raw (or vice versa) terminal modes. Vedeu is hard-wired to use
|
34
|
-
# the `Escape` key to trigger this change for the time being.
|
35
|
-
ModeSwitch = Class.new(StandardError)
|
36
|
-
|
37
|
-
# Raised when attempting to reach the currently in focus interface, when no
|
38
|
-
# interfaces have been defined yet.
|
39
|
-
NoInterfacesDefined = Class.new(StandardError)
|
40
|
-
|
41
|
-
# Raised to remind me (or client application developers) that the subclass
|
42
|
-
# implements the functionality sought.
|
43
|
-
NotImplemented = Class.new(StandardError)
|
44
|
-
|
45
|
-
# Raised when trying to access an interface column less than 1 or greater
|
46
|
-
# than 12. Vedeu is hard-wired to a 12-column layout for the time being.
|
47
|
-
OutOfRange = Class.new(StandardError)
|
48
|
-
|
49
5
|
# When Vedeu is included within one of your classes, you should have all
|
50
6
|
# API methods at your disposal.
|
51
7
|
#
|
@@ -59,7 +15,10 @@ module Vedeu
|
|
59
15
|
receiver.extend(API)
|
60
16
|
end
|
61
17
|
|
62
|
-
end
|
18
|
+
end # Vedeu
|
19
|
+
|
20
|
+
$LIB_DIR = File.dirname(__FILE__) + '/../lib'
|
21
|
+
$LOAD_PATH.unshift($LIB_DIR) unless $LOAD_PATH.include?($LIB_DIR)
|
63
22
|
|
64
23
|
require 'date'
|
65
24
|
require 'forwardable'
|
@@ -68,13 +27,17 @@ require 'logger'
|
|
68
27
|
require 'optparse'
|
69
28
|
require 'set'
|
70
29
|
|
30
|
+
require 'vedeu/support/exceptions'
|
71
31
|
require 'vedeu/support/common'
|
72
32
|
require 'vedeu/configuration/cli'
|
73
33
|
require 'vedeu/configuration/api'
|
74
34
|
require 'vedeu/configuration/configuration'
|
35
|
+
|
75
36
|
require 'vedeu/support/log'
|
76
37
|
require 'vedeu/support/trace'
|
77
38
|
|
39
|
+
require 'vedeu/api/api'
|
40
|
+
|
78
41
|
require 'vedeu/models/attributes/coercions'
|
79
42
|
require 'vedeu/models/attributes/colour_translator'
|
80
43
|
require 'vedeu/models/attributes/background'
|
@@ -82,6 +45,7 @@ require 'vedeu/models/attributes/foreground'
|
|
82
45
|
require 'vedeu/models/attributes/presentation'
|
83
46
|
require 'vedeu/models/composition'
|
84
47
|
|
48
|
+
require 'vedeu/support/repository'
|
85
49
|
require 'vedeu/support/position'
|
86
50
|
require 'vedeu/support/esc'
|
87
51
|
require 'vedeu/support/terminal'
|
@@ -99,7 +63,6 @@ require 'vedeu/models/stream'
|
|
99
63
|
require 'vedeu/repositories/events'
|
100
64
|
|
101
65
|
require 'vedeu/api/defined'
|
102
|
-
require 'vedeu/api/api'
|
103
66
|
require 'vedeu/api/composition'
|
104
67
|
require 'vedeu/api/helpers'
|
105
68
|
require 'vedeu/api/interface'
|
@@ -133,3 +96,5 @@ require 'vedeu/input/input'
|
|
133
96
|
|
134
97
|
require 'vedeu/application'
|
135
98
|
require 'vedeu/launcher'
|
99
|
+
|
100
|
+
# Vedeu::Trace.call({ trace: true })
|
@@ -19,24 +19,18 @@ module Vedeu
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '.event' do
|
22
|
-
it '
|
23
|
-
|
24
|
-
{
|
25
|
-
events: [event],
|
26
|
-
}
|
27
|
-
)
|
28
|
-
end
|
29
|
-
end
|
22
|
+
it 'delegates to the Events repository' do
|
23
|
+
Events.expects(:add)
|
30
24
|
|
31
|
-
|
32
|
-
it 'returns the Events singleton' do
|
33
|
-
Vedeu.events.must_be_instance_of(Vedeu::Events)
|
25
|
+
Vedeu.event(:some_event)
|
34
26
|
end
|
35
27
|
end
|
36
28
|
|
37
29
|
describe '.focus' do
|
38
30
|
it 'sets the named interface to be focussed' do
|
39
|
-
|
31
|
+
Vedeu.expects(:trigger).with(:_focus_by_name_, 'plutonium')
|
32
|
+
|
33
|
+
Vedeu.focus('plutonium')
|
40
34
|
end
|
41
35
|
end
|
42
36
|
|
@@ -79,20 +73,20 @@ module Vedeu
|
|
79
73
|
describe '.log' do
|
80
74
|
it 'writes the message to the log file when debugging is enabled' do
|
81
75
|
Configuration.stub(:debug?, true) do
|
82
|
-
Vedeu.log('
|
76
|
+
Vedeu.log('Testing debugging to log').must_equal(true)
|
83
77
|
end
|
84
78
|
end
|
85
79
|
|
86
80
|
it 'returns nil when debugging is disabled' do
|
87
81
|
Configuration.stub(:debug?, false) do
|
88
|
-
Vedeu.log('some message...').must_equal(nil)
|
82
|
+
Vedeu.log('some message not logged...').must_equal(nil)
|
89
83
|
end
|
90
84
|
end
|
91
85
|
|
92
86
|
it 'write the message to the log file when the `force` argument ' \
|
93
87
|
'evaluates to true' do
|
94
88
|
Configuration.stub(:debug?, false) do
|
95
|
-
Vedeu.log('
|
89
|
+
Vedeu.log('Testing forced debugging to log', true).must_equal(true)
|
96
90
|
end
|
97
91
|
end
|
98
92
|
end
|
@@ -112,7 +106,7 @@ module Vedeu
|
|
112
106
|
end
|
113
107
|
|
114
108
|
describe '.resize' do
|
115
|
-
it 'triggers the :_clear_ and :
|
109
|
+
it 'triggers the :_clear_, :_refresh_ and :_cursor_refresh_ events' do
|
116
110
|
skip
|
117
111
|
end
|
118
112
|
end
|
@@ -127,7 +121,9 @@ module Vedeu
|
|
127
121
|
describe '.unevent' do
|
128
122
|
it 'unregister the event by name' do
|
129
123
|
Vedeu.event(:calcium) { proc { |x| x } }
|
130
|
-
|
124
|
+
Events.registered.must_include(:calcium)
|
125
|
+
Vedeu.unevent(:calcium)
|
126
|
+
Events.registered.wont_include(:calcium)
|
131
127
|
end
|
132
128
|
end
|
133
129
|
|
@@ -139,7 +135,7 @@ module Vedeu
|
|
139
135
|
.must_raise(Vedeu::InterfaceNotFound)
|
140
136
|
end
|
141
137
|
|
142
|
-
it 'returns' do
|
138
|
+
it 'returns an instance of the named interface' do
|
143
139
|
Vedeu.interface('aluminium')
|
144
140
|
|
145
141
|
Vedeu.use('aluminium').must_be_instance_of(Vedeu::Interface)
|
@@ -4,12 +4,6 @@ module Vedeu
|
|
4
4
|
module API
|
5
5
|
describe Defined do
|
6
6
|
describe '#events' do
|
7
|
-
it 'returns no events when none currently registered' do
|
8
|
-
Vedeu.stub(:events, Events.new) do
|
9
|
-
Defined.events.must_equal([])
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
7
|
it 'returns all events currently registered' do
|
14
8
|
Vedeu.event(:birthday) { :eat_too_much_cake }
|
15
9
|
|
@@ -45,6 +39,22 @@ module Vedeu
|
|
45
39
|
end
|
46
40
|
end
|
47
41
|
|
42
|
+
describe '#keymaps' do
|
43
|
+
before { Vedeu::Keymaps.reset }
|
44
|
+
|
45
|
+
it 'returns the default keymap when no others are registered' do
|
46
|
+
Defined.keymaps.must_equal(['_global_keymap_'])
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns all keymaps currently registered' do
|
50
|
+
Vedeu.keys('flerovium') do
|
51
|
+
key('u') { :some_action }
|
52
|
+
end
|
53
|
+
|
54
|
+
Defined.keymaps.must_equal(['_global_keymap_', 'flerovium'])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
48
58
|
describe '#menus' do
|
49
59
|
before { Vedeu::Menus.reset }
|
50
60
|
|
@@ -2,6 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
module API
|
5
|
+
|
5
6
|
describe Interface do
|
6
7
|
before { Vedeu::Buffers.reset }
|
7
8
|
|
@@ -112,28 +113,12 @@ module Vedeu
|
|
112
113
|
end
|
113
114
|
|
114
115
|
describe '#centred' do
|
115
|
-
it '
|
116
|
-
|
117
|
-
Vedeu.interface 'boron' do
|
118
|
-
centred :invalid
|
119
|
-
end
|
120
|
-
}.must_raise(InvalidSyntax)
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'sets the centred to true (visible)' do
|
124
|
-
Vedeu.interface 'boron' do
|
125
|
-
centred true
|
126
|
-
end
|
127
|
-
|
128
|
-
Vedeu.use('boron').attributes[:geometry][:centred].must_equal(true)
|
116
|
+
it 'returns false if the value is false or nil' do
|
117
|
+
API::Interface.new.centred(false).must_equal(false)
|
129
118
|
end
|
130
119
|
|
131
|
-
it '
|
132
|
-
|
133
|
-
centred false
|
134
|
-
end
|
135
|
-
|
136
|
-
Vedeu.use('boron').attributes[:geometry][:centred].must_equal(false)
|
120
|
+
it 'returns true' do
|
121
|
+
API::Interface.new.centred.must_equal(true)
|
137
122
|
end
|
138
123
|
end
|
139
124
|
|
@@ -12,7 +12,7 @@ module Vedeu
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'raises an exception if no name was specified for the menu' do
|
15
|
-
proc { Menu.define { } }.must_raise(
|
15
|
+
proc { Menu.define { } }.must_raise(MissingRequired)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'adds the menu to the menus repository' do
|
@@ -234,5 +234,46 @@ module Vedeu
|
|
234
234
|
geometry.east.must_equal(26)
|
235
235
|
end
|
236
236
|
end
|
237
|
+
|
238
|
+
describe '#virtual_y' do
|
239
|
+
it 'returns the virtual y positions within the interfaces dimensions' do
|
240
|
+
geometry = Geometry.new({ height: 6, width: 6, x: 7, y: 5 })
|
241
|
+
geometry.virtual_y.must_equal([5, 6, 7, 8, 9, 10])
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe '#virtual_x' do
|
246
|
+
it 'returns the virtual x positions within the interfaces dimensions' do
|
247
|
+
geometry = Geometry.new({ height: 6, width: 6, x: 7, y: 5 })
|
248
|
+
geometry.virtual_x.must_equal([7, 8, 9, 10, 11, 12])
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
describe '#to_h' do
|
253
|
+
it 'returns all the values within the instance as a hash' do
|
254
|
+
geometry = Geometry.new({ height: 6, width: 6, x: 3, y: 3 })
|
255
|
+
geometry.to_h.must_equal(
|
256
|
+
{
|
257
|
+
centred: false,
|
258
|
+
height: 6,
|
259
|
+
width: 6,
|
260
|
+
x: 3,
|
261
|
+
y: 3,
|
262
|
+
viewport_height: 6,
|
263
|
+
viewport_width: 6,
|
264
|
+
top: 3,
|
265
|
+
right: 9,
|
266
|
+
bottom: 9,
|
267
|
+
left: 3,
|
268
|
+
north: 2,
|
269
|
+
east: 10,
|
270
|
+
south: 10,
|
271
|
+
west: 2,
|
272
|
+
virtual_x: [3, 4, 5, 6, 7, 8],
|
273
|
+
virtual_y: [3, 4, 5, 6, 7, 8]
|
274
|
+
}
|
275
|
+
)
|
276
|
+
end
|
277
|
+
end
|
237
278
|
end
|
238
279
|
end
|
@@ -60,6 +60,20 @@ module Vedeu
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
describe '#in_focus?' do
|
64
|
+
context 'when the interface is currently in focus' do
|
65
|
+
before { Focus.stubs(:current?).returns(true) }
|
66
|
+
|
67
|
+
it { interface.in_focus?.must_equal(true) }
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when the interface is not currently in focus' do
|
71
|
+
before { Focus.stubs(:current?).returns(false) }
|
72
|
+
|
73
|
+
it { interface.in_focus?.must_equal(false) }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
63
77
|
describe '#group' do
|
64
78
|
it 'returns the value' do
|
65
79
|
interface.group.must_equal('my_group')
|