vedeu 0.6.7 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/docs/dsl.md +4 -4
- data/lib/vedeu/all.rb +6 -18
- data/lib/vedeu/api.rb +14 -13
- data/lib/vedeu/bindings/system.rb +5 -4
- data/lib/vedeu/buffers/virtual_buffer.rb +13 -11
- data/lib/vedeu/configuration/api.rb +4 -3
- data/lib/vedeu/cursors/cursor.rb +23 -18
- data/lib/vedeu/distributed/client.rb +11 -6
- data/lib/vedeu/distributed/server.rb +4 -3
- data/lib/vedeu/dsl/keymap.rb +6 -6
- data/lib/vedeu/editor/all.rb +19 -0
- data/lib/vedeu/{input/editor → editor}/capture.rb +1 -1
- data/lib/vedeu/{input/editor → editor}/cropper.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/cursor.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/document.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/documents.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/editor.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/insert.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/line.rb +0 -0
- data/lib/vedeu/{input/editor → editor}/lines.rb +0 -0
- data/lib/vedeu/error.rb +21 -18
- data/lib/vedeu/esc/borders.rb +6 -4
- data/lib/vedeu/esc/colours.rb +13 -12
- data/lib/vedeu/esc/esc.rb +11 -10
- data/lib/vedeu/input/all.rb +15 -0
- data/lib/vedeu/input/input.rb +55 -52
- data/lib/vedeu/input/key.rb +36 -30
- data/lib/vedeu/input/keymap.rb +101 -92
- data/lib/vedeu/input/keymaps.rb +10 -6
- data/lib/vedeu/input/keys.rb +8 -4
- data/lib/vedeu/input/mapper.rb +125 -121
- data/lib/vedeu/input/translator.rb +159 -0
- data/lib/vedeu/internal_api.rb +16 -15
- data/lib/vedeu/logging/all.rb +13 -0
- data/lib/vedeu/logging/debug.rb +84 -0
- data/lib/vedeu/logging/lockless_log_device.rb +65 -0
- data/lib/vedeu/logging/log.rb +179 -0
- data/lib/vedeu/logging/mono_logger.rb +26 -0
- data/lib/vedeu/logging/timer.rb +68 -0
- data/lib/vedeu/menus/all.rb +12 -0
- data/lib/vedeu/{dsl/menu.rb → menus/dsl.rb} +19 -18
- data/lib/vedeu/menus/menu.rb +234 -0
- data/lib/vedeu/{null/menu.rb → menus/null.rb} +6 -6
- data/lib/vedeu/menus/repository.rb +18 -0
- data/lib/vedeu/models/cell.rb +62 -55
- data/lib/vedeu/models/escape.rb +55 -50
- data/lib/vedeu/models/page.rb +74 -69
- data/lib/vedeu/models/row.rb +55 -51
- data/lib/vedeu/models/views/all.rb +1 -0
- data/lib/vedeu/models/views/char.rb +1 -1
- data/lib/vedeu/models/views/html_char.rb +165 -0
- data/lib/vedeu/output/renderers/html.rb +5 -4
- data/lib/vedeu/repositories/model.rb +2 -0
- data/lib/vedeu/runtime/application.rb +110 -103
- data/lib/vedeu/runtime/bootstrap.rb +109 -103
- data/lib/vedeu/runtime/flags.rb +45 -41
- data/lib/vedeu/runtime/launcher.rb +1 -1
- data/lib/vedeu/runtime/main_loop.rb +51 -46
- data/lib/vedeu/runtime/traps.rb +20 -16
- data/lib/vedeu/version.rb +1 -1
- data/lib/vedeu.rb +2 -2
- data/test/lib/vedeu/buffers/virtual_buffer_test.rb +1 -1
- data/test/lib/vedeu/cursors/cursor_test.rb +11 -5
- data/test/lib/vedeu/dsl/interface_test.rb +1 -1
- data/test/lib/vedeu/dsl/keymap_test.rb +2 -2
- data/test/lib/vedeu/{input/editor → editor}/capture_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/cropper_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/cursor_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/document_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/documents_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/editor_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/insert_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/line_test.rb +0 -0
- data/test/lib/vedeu/{input/editor → editor}/lines_test.rb +0 -0
- data/test/lib/vedeu/input/input_test.rb +58 -54
- data/test/lib/vedeu/input/key_test.rb +29 -25
- data/test/lib/vedeu/input/keymap_test.rb +74 -70
- data/test/lib/vedeu/input/keymaps_test.rb +8 -4
- data/test/lib/vedeu/input/keys_test.rb +12 -8
- data/test/lib/vedeu/input/mapper_test.rb +64 -56
- data/test/lib/vedeu/input/translator_test.rb +36 -0
- data/test/lib/vedeu/logging/debug_test.rb +39 -0
- data/test/lib/vedeu/logging/lockless_log_device_test.rb +42 -0
- data/test/lib/vedeu/logging/log_test.rb +52 -0
- data/test/lib/vedeu/logging/mono_logger_test.rb +43 -0
- data/test/lib/vedeu/logging/timer_test.rb +44 -0
- data/test/lib/vedeu/{dsl/menu_test.rb → menus/dsl_test.rb} +6 -6
- data/test/lib/vedeu/menus/menu_test.rb +305 -0
- data/test/lib/vedeu/{null/menu_test.rb → menus/null_test.rb} +5 -5
- data/test/lib/vedeu/menus/repository_test.rb +17 -0
- data/test/lib/vedeu/models/cell_test.rb +54 -50
- data/test/lib/vedeu/models/escape_test.rb +49 -45
- data/test/lib/vedeu/models/page_test.rb +167 -160
- data/test/lib/vedeu/models/row_test.rb +71 -67
- data/test/lib/vedeu/models/views/html_char_test.rb +110 -0
- data/test/lib/vedeu/output/compressor_test.rb +44 -22
- data/test/lib/vedeu/output/renderers_test.rb +4 -2
- data/test/lib/vedeu/runtime/application_test.rb +36 -32
- data/test/lib/vedeu/runtime/bootstrap_test.rb +31 -26
- data/test/lib/vedeu/runtime/flags_test.rb +33 -29
- data/test/lib/vedeu/runtime/launcher_test.rb +4 -2
- data/test/lib/vedeu/runtime/main_loop_test.rb +28 -24
- data/test/lib/vedeu/runtime/traps_test.rb +8 -4
- data/test/test_helper.rb +4 -2
- metadata +66 -63
- data/lib/vedeu/input/editor/all.rb +0 -19
- data/lib/vedeu/input/input_translator.rb +0 -155
- data/lib/vedeu/log/debug.rb +0 -79
- data/lib/vedeu/log/lockless_log_device.rb +0 -61
- data/lib/vedeu/log/log.rb +0 -172
- data/lib/vedeu/log/mono_logger.rb +0 -21
- data/lib/vedeu/log/timer.rb +0 -63
- data/lib/vedeu/models/menu.rb +0 -217
- data/lib/vedeu/models/menus.rb +0 -14
- data/lib/vedeu/output/html_char.rb +0 -161
- data/test/lib/vedeu/input/input_translator_test.rb +0 -32
- data/test/lib/vedeu/log/debug_test.rb +0 -35
- data/test/lib/vedeu/log/lockless_log_device_test.rb +0 -29
- data/test/lib/vedeu/log/log_test.rb +0 -48
- data/test/lib/vedeu/log/mono_logger_test.rb +0 -31
- data/test/lib/vedeu/log/timer_test.rb +0 -40
- data/test/lib/vedeu/models/menu_test.rb +0 -301
- data/test/lib/vedeu/models/menus_test.rb +0 -13
- data/test/lib/vedeu/output/html_char_test.rb +0 -106
data/lib/vedeu/runtime/flags.rb
CHANGED
@@ -1,57 +1,61 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
|
4
|
-
#
|
5
|
-
class Flags
|
3
|
+
module Runtime
|
6
4
|
|
7
|
-
|
5
|
+
# Home of various runtime flags which Vedeu uses.
|
6
|
+
#
|
7
|
+
class Flags
|
8
8
|
|
9
|
-
|
9
|
+
include Singleton
|
10
10
|
|
11
|
-
|
12
|
-
def ready!
|
13
|
-
instance.options[:ready] = true
|
14
|
-
end
|
11
|
+
class << self
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
# @return [Boolean]
|
14
|
+
def ready!
|
15
|
+
instance.options[:ready] = true
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Boolean]
|
19
|
+
def ready?
|
20
|
+
instance.options[:ready]
|
21
|
+
end
|
22
|
+
|
23
|
+
# Reset the flags to the default values.
|
24
|
+
#
|
25
|
+
# @return [Hash]
|
26
|
+
def reset!
|
27
|
+
instance.reset!
|
28
|
+
end
|
29
|
+
|
30
|
+
end # Eigenclass
|
31
|
+
|
32
|
+
# @!attribute [rw]
|
33
|
+
# @return [Hash]
|
34
|
+
attr_accessor :options
|
20
35
|
|
21
|
-
#
|
36
|
+
# Create a new singleton instance of Vedeu::Runtime::Flags.
|
22
37
|
#
|
38
|
+
# @return [Vedeu::Runtime::Flags]
|
39
|
+
def initialize
|
40
|
+
self.options = defaults
|
41
|
+
end
|
42
|
+
|
23
43
|
# @return [Hash]
|
24
44
|
def reset!
|
25
|
-
|
45
|
+
self.options = defaults
|
26
46
|
end
|
27
47
|
|
28
|
-
|
48
|
+
private
|
29
49
|
|
30
|
-
|
31
|
-
|
32
|
-
|
50
|
+
# @return [Hash]
|
51
|
+
def defaults
|
52
|
+
{
|
53
|
+
ready: false,
|
54
|
+
}
|
55
|
+
end
|
33
56
|
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
def initialize
|
38
|
-
self.options = defaults
|
39
|
-
end
|
40
|
-
|
41
|
-
# @return [Hash]
|
42
|
-
def reset!
|
43
|
-
self.options = defaults
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
# @return [Hash]
|
49
|
-
def defaults
|
50
|
-
{
|
51
|
-
ready: false,
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
end # Flags
|
57
|
+
end # Flags
|
58
|
+
|
59
|
+
end # Runtime
|
56
60
|
|
57
61
|
end # Vedeu
|
@@ -1,55 +1,60 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module Runtime
|
4
|
+
|
5
|
+
# Provides the main loop for a Vedeu application.
|
6
|
+
#
|
7
|
+
class MainLoop
|
8
|
+
|
9
|
+
trap('SIGTERM') { stop! }
|
10
|
+
trap('TERM') { stop! }
|
11
|
+
trap('INT') { stop! }
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
# :nocov:
|
16
|
+
# Start the main loop.
|
17
|
+
#
|
18
|
+
# @return [void]
|
19
|
+
# @yieldreturn [void] The client application.
|
20
|
+
def start!
|
21
|
+
@started = true
|
22
|
+
@loop = true
|
23
|
+
|
24
|
+
while @loop
|
25
|
+
yield
|
26
|
+
|
27
|
+
safe_exit_point!
|
28
|
+
end
|
29
|
+
rescue Vedeu::Error::Interrupt
|
30
|
+
Vedeu.log(type: :info,
|
31
|
+
message: 'Vedeu execution interrupted, exiting.')
|
32
|
+
end
|
33
|
+
# :nocov:
|
6
34
|
|
7
|
-
|
8
|
-
|
9
|
-
|
35
|
+
# Signal that we wish to terminate the running application.
|
36
|
+
#
|
37
|
+
# @return [void]
|
38
|
+
def stop!
|
39
|
+
@loop = false
|
40
|
+
end
|
10
41
|
|
11
|
-
|
42
|
+
# :nocov:
|
43
|
+
# Check the application has started and we wish to continue
|
44
|
+
# running.
|
45
|
+
#
|
46
|
+
# @raise [Vedeu::Error::Interrupt] When we wish to terminate
|
47
|
+
# the running application.
|
48
|
+
# @return [void]
|
49
|
+
def safe_exit_point!
|
50
|
+
fail Vedeu::Error::Interrupt if @started && !@loop
|
51
|
+
end
|
52
|
+
# :nocov:
|
12
53
|
|
13
|
-
#
|
14
|
-
# Start the main loop.
|
15
|
-
#
|
16
|
-
# @return [void]
|
17
|
-
# @yieldreturn [void] The client application.
|
18
|
-
def start!
|
19
|
-
@started = true
|
20
|
-
@loop = true
|
54
|
+
end # Eigenclass
|
21
55
|
|
22
|
-
|
23
|
-
yield
|
56
|
+
end # MainLoop
|
24
57
|
|
25
|
-
|
26
|
-
end
|
27
|
-
rescue Vedeu::Error::Interrupt
|
28
|
-
Vedeu.log(type: :info,
|
29
|
-
message: 'Vedeu execution interrupted, exiting.')
|
30
|
-
end
|
31
|
-
# :nocov:
|
32
|
-
|
33
|
-
# Signal that we wish to terminate the running application.
|
34
|
-
#
|
35
|
-
# @return [void]
|
36
|
-
def stop!
|
37
|
-
@loop = false
|
38
|
-
end
|
39
|
-
|
40
|
-
# :nocov:
|
41
|
-
# Check the application has started and we wish to continue running.
|
42
|
-
#
|
43
|
-
# @raise [Vedeu::Error::Interrupt] When we wish to terminate the running
|
44
|
-
# application.
|
45
|
-
# @return [void]
|
46
|
-
def safe_exit_point!
|
47
|
-
fail Vedeu::Error::Interrupt if @started && !@loop
|
48
|
-
end
|
49
|
-
# :nocov:
|
50
|
-
|
51
|
-
end # Eigenclass
|
52
|
-
|
53
|
-
end # MainLoop
|
58
|
+
end # Runtime
|
54
59
|
|
55
60
|
end # Vedeu
|
data/lib/vedeu/runtime/traps.rb
CHANGED
@@ -1,25 +1,29 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
|
4
|
-
#
|
5
|
-
module Traps
|
3
|
+
module Runtime
|
6
4
|
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
end
|
5
|
+
# Vedeu can respond to various signals which are handled here.
|
6
|
+
#
|
7
|
+
module Traps
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
# :nocov:
|
10
|
+
Signal.trap('INT') do
|
11
|
+
exit(1)
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
Signal.trap('TERM') do
|
15
|
+
exit(1)
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
18
|
+
Signal.trap('TTIN') {}
|
19
|
+
Signal.trap('USR1') {}
|
20
|
+
Signal.trap('USR2') {}
|
22
21
|
|
23
|
-
|
22
|
+
Signal.trap('SIGWINCH') { Vedeu.trigger(:_resize_) }
|
23
|
+
# :nocov:
|
24
|
+
|
25
|
+
end # Traps
|
26
|
+
|
27
|
+
end # Runtime
|
24
28
|
|
25
29
|
end # Vedeu
|
data/lib/vedeu/version.rb
CHANGED
data/lib/vedeu.rb
CHANGED
@@ -21,7 +21,7 @@ require 'zlib'
|
|
21
21
|
|
22
22
|
require 'thor'
|
23
23
|
|
24
|
-
require 'vedeu/
|
24
|
+
require 'vedeu/logging/log'
|
25
25
|
|
26
26
|
# Vedeu is a GUI framework for terminal/console applications written in Ruby.
|
27
27
|
#
|
@@ -30,7 +30,7 @@ module Vedeu
|
|
30
30
|
extend Forwardable
|
31
31
|
extend self
|
32
32
|
|
33
|
-
def_delegators Vedeu::Log, :log
|
33
|
+
def_delegators Vedeu::Logging::Log, :log
|
34
34
|
|
35
35
|
# Return the name of currently focussed interface.
|
36
36
|
#
|
@@ -52,7 +52,9 @@ module Vedeu
|
|
52
52
|
it { subject.instance_variable_get('@name').must_equal('silver') }
|
53
53
|
it { subject.instance_variable_get('@ox').must_equal(ox) }
|
54
54
|
it { subject.instance_variable_get('@oy').must_equal(oy) }
|
55
|
-
it {
|
55
|
+
it {
|
56
|
+
subject.instance_variable_get('@repository').must_equal(repository)
|
57
|
+
}
|
56
58
|
it { subject.instance_variable_get('@visible').must_equal(true) }
|
57
59
|
it { subject.instance_variable_get('@x').must_equal(x) }
|
58
60
|
it { subject.instance_variable_get('@y').must_equal(y) }
|
@@ -72,7 +74,9 @@ module Vedeu
|
|
72
74
|
|
73
75
|
describe '#hide' do
|
74
76
|
let(:visible) { true }
|
75
|
-
let(:hide_cursor) {
|
77
|
+
let(:hide_cursor) {
|
78
|
+
Vedeu::Models::Escape.new(value: Vedeu::Esc.hide_cursor)
|
79
|
+
}
|
76
80
|
|
77
81
|
before do
|
78
82
|
Vedeu::Output.stubs(:render).
|
@@ -81,7 +85,7 @@ module Vedeu
|
|
81
85
|
|
82
86
|
subject { instance.hide }
|
83
87
|
|
84
|
-
it { subject.must_be_instance_of(Vedeu::Escape) }
|
88
|
+
it { subject.must_be_instance_of(Vedeu::Models::Escape) }
|
85
89
|
end
|
86
90
|
|
87
91
|
describe '#move_down' do
|
@@ -196,7 +200,9 @@ module Vedeu
|
|
196
200
|
|
197
201
|
describe '#show' do
|
198
202
|
let(:visible) { false }
|
199
|
-
let(:show_cursor) {
|
203
|
+
let(:show_cursor) {
|
204
|
+
Vedeu::Models::Escape.new(value: Vedeu::Esc.show_cursor)
|
205
|
+
}
|
200
206
|
|
201
207
|
before do
|
202
208
|
Vedeu::Output.stubs(:render).
|
@@ -205,7 +211,7 @@ module Vedeu
|
|
205
211
|
|
206
212
|
subject { instance.show }
|
207
213
|
|
208
|
-
it { subject.must_be_instance_of(Vedeu::Escape) }
|
214
|
+
it { subject.must_be_instance_of(Vedeu::Models::Escape) }
|
209
215
|
end
|
210
216
|
|
211
217
|
describe '#reposition' do
|
@@ -8,7 +8,7 @@ module Vedeu
|
|
8
8
|
|
9
9
|
let(:described) { Vedeu::DSL::Keymap }
|
10
10
|
let(:instance) { described.new(model) }
|
11
|
-
let(:model) { Vedeu::Keymap.new(name: '_test_') }
|
11
|
+
let(:model) { Vedeu::Input::Keymap.new(name: '_test_') }
|
12
12
|
|
13
13
|
describe '#initialize' do
|
14
14
|
it { instance.must_be_instance_of(described) }
|
@@ -47,7 +47,7 @@ module Vedeu
|
|
47
47
|
end
|
48
48
|
|
49
49
|
context 'when the key is valid (not already defined)' do
|
50
|
-
before { model.stubs(:add).returns(Vedeu::Keymap) }
|
50
|
+
before { model.stubs(:add).returns(Vedeu::Input::Keymap) }
|
51
51
|
|
52
52
|
it { subject.must_equal(['j', :down]) }
|
53
53
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -2,87 +2,91 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
let(:reader) { Vedeu::Terminal }
|
8
|
-
let(:keypress) { 'a' }
|
9
|
-
let(:described) { Vedeu::Input }
|
10
|
-
let(:instance) { described.new(reader) }
|
11
|
-
let(:raw_mode) { true }
|
12
|
-
|
13
|
-
describe '#initialize' do
|
14
|
-
it { instance.must_be_instance_of(described) }
|
15
|
-
it { instance.instance_variable_get('@reader').must_equal(reader) }
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '.capture' do
|
19
|
-
before do
|
20
|
-
reader.stubs(:raw_mode?).returns(raw_mode)
|
21
|
-
reader.stubs(:fake_mode?).returns(fake_mode)
|
22
|
-
Vedeu.stubs(:trigger).returns([false])
|
23
|
-
end
|
5
|
+
module Input
|
24
6
|
|
25
|
-
|
7
|
+
describe Input do
|
26
8
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
9
|
+
let(:reader) { Vedeu::Terminal }
|
10
|
+
let(:keypress) { 'a' }
|
11
|
+
let(:described) { Vedeu::Input::Input }
|
12
|
+
let(:instance) { described.new(reader) }
|
13
|
+
let(:raw_mode) { true }
|
31
14
|
|
32
|
-
|
15
|
+
describe '#initialize' do
|
16
|
+
it { instance.must_be_instance_of(described) }
|
17
|
+
it { instance.instance_variable_get('@reader').must_equal(reader) }
|
18
|
+
end
|
33
19
|
|
34
|
-
|
35
|
-
|
36
|
-
|
20
|
+
describe '.capture' do
|
21
|
+
before do
|
22
|
+
reader.stubs(:raw_mode?).returns(raw_mode)
|
23
|
+
reader.stubs(:fake_mode?).returns(fake_mode)
|
24
|
+
Vedeu.stubs(:trigger).returns([false])
|
37
25
|
end
|
38
|
-
end
|
39
26
|
|
40
|
-
|
41
|
-
let(:raw_mode) { false }
|
42
|
-
let(:fake_mode) { true }
|
43
|
-
let(:keypress) { 'b' }
|
27
|
+
subject { described.capture(reader) }
|
44
28
|
|
45
|
-
|
29
|
+
context 'when in cooked mode' do
|
30
|
+
let(:raw_mode) { false }
|
31
|
+
let(:fake_mode) { false }
|
32
|
+
let(:command) { 'help' }
|
46
33
|
|
47
|
-
|
48
|
-
|
49
|
-
|
34
|
+
before { reader.stubs(:read).returns(command) }
|
35
|
+
|
36
|
+
it 'triggers an event with the command' do
|
37
|
+
Vedeu.expects(:trigger).with(:_command_, command)
|
38
|
+
subject
|
39
|
+
end
|
50
40
|
end
|
51
|
-
end
|
52
41
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
42
|
+
context 'when in fake mode' do
|
43
|
+
let(:raw_mode) { false }
|
44
|
+
let(:fake_mode) { true }
|
45
|
+
let(:keypress) { 'b' }
|
57
46
|
|
58
|
-
|
47
|
+
before { reader.stubs(:read).returns(keypress) }
|
59
48
|
|
60
|
-
context 'when the key is not special' do
|
61
49
|
it 'triggers an event with the keypress' do
|
62
|
-
Vedeu.expects(:trigger).with(:
|
50
|
+
Vedeu.expects(:trigger).with(:_editor_, keypress)
|
63
51
|
subject
|
64
52
|
end
|
65
53
|
end
|
66
54
|
|
67
|
-
context 'when
|
68
|
-
let(:
|
55
|
+
context 'when in raw mode' do
|
56
|
+
let(:raw_mode) { true }
|
57
|
+
let(:fake_mode) { false }
|
58
|
+
let(:keypress) { 'a' }
|
69
59
|
|
70
|
-
|
71
|
-
|
72
|
-
|
60
|
+
before { reader.stubs(:read).returns(keypress) }
|
61
|
+
|
62
|
+
context 'when the key is not special' do
|
63
|
+
it 'triggers an event with the keypress' do
|
64
|
+
Vedeu.expects(:trigger).with(:_keypress_, keypress)
|
65
|
+
subject
|
66
|
+
end
|
73
67
|
end
|
74
68
|
|
75
|
-
context 'when the key is
|
76
|
-
let(:keypress) { "\e[
|
69
|
+
context 'when the key is special' do
|
70
|
+
let(:keypress) { "\e[A" }
|
77
71
|
|
78
72
|
it 'triggers an event with the keypress' do
|
79
|
-
Vedeu.expects(:trigger).with(:_keypress_, :
|
73
|
+
Vedeu.expects(:trigger).with(:_keypress_, :up)
|
80
74
|
subject
|
81
75
|
end
|
76
|
+
|
77
|
+
context 'when the key is an F key' do
|
78
|
+
let(:keypress) { "\e[17~" }
|
79
|
+
|
80
|
+
it 'triggers an event with the keypress' do
|
81
|
+
Vedeu.expects(:trigger).with(:_keypress_, :f6)
|
82
|
+
subject
|
83
|
+
end
|
84
|
+
end
|
82
85
|
end
|
83
86
|
end
|
84
87
|
end
|
85
|
-
|
88
|
+
|
89
|
+
end # Input
|
86
90
|
|
87
91
|
end # Input
|
88
92
|
|
@@ -2,44 +2,48 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
|
5
|
+
module Input
|
6
6
|
|
7
|
-
|
8
|
-
let(:instance) { described.new(input) { :output } }
|
9
|
-
let(:input) { 'a' }
|
7
|
+
describe Key do
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
let(:described) { Vedeu::Input::Key }
|
10
|
+
let(:instance) { described.new(input) { :output } }
|
11
|
+
let(:input) { 'a' }
|
14
12
|
|
15
|
-
|
16
|
-
|
13
|
+
describe '#initialize' do
|
14
|
+
it { instance.must_be_instance_of(described) }
|
15
|
+
it { instance.instance_variable_get('@input').must_equal(input) }
|
17
16
|
|
18
|
-
|
17
|
+
context 'when the required block is not given' do
|
18
|
+
subject { described.new(input) }
|
19
|
+
|
20
|
+
it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
|
21
|
+
end
|
19
22
|
end
|
20
|
-
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
describe '#input' do
|
25
|
+
subject { instance.input }
|
26
|
+
|
27
|
+
it 'returns the key defined' do
|
28
|
+
subject.must_equal('a')
|
29
|
+
end
|
24
30
|
|
25
|
-
|
26
|
-
subject.must_equal('a')
|
31
|
+
it { instance.must_respond_to(:key) }
|
27
32
|
end
|
28
33
|
|
29
|
-
|
30
|
-
|
34
|
+
describe '#output' do
|
35
|
+
subject { instance.output }
|
31
36
|
|
32
|
-
|
33
|
-
|
37
|
+
it 'returns the result of calling the proc' do
|
38
|
+
subject.must_equal(:output)
|
39
|
+
end
|
34
40
|
|
35
|
-
|
36
|
-
|
41
|
+
it { instance.must_respond_to(:action) }
|
42
|
+
it { instance.must_respond_to(:press) }
|
37
43
|
end
|
38
44
|
|
39
|
-
|
40
|
-
it { instance.must_respond_to(:press) }
|
41
|
-
end
|
45
|
+
end # Key
|
42
46
|
|
43
|
-
end #
|
47
|
+
end # Input
|
44
48
|
|
45
49
|
end # Vedeu
|