vedeu 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/docs/dsl.md +4 -4
  4. data/lib/vedeu/all.rb +6 -18
  5. data/lib/vedeu/api.rb +14 -13
  6. data/lib/vedeu/bindings/system.rb +5 -4
  7. data/lib/vedeu/buffers/virtual_buffer.rb +13 -11
  8. data/lib/vedeu/configuration/api.rb +4 -3
  9. data/lib/vedeu/cursors/cursor.rb +23 -18
  10. data/lib/vedeu/distributed/client.rb +11 -6
  11. data/lib/vedeu/distributed/server.rb +4 -3
  12. data/lib/vedeu/dsl/keymap.rb +6 -6
  13. data/lib/vedeu/editor/all.rb +19 -0
  14. data/lib/vedeu/{input/editor → editor}/capture.rb +1 -1
  15. data/lib/vedeu/{input/editor → editor}/cropper.rb +0 -0
  16. data/lib/vedeu/{input/editor → editor}/cursor.rb +0 -0
  17. data/lib/vedeu/{input/editor → editor}/document.rb +0 -0
  18. data/lib/vedeu/{input/editor → editor}/documents.rb +0 -0
  19. data/lib/vedeu/{input/editor → editor}/editor.rb +0 -0
  20. data/lib/vedeu/{input/editor → editor}/insert.rb +0 -0
  21. data/lib/vedeu/{input/editor → editor}/line.rb +0 -0
  22. data/lib/vedeu/{input/editor → editor}/lines.rb +0 -0
  23. data/lib/vedeu/error.rb +21 -18
  24. data/lib/vedeu/esc/borders.rb +6 -4
  25. data/lib/vedeu/esc/colours.rb +13 -12
  26. data/lib/vedeu/esc/esc.rb +11 -10
  27. data/lib/vedeu/input/all.rb +15 -0
  28. data/lib/vedeu/input/input.rb +55 -52
  29. data/lib/vedeu/input/key.rb +36 -30
  30. data/lib/vedeu/input/keymap.rb +101 -92
  31. data/lib/vedeu/input/keymaps.rb +10 -6
  32. data/lib/vedeu/input/keys.rb +8 -4
  33. data/lib/vedeu/input/mapper.rb +125 -121
  34. data/lib/vedeu/input/translator.rb +159 -0
  35. data/lib/vedeu/internal_api.rb +16 -15
  36. data/lib/vedeu/logging/all.rb +13 -0
  37. data/lib/vedeu/logging/debug.rb +84 -0
  38. data/lib/vedeu/logging/lockless_log_device.rb +65 -0
  39. data/lib/vedeu/logging/log.rb +179 -0
  40. data/lib/vedeu/logging/mono_logger.rb +26 -0
  41. data/lib/vedeu/logging/timer.rb +68 -0
  42. data/lib/vedeu/menus/all.rb +12 -0
  43. data/lib/vedeu/{dsl/menu.rb → menus/dsl.rb} +19 -18
  44. data/lib/vedeu/menus/menu.rb +234 -0
  45. data/lib/vedeu/{null/menu.rb → menus/null.rb} +6 -6
  46. data/lib/vedeu/menus/repository.rb +18 -0
  47. data/lib/vedeu/models/cell.rb +62 -55
  48. data/lib/vedeu/models/escape.rb +55 -50
  49. data/lib/vedeu/models/page.rb +74 -69
  50. data/lib/vedeu/models/row.rb +55 -51
  51. data/lib/vedeu/models/views/all.rb +1 -0
  52. data/lib/vedeu/models/views/char.rb +1 -1
  53. data/lib/vedeu/models/views/html_char.rb +165 -0
  54. data/lib/vedeu/output/renderers/html.rb +5 -4
  55. data/lib/vedeu/repositories/model.rb +2 -0
  56. data/lib/vedeu/runtime/application.rb +110 -103
  57. data/lib/vedeu/runtime/bootstrap.rb +109 -103
  58. data/lib/vedeu/runtime/flags.rb +45 -41
  59. data/lib/vedeu/runtime/launcher.rb +1 -1
  60. data/lib/vedeu/runtime/main_loop.rb +51 -46
  61. data/lib/vedeu/runtime/traps.rb +20 -16
  62. data/lib/vedeu/version.rb +1 -1
  63. data/lib/vedeu.rb +2 -2
  64. data/test/lib/vedeu/buffers/virtual_buffer_test.rb +1 -1
  65. data/test/lib/vedeu/cursors/cursor_test.rb +11 -5
  66. data/test/lib/vedeu/dsl/interface_test.rb +1 -1
  67. data/test/lib/vedeu/dsl/keymap_test.rb +2 -2
  68. data/test/lib/vedeu/{input/editor → editor}/capture_test.rb +0 -0
  69. data/test/lib/vedeu/{input/editor → editor}/cropper_test.rb +0 -0
  70. data/test/lib/vedeu/{input/editor → editor}/cursor_test.rb +0 -0
  71. data/test/lib/vedeu/{input/editor → editor}/document_test.rb +0 -0
  72. data/test/lib/vedeu/{input/editor → editor}/documents_test.rb +0 -0
  73. data/test/lib/vedeu/{input/editor → editor}/editor_test.rb +0 -0
  74. data/test/lib/vedeu/{input/editor → editor}/insert_test.rb +0 -0
  75. data/test/lib/vedeu/{input/editor → editor}/line_test.rb +0 -0
  76. data/test/lib/vedeu/{input/editor → editor}/lines_test.rb +0 -0
  77. data/test/lib/vedeu/input/input_test.rb +58 -54
  78. data/test/lib/vedeu/input/key_test.rb +29 -25
  79. data/test/lib/vedeu/input/keymap_test.rb +74 -70
  80. data/test/lib/vedeu/input/keymaps_test.rb +8 -4
  81. data/test/lib/vedeu/input/keys_test.rb +12 -8
  82. data/test/lib/vedeu/input/mapper_test.rb +64 -56
  83. data/test/lib/vedeu/input/translator_test.rb +36 -0
  84. data/test/lib/vedeu/logging/debug_test.rb +39 -0
  85. data/test/lib/vedeu/logging/lockless_log_device_test.rb +42 -0
  86. data/test/lib/vedeu/logging/log_test.rb +52 -0
  87. data/test/lib/vedeu/logging/mono_logger_test.rb +43 -0
  88. data/test/lib/vedeu/logging/timer_test.rb +44 -0
  89. data/test/lib/vedeu/{dsl/menu_test.rb → menus/dsl_test.rb} +6 -6
  90. data/test/lib/vedeu/menus/menu_test.rb +305 -0
  91. data/test/lib/vedeu/{null/menu_test.rb → menus/null_test.rb} +5 -5
  92. data/test/lib/vedeu/menus/repository_test.rb +17 -0
  93. data/test/lib/vedeu/models/cell_test.rb +54 -50
  94. data/test/lib/vedeu/models/escape_test.rb +49 -45
  95. data/test/lib/vedeu/models/page_test.rb +167 -160
  96. data/test/lib/vedeu/models/row_test.rb +71 -67
  97. data/test/lib/vedeu/models/views/html_char_test.rb +110 -0
  98. data/test/lib/vedeu/output/compressor_test.rb +44 -22
  99. data/test/lib/vedeu/output/renderers_test.rb +4 -2
  100. data/test/lib/vedeu/runtime/application_test.rb +36 -32
  101. data/test/lib/vedeu/runtime/bootstrap_test.rb +31 -26
  102. data/test/lib/vedeu/runtime/flags_test.rb +33 -29
  103. data/test/lib/vedeu/runtime/launcher_test.rb +4 -2
  104. data/test/lib/vedeu/runtime/main_loop_test.rb +28 -24
  105. data/test/lib/vedeu/runtime/traps_test.rb +8 -4
  106. data/test/test_helper.rb +4 -2
  107. metadata +66 -63
  108. data/lib/vedeu/input/editor/all.rb +0 -19
  109. data/lib/vedeu/input/input_translator.rb +0 -155
  110. data/lib/vedeu/log/debug.rb +0 -79
  111. data/lib/vedeu/log/lockless_log_device.rb +0 -61
  112. data/lib/vedeu/log/log.rb +0 -172
  113. data/lib/vedeu/log/mono_logger.rb +0 -21
  114. data/lib/vedeu/log/timer.rb +0 -63
  115. data/lib/vedeu/models/menu.rb +0 -217
  116. data/lib/vedeu/models/menus.rb +0 -14
  117. data/lib/vedeu/output/html_char.rb +0 -161
  118. data/test/lib/vedeu/input/input_translator_test.rb +0 -32
  119. data/test/lib/vedeu/log/debug_test.rb +0 -35
  120. data/test/lib/vedeu/log/lockless_log_device_test.rb +0 -29
  121. data/test/lib/vedeu/log/log_test.rb +0 -48
  122. data/test/lib/vedeu/log/mono_logger_test.rb +0 -31
  123. data/test/lib/vedeu/log/timer_test.rb +0 -40
  124. data/test/lib/vedeu/models/menu_test.rb +0 -301
  125. data/test/lib/vedeu/models/menus_test.rb +0 -13
  126. data/test/lib/vedeu/output/html_char_test.rb +0 -106
@@ -1,57 +1,61 @@
1
1
  module Vedeu
2
2
 
3
- # Home of various runtime flags which Vedeu uses.
4
- #
5
- class Flags
3
+ module Runtime
6
4
 
7
- include Singleton
5
+ # Home of various runtime flags which Vedeu uses.
6
+ #
7
+ class Flags
8
8
 
9
- class << self
9
+ include Singleton
10
10
 
11
- # @return [Boolean]
12
- def ready!
13
- instance.options[:ready] = true
14
- end
11
+ class << self
15
12
 
16
- # @return [Boolean]
17
- def ready?
18
- instance.options[:ready]
19
- end
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
- # Reset the flags to the default values.
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
- instance.reset!
45
+ self.options = defaults
26
46
  end
27
47
 
28
- end # Eigenclass
48
+ private
29
49
 
30
- # @!attribute [rw]
31
- # @return [Hash]
32
- attr_accessor :options
50
+ # @return [Hash]
51
+ def defaults
52
+ {
53
+ ready: false,
54
+ }
55
+ end
33
56
 
34
- # Create a new singleton instance of Vedeu::Flags.
35
- #
36
- # @return [Vedeu::Flags]
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
@@ -73,7 +73,7 @@ module Vedeu
73
73
  $stdout = @stdout
74
74
  $stderr = @stderr
75
75
 
76
- Vedeu::Application.start(configuration)
76
+ Vedeu::Runtime::Application.start(configuration)
77
77
 
78
78
  @exit_code = 0
79
79
 
@@ -1,55 +1,60 @@
1
1
  module Vedeu
2
2
 
3
- # Provides the main loop for a Vedeu application.
4
- #
5
- class MainLoop
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
- trap('SIGTERM') { stop! }
8
- trap('TERM') { stop! }
9
- trap('INT') { stop! }
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
- class << self
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
- # :nocov:
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
- while @loop
23
- yield
56
+ end # MainLoop
24
57
 
25
- safe_exit_point!
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
@@ -1,25 +1,29 @@
1
1
  module Vedeu
2
2
 
3
- # Vedeu can respond to various signals which are handled here.
4
- #
5
- module Traps
3
+ module Runtime
6
4
 
7
- # :nocov:
8
- Signal.trap('INT') do
9
- exit(1)
10
- end
5
+ # Vedeu can respond to various signals which are handled here.
6
+ #
7
+ module Traps
11
8
 
12
- Signal.trap('TERM') do
13
- exit(1)
14
- end
9
+ # :nocov:
10
+ Signal.trap('INT') do
11
+ exit(1)
12
+ end
15
13
 
16
- Signal.trap('TTIN') {}
17
- Signal.trap('USR1') {}
18
- Signal.trap('USR2') {}
14
+ Signal.trap('TERM') do
15
+ exit(1)
16
+ end
19
17
 
20
- Signal.trap('SIGWINCH') { Vedeu.trigger(:_resize_) }
21
- # :nocov:
18
+ Signal.trap('TTIN') {}
19
+ Signal.trap('USR1') {}
20
+ Signal.trap('USR2') {}
22
21
 
23
- end # Traps
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
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.6.7'
4
+ VERSION = '0.6.8'
5
5
 
6
6
  end
data/lib/vedeu.rb CHANGED
@@ -21,7 +21,7 @@ require 'zlib'
21
21
 
22
22
  require 'thor'
23
23
 
24
- require 'vedeu/log/log'
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
  #
@@ -78,7 +78,7 @@ module Vedeu
78
78
  let(:y) { 0 }
79
79
  let(:x) { 2 }
80
80
 
81
- it { subject.must_be_instance_of(Vedeu::Cell) }
81
+ it { subject.must_be_instance_of(Vedeu::Models::Cell) }
82
82
  end
83
83
  end
84
84
 
@@ -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 { subject.instance_variable_get('@repository').must_equal(repository) }
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) { Vedeu::Escape.new(value: Vedeu::Esc.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) { Vedeu::Escape.new(value: Vedeu::Esc.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
@@ -249,7 +249,7 @@ module Vedeu
249
249
  end
250
250
  }
251
251
 
252
- it { subject.must_be_instance_of(Vedeu::Keymap) }
252
+ it { subject.must_be_instance_of(Vedeu::Input::Keymap) }
253
253
  it { instance.must_respond_to(:keys) }
254
254
  end
255
255
 
@@ -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
@@ -2,87 +2,91 @@ require 'test_helper'
2
2
 
3
3
  module Vedeu
4
4
 
5
- describe Input do
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
- subject { described.capture(reader) }
7
+ describe Input do
26
8
 
27
- context 'when in cooked mode' do
28
- let(:raw_mode) { false }
29
- let(:fake_mode) { false }
30
- let(:command) { 'help' }
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
- before { reader.stubs(:read).returns(command) }
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
- it 'triggers an event with the command' do
35
- Vedeu.expects(:trigger).with(:_command_, command)
36
- subject
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
- context 'when in fake mode' do
41
- let(:raw_mode) { false }
42
- let(:fake_mode) { true }
43
- let(:keypress) { 'b' }
27
+ subject { described.capture(reader) }
44
28
 
45
- before { reader.stubs(:read).returns(keypress) }
29
+ context 'when in cooked mode' do
30
+ let(:raw_mode) { false }
31
+ let(:fake_mode) { false }
32
+ let(:command) { 'help' }
46
33
 
47
- it 'triggers an event with the keypress' do
48
- Vedeu.expects(:trigger).with(:_editor_, keypress)
49
- subject
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
- context 'when in raw mode' do
54
- let(:raw_mode) { true }
55
- let(:fake_mode) { false }
56
- let(:keypress) { 'a' }
42
+ context 'when in fake mode' do
43
+ let(:raw_mode) { false }
44
+ let(:fake_mode) { true }
45
+ let(:keypress) { 'b' }
57
46
 
58
- before { reader.stubs(:read).returns(keypress) }
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(:_keypress_, keypress)
50
+ Vedeu.expects(:trigger).with(:_editor_, keypress)
63
51
  subject
64
52
  end
65
53
  end
66
54
 
67
- context 'when the key is special' do
68
- let(:keypress) { "\e[A" }
55
+ context 'when in raw mode' do
56
+ let(:raw_mode) { true }
57
+ let(:fake_mode) { false }
58
+ let(:keypress) { 'a' }
69
59
 
70
- it 'triggers an event with the keypress' do
71
- Vedeu.expects(:trigger).with(:_keypress_, :up)
72
- subject
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 an F key' do
76
- let(:keypress) { "\e[17~" }
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_, :f6)
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
- end
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
- describe Key do
5
+ module Input
6
6
 
7
- let(:described) { Vedeu::Key }
8
- let(:instance) { described.new(input) { :output } }
9
- let(:input) { 'a' }
7
+ describe Key do
10
8
 
11
- describe '#initialize' do
12
- it { instance.must_be_instance_of(described) }
13
- it { instance.instance_variable_get('@input').must_equal(input) }
9
+ let(:described) { Vedeu::Input::Key }
10
+ let(:instance) { described.new(input) { :output } }
11
+ let(:input) { 'a' }
14
12
 
15
- context 'when the required block is not given' do
16
- subject { described.new(input) }
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
- it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
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
- describe '#input' do
23
- subject { instance.input }
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
- it 'returns the key defined' do
26
- subject.must_equal('a')
31
+ it { instance.must_respond_to(:key) }
27
32
  end
28
33
 
29
- it { instance.must_respond_to(:key) }
30
- end
34
+ describe '#output' do
35
+ subject { instance.output }
31
36
 
32
- describe '#output' do
33
- subject { instance.output }
37
+ it 'returns the result of calling the proc' do
38
+ subject.must_equal(:output)
39
+ end
34
40
 
35
- it 'returns the result of calling the proc' do
36
- subject.must_equal(:output)
41
+ it { instance.must_respond_to(:action) }
42
+ it { instance.must_respond_to(:press) }
37
43
  end
38
44
 
39
- it { instance.must_respond_to(:action) }
40
- it { instance.must_respond_to(:press) }
41
- end
45
+ end # Key
42
46
 
43
- end # Key
47
+ end # Input
44
48
 
45
49
  end # Vedeu