vedeu 0.6.59 → 0.6.60

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5813addb77c651976f42073bc53aab1b4af606a
4
- data.tar.gz: 3cb787a6bb92c95ef9a883eced3c6452afdccf8b
3
+ metadata.gz: 686a2b4fb8270f973081dc3c7d108cdb49e6449a
4
+ data.tar.gz: 4ad07b62d0523da5bcfa758b53d1602b12396bc5
5
5
  SHA512:
6
- metadata.gz: b55242a13ddc309b76455ccb9938abf0f2c517f448b82a43f885cede2e82616c2b6c9419f80f48b7283f4fcda220cc3d5eb1b31b74e719ebb751d1d9f7ed4849
7
- data.tar.gz: e8005cd4ff555b0a51cfbbba53401cf2040291382c6b87f7687c1553c97a9c24f6eb6f308c2d4df106c5e2a5b728b7c36e93599bdc61eb3cded59be34e77dfc2
6
+ metadata.gz: 019242a5c896bf72c9e396f389ec4e185b461d9839087ae68f208a17c62307137aece08f65174ba3d4aa68f4d90233b327138dcaec1de35f858fa916ac58f43c
7
+ data.tar.gz: f1489ca293258577eef48e095e8cea55cc22502d14c0a2df0f3fd281b0b200348cb6dd9486a92a845c68638d766514a7771d01dc63d1a6e4fe0b15c3abfa2ef0
@@ -37,6 +37,5 @@ require 'vedeu/borders/title'
37
37
  require 'vedeu/borders/caption'
38
38
  require 'vedeu/borders/border'
39
39
  require 'vedeu/borders/dsl'
40
- require 'vedeu/borders/null'
41
40
  require 'vedeu/borders/refresh'
42
41
  require 'vedeu/borders/repository'
@@ -9,7 +9,7 @@ module Vedeu
9
9
 
10
10
  singleton_class.send(:alias_method, :borders, :repository)
11
11
 
12
- null Vedeu::Borders::Null
12
+ null Vedeu::Borders::Border, enabled: false
13
13
  real Vedeu::Borders::Border
14
14
 
15
15
  end # Repository
@@ -8,7 +8,6 @@ module Vedeu
8
8
 
9
9
  end # Vedeu
10
10
 
11
- require 'vedeu/editor/capture'
12
11
  require 'vedeu/editor/cropper'
13
12
  require 'vedeu/editor/delete'
14
13
  require 'vedeu/editor/editor'
@@ -2,27 +2,31 @@ module Vedeu
2
2
 
3
3
  module Input
4
4
 
5
- # Captures input from the user via {Vedeu::Terminal#input} and
5
+ # Captures input from the user terminal via 'getch' and
6
6
  # translates special characters into symbols.
7
7
  #
8
8
  class Capture
9
9
 
10
+ ESCAPE_KEY_CODE = 27 # \e
11
+
12
+ extend Forwardable
13
+
14
+ def_delegators Vedeu::Terminal::Mode,
15
+ :cooked_mode?,
16
+ :fake_mode?,
17
+ :raw_mode?
18
+
10
19
  # Instantiate Vedeu::Input::Input and capture keypress(es).
11
20
  #
12
- # @param (see #initialize)
13
21
  # @return (see #read)
14
- def self.read(reader)
15
- new(reader).read
22
+ def self.read
23
+ new.read
16
24
  end
17
25
 
18
26
  # Returns a new instance of Vedeu::Input::Input.
19
27
  #
20
- # @param reader [IO] An object that responds to `#read`.
21
- # Typically, this is Vedeu::Terminal.
22
28
  # @return [Vedeu::Input::Input]
23
- def initialize(reader)
24
- @reader = reader
25
- end
29
+ def initialize; end
26
30
 
27
31
  # Triggers various events dependent on the terminal mode.
28
32
  #
@@ -42,68 +46,97 @@ module Vedeu
42
46
  #
43
47
  # @return [Array|String|Symbol]
44
48
  def read
45
- if click?(keypress)
46
- Vedeu.trigger(:_mouse_event_, keypress)
49
+ Vedeu.log(type: :input, message: 'Waiting for user input...'.freeze)
47
50
 
48
- elsif reader.raw_mode?
51
+ if raw_mode?
49
52
  Vedeu.trigger(:_keypress_, keypress)
50
53
 
51
- elsif reader.fake_mode?
52
- name = Vedeu.focus
53
- interface = Vedeu.interfaces.by_name(name)
54
- key = keypress
54
+ elsif fake_mode?
55
+ @key ||= keypress
56
+
57
+ if click?(@key)
58
+ Vedeu.trigger(:_mouse_event_, @key)
55
59
 
56
- if Vedeu::Input::Mapper.registered?(key, name)
57
- Vedeu.trigger(:_keypress_, key, name)
60
+ elsif Vedeu::Input::Mapper.registered?(@key, name)
61
+ Vedeu.trigger(:_keypress_, @key, name)
58
62
 
59
63
  elsif interface.editable?
60
- Vedeu.trigger(:_editor_, key)
64
+ Vedeu.trigger(:_editor_, @key)
65
+
66
+ elsif @key.nil?
67
+ nil
61
68
 
62
69
  else
63
- Vedeu.trigger(:key, key)
70
+ Vedeu.trigger(:key, @key)
64
71
 
65
72
  end
66
- else
73
+
74
+ elsif cooked_mode?
67
75
  Vedeu.trigger(:_command_, command)
68
76
 
69
77
  end
70
78
  end
71
79
 
72
- protected
80
+ private
73
81
 
74
- # @!attribute [r] reader
75
- # @return [IO]
76
- attr_reader :reader
82
+ # Returns the translated (when possible) keypress(es).
83
+ #
84
+ # @return [String|Symbol]
85
+ def keypress
86
+ Vedeu::Input::Translator.translate(input)
87
+ end
77
88
 
78
- private
89
+ # Takes input from the user via the keyboard. Accepts special
90
+ # keys like the F-Keys etc, by capturing the entire sequence.
91
+ #
92
+ # @return [String]
93
+ def input
94
+ keys = console.getch
95
+
96
+ if keys.ord == ESCAPE_KEY_CODE
97
+ keys << console.read_nonblock(4) rescue nil
98
+ keys << console.read_nonblock(3) rescue nil
99
+ keys << console.read_nonblock(2) rescue nil
100
+ end
101
+
102
+ return Vedeu::Input::Mouse.click(keys) if click?(keys)
103
+
104
+ keys
105
+ end
79
106
 
80
107
  # Returns a boolean indicating whether a mouse click was
81
108
  # received.
82
109
  #
83
- # @param key [String]
110
+ # @param key [NilClass|String|Symbol|Vedeu::Cursors::Cursor]
84
111
  # @return [Boolean]
85
- def click?(key)
86
- return false if key.is_a?(Symbol)
112
+ def click?(input)
113
+ return false if input.nil? || input.is_a?(Symbol)
87
114
 
88
- key.is_a?(Vedeu::Cursors::Cursor) || key.start_with?("\e[M")
115
+ input.is_a?(Vedeu::Cursors::Cursor) || input.start_with?("\e[M")
89
116
  end
90
117
 
91
- # Returns the translated (when possible) keypress(es).
92
- #
93
- # @return [String|Symbol]
94
- def keypress
95
- key = input
96
-
97
- @keypress ||= Vedeu::Input::Translator.translate(key)
118
+ # @return [IO]
119
+ def console
120
+ @console ||= Vedeu::Terminal.console
98
121
  end
99
122
 
100
- # Returns the input from the terminal.
123
+ # Takes input from the user via the keyboard. Accepts special
124
+ # keys like the F-Keys etc, by capturing the entire sequence.
101
125
  #
102
126
  # @return [String]
103
- def input
104
- @input ||= reader.read
127
+ def command
128
+ console.gets.chomp
129
+ end
130
+
131
+ # @return [String|Symbol]
132
+ def name
133
+ Vedeu.focus
134
+ end
135
+
136
+ # @return [Vedeu::Interfaces::Interface]
137
+ def interface
138
+ Vedeu.interfaces.by_name(name)
105
139
  end
106
- alias_method :command, :input
107
140
 
108
141
  end # Input
109
142
 
@@ -29,6 +29,8 @@ module Vedeu
29
29
  Vedeu.log(type: :input,
30
30
  message: "Mouse pressed: '#{button}' (x: #{x}, y: #{y})")
31
31
 
32
+ Vedeu.trigger(:_mouse_event_, input)
33
+
32
34
  if left_click?
33
35
  Vedeu.trigger(:_cursor_reposition_, Vedeu.focus, y, x)
34
36
 
@@ -62,8 +62,10 @@ module Vedeu
62
62
  #
63
63
  # @param name [String|Symbol] The name of the stored model.
64
64
  # @return [void]
65
- def by_name(name = Vedeu.focus)
66
- return find(name) if present?(name) && registered?(name)
65
+ def by_name(name = nil)
66
+ name = present?(name) ? name : Vedeu.focus
67
+
68
+ return find(name) if registered?(name)
67
69
 
68
70
  attrs = if null_attributes.any?
69
71
  null_attributes.merge!(name: name)
@@ -102,7 +102,7 @@ module Vedeu
102
102
  # @return [void]
103
103
  def main_sequence
104
104
  if configuration.interactive?
105
- Vedeu::Input::Capture.read(Terminal)
105
+ Vedeu::Input::Capture.read
106
106
 
107
107
  else
108
108
  Vedeu.trigger(:_standalone_)
@@ -29,23 +29,6 @@ module Vedeu
29
29
  restore_screen
30
30
  end
31
31
 
32
- # Takes input from the user via the keyboard. Accepts special keys
33
- # like the F-Keys etc, by capturing the entire sequence.
34
- #
35
- # @return [String]
36
- def input
37
- Vedeu.log(type: :input, message: 'Waiting for user input...'.freeze)
38
-
39
- if raw_mode? || fake_mode?
40
- Vedeu::Editor::Capture.read(console)
41
-
42
- else
43
- console.gets.chomp
44
-
45
- end
46
- end
47
- alias_method :read, :input
48
-
49
32
  # Prints the streams to the screen and returns the streams.
50
33
  #
51
34
  # @param streams [String|Array]
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.59'.freeze
4
+ VERSION = '0.6.60'.freeze
5
5
 
6
6
  end
@@ -49,7 +49,7 @@ module Vedeu
49
49
  context 'when no interfaces/views have been registered' do
50
50
  before { Vedeu::Models::Focus.reset }
51
51
 
52
- it { proc { subject }.must_raise(Vedeu::Error::MissingRequired) }
52
+ it { proc { subject }.must_raise(Vedeu::Error::Fatal) }
53
53
  end
54
54
  end
55
55
 
@@ -6,132 +6,251 @@ module Vedeu
6
6
 
7
7
  describe Capture do
8
8
 
9
- let(:reader) { Vedeu::Terminal }
10
- let(:keypress) { 'a' }
11
9
  let(:described) { Vedeu::Input::Capture }
12
- let(:instance) { described.new(reader) }
13
- let(:raw_mode) { true }
10
+ let(:instance) { described.new }
14
11
 
15
12
  describe '#initialize' do
16
13
  it { instance.must_be_instance_of(described) }
17
- it { instance.instance_variable_get('@reader').must_equal(reader) }
14
+ end
15
+
16
+ describe '#read' do
17
+ it { instance.must_respond_to(:read) }
18
18
  end
19
19
 
20
20
  describe '.read' do
21
+ let(:is_cooked_mode) { false }
22
+ let(:is_fake_mode) { false }
23
+ let(:is_raw_mode) { false }
24
+ let(:keypress) {}
25
+ let(:_name) { 'Vedeu::Input::Capture' }
26
+ let(:interface) {
27
+ Vedeu::Interfaces::Interface.new(editable: editable,
28
+ name: _name)
29
+ }
30
+ let(:editable) { false }
31
+
21
32
  before do
22
- reader.stubs(:raw_mode?).returns(raw_mode)
23
- reader.stubs(:fake_mode?).returns(fake_mode)
24
- Vedeu.stubs(:trigger).returns([false])
33
+ Vedeu::Terminal::Mode.stubs(:cooked_mode?).returns(is_cooked_mode)
34
+ Vedeu::Terminal::Mode.stubs(:fake_mode?).returns(is_fake_mode)
35
+ Vedeu::Terminal::Mode.stubs(:raw_mode?).returns(is_raw_mode)
36
+ Vedeu.stubs(:focus).returns(_name)
25
37
  end
26
38
 
27
- subject { described.read(reader) }
39
+ subject { described.read }
28
40
 
29
- context 'when in cooked mode' do
30
- let(:raw_mode) { false }
31
- let(:fake_mode) { false }
32
- let(:command) { 'help' }
41
+ it 'appends "Waiting for user input..." to the log' do
42
+ Vedeu.expects(:log)
43
+ subject
44
+ end
33
45
 
34
- before { reader.stubs(:read).returns(command) }
46
+ context 'when the terminal mode is :fake' do
47
+ let(:is_fake_mode) { true }
48
+ let(:registered) { false }
35
49
 
36
- it 'triggers an event with the command' do
37
- Vedeu.expects(:trigger).with(:_command_, command)
38
- subject
50
+ before do
51
+ Vedeu::Terminal.console.stubs(:getch).returns(keypress)
52
+ Vedeu::Input::Mapper.stubs(:registered?).with(translated, _name).returns(registered)
53
+ Vedeu.interfaces.stubs(:by_name).returns(interface)
39
54
  end
40
- end
41
55
 
42
- context 'when in fake mode' do
43
- let(:raw_mode) { false }
44
- let(:fake_mode) { true }
45
- let(:keypress) { 'b' }
56
+ context 'when the keypress is an escape sequence' do
57
+ context 'when the key is :shift_f5 (read_nonblock(7))' do
58
+ let(:keypress) { "\e[15;2~" }
59
+ let(:translated) { :shift_f5 }
46
60
 
47
- before { reader.stubs(:read).returns(keypress) }
61
+ context 'when the key is registered with a keymap' do
62
+ let(:registered) { true }
48
63
 
49
- context 'when an interface or view has been registered' do
50
- let(:interface_name) { :fake_interface }
51
- let(:interface) {
52
- Vedeu::Interfaces::Interface.new(name: interface_name, editable: editable)
53
- }
54
- let(:editable) { false }
55
- let(:registered) { false }
64
+ it {
65
+ Vedeu::Input::Mapper.expects(:registered?).with(translated, _name)
66
+ subject
67
+ }
68
+
69
+ it {
70
+ Vedeu.expects(:trigger).with(:_keypress_, translated, 'Vedeu::Input::Capture')
71
+ subject
72
+ }
73
+ end
56
74
 
57
- before do
58
- Vedeu.stubs(:focus).returns(interface_name)
59
- Vedeu.interfaces.stubs(:by_name).with(interface_name).returns(interface)
60
- Vedeu::Input::Mapper.expects(:registered?).with(keypress, interface_name).returns(registered)
75
+ context 'when the key is not registered with a keymap' do
76
+ context 'when the interface is editable' do
77
+ let(:editable) { true }
78
+
79
+ it {
80
+ Vedeu.expects(:trigger).with(:_editor_, :shift_f5)
81
+ subject
82
+ }
83
+ end
84
+
85
+ context 'when the interface is not editable' do
86
+ it {
87
+ Vedeu.expects(:trigger).with(:key, :shift_f5)
88
+ subject
89
+ }
90
+ end
91
+ end
61
92
  end
62
93
 
63
- context 'when the keypress is registered with the keymap' do
64
- let(:registered) { true }
94
+ context 'when the key is really a mouse click (read_nonblock(6))' do
95
+ let(:keypress) { "\e[M`6E" }
96
+ let(:translated) {}
65
97
 
66
- it 'triggers an event with the keypress' do
67
- Vedeu.expects(:trigger).with(:_keypress_, keypress, interface_name)
98
+ it {
99
+ Vedeu.expects(:trigger).with(:_cursor_up_, _name)
100
+ Vedeu.expects(:trigger).with(:_mouse_event_, "\e[M`6E")
68
101
  subject
69
- end
102
+ }
70
103
  end
71
104
 
72
- context 'when the keypress is not registered with the keymap' do
73
- let(:registered) { false }
105
+ context 'when the key is :f6 key (read_nonblock(5))' do
106
+ let(:keypress) { "\e[17~" }
107
+ let(:translated) { :f6 }
74
108
 
75
- context 'when the interface or view is editable' do
76
- let(:editable) { true }
109
+ it {
110
+ Vedeu.expects(:trigger).with(:key, translated)
111
+ subject
112
+ }
113
+ end
77
114
 
78
- it 'triggers an event with the keypress' do
79
- Vedeu.expects(:trigger).with(:_editor_, keypress)
80
- subject
81
- end
82
- end
115
+ context 'when the key is :delete (read_nonblock(4))' do
116
+ let(:keypress) { "\e[3~" }
117
+ let(:translated) { :delete }
83
118
 
84
- context 'when the interface or view is not editable' do
85
- let(:editable) { false }
119
+ it {
120
+ Vedeu.expects(:trigger).with(:key, translated)
121
+ subject
122
+ }
123
+ end
86
124
 
87
- it 'triggers an event with the keypress' do
88
- Vedeu.expects(:trigger).with(:key, keypress)
89
- subject
90
- end
91
- end
125
+ context 'when the key is :up (read_nonblock(3))' do
126
+ let(:keypress) { "\e[A" }
127
+ let(:translated) { :up }
128
+
129
+ it {
130
+ Vedeu.expects(:trigger).with(:key, translated)
131
+ subject
132
+ }
133
+ end
134
+
135
+ context 'when the key is :escape (read_nonblock(1))' do
136
+ let(:keypress) { "\e" }
137
+ let(:translated) { :escape }
138
+
139
+ it {
140
+ Vedeu.expects(:trigger).with(:key, translated)
141
+ subject
142
+ }
92
143
  end
93
144
  end
94
145
 
95
- # context 'when no interfaces or views have been registered' do
96
- # before {
97
- # Vedeu.focus.reset
98
- # Vedeu.interfaces.reset
99
- # }
146
+ context 'when the keypress is not an escape sequence' do
147
+ let(:keypress) { 'r' }
148
+ let(:translated) { 'r' }
100
149
 
101
- # it { proc { subject }.must_raise(Vedeu::Error::Fatal) }
102
- # end
150
+ it {
151
+ Vedeu.expects(:trigger).with(:key, keypress)
152
+ subject
153
+ }
154
+ end
103
155
  end
104
156
 
105
- context 'when in raw mode' do
106
- let(:raw_mode) { true }
107
- let(:fake_mode) { false }
108
- let(:keypress) { 'a' }
157
+ context 'when the terminal mode is :raw' do
158
+ let(:is_raw_mode) { true }
109
159
 
110
- before { reader.stubs(:read).returns(keypress) }
160
+ before do
161
+ Vedeu::Terminal.console.stubs(:getch).returns(keypress)
162
+ end
111
163
 
112
- context 'when the key is not special' do
113
- it 'triggers an event with the keypress' do
114
- Vedeu.expects(:trigger).with(:_keypress_, keypress)
115
- subject
164
+ context 'when the keypress is an escape sequence' do
165
+ context 'when the key is :shift_f5 (read_nonblock(7))' do
166
+ let(:keypress) { "\e[15;2~" }
167
+
168
+ it {
169
+ Vedeu.expects(:trigger).with(:_keypress_, :shift_f5)
170
+ subject
171
+ }
116
172
  end
117
- end
118
173
 
119
- context 'when the key is special' do
120
- let(:keypress) { "\e[A" }
174
+ context 'when the key is really a mouse click (read_nonblock(6))' do
175
+ let(:keypress) { "\e[M`6E" }
121
176
 
122
- it 'triggers an event with the keypress' do
123
- Vedeu.expects(:trigger).with(:_keypress_, :up)
124
- subject
177
+ it {
178
+ Vedeu.expects(:trigger).with(:_cursor_up_, _name)
179
+ Vedeu.expects(:trigger).with(:_mouse_event_, "\e[M`6E")
180
+ Vedeu.expects(:trigger).with(:_keypress_, nil)
181
+ subject
182
+ }
125
183
  end
126
184
 
127
- context 'when the key is an F key' do
185
+ context 'when the key is :f6 key (read_nonblock(5))' do
128
186
  let(:keypress) { "\e[17~" }
129
187
 
130
- it 'triggers an event with the keypress' do
188
+ it {
131
189
  Vedeu.expects(:trigger).with(:_keypress_, :f6)
132
190
  subject
133
- end
191
+ }
192
+ end
193
+
194
+ context 'when the key is :delete (read_nonblock(4))' do
195
+ let(:keypress) { "\e[3~" }
196
+
197
+ it {
198
+ Vedeu.expects(:trigger).with(:_keypress_, :delete)
199
+ subject
200
+ }
134
201
  end
202
+
203
+ context 'when the key is :up (read_nonblock(3))' do
204
+ let(:keypress) { "\e[A" }
205
+
206
+ it {
207
+ Vedeu.expects(:trigger).with(:_keypress_, :up)
208
+ subject
209
+ }
210
+ end
211
+
212
+ context 'when the key is :escape (read_nonblock(1))' do
213
+ let(:keypress) { "\e" }
214
+
215
+ it {
216
+ Vedeu.expects(:trigger).with(:_keypress_, :escape)
217
+ subject
218
+ }
219
+ end
220
+ end
221
+
222
+ context 'when the keypress is not an escape sequence' do
223
+ let(:keypress) { 'r' }
224
+
225
+ it {
226
+ Vedeu.expects(:trigger).with(:_keypress_, keypress)
227
+ subject
228
+ }
229
+ end
230
+ end
231
+
232
+ context 'when the terminal mode is :cooked' do
233
+ let(:command) { "help\n" }
234
+ let(:is_cooked_mode) { true }
235
+
236
+ before do
237
+ Vedeu::Terminal.console.stubs(:gets).returns(command)
238
+ end
239
+
240
+ context 'when the input is a mouse click' do
241
+ let(:command) { "\e[M`6E" }
242
+
243
+ it {
244
+ Vedeu.expects(:trigger).with(:_command_, command)
245
+ subject
246
+ }
247
+ end
248
+
249
+ context 'when the input is not a mouse click' do
250
+ it {
251
+ Vedeu.expects(:trigger).with(:_command_, 'help')
252
+ subject
253
+ }
135
254
  end
136
255
  end
137
256
  end
@@ -25,6 +25,7 @@ module Vedeu
25
25
  let(:input) { "\e[M ,%" }
26
26
 
27
27
  it {
28
+ Vedeu.expects(:trigger).with(:_mouse_event_, input)
28
29
  Vedeu.expects(:trigger).with(:_cursor_reposition_, Vedeu.focus, 5, 12)
29
30
  subject
30
31
  }
@@ -34,6 +35,7 @@ module Vedeu
34
35
  let(:input) { "\e[M`6E" }
35
36
 
36
37
  it {
38
+ Vedeu.expects(:trigger).with(:_mouse_event_, input)
37
39
  Vedeu.expects(:trigger).with(:_cursor_up_, Vedeu.focus)
38
40
  subject
39
41
  }
@@ -43,6 +45,7 @@ module Vedeu
43
45
  let(:input) { "\e[MaN5" }
44
46
 
45
47
  it {
48
+ Vedeu.expects(:trigger).with(:_mouse_event_, input)
46
49
  Vedeu.expects(:trigger).with(:_cursor_down_, Vedeu.focus)
47
50
  subject
48
51
  }
@@ -52,6 +55,7 @@ module Vedeu
52
55
  let(:input) { "\e[Mb0(" }
53
56
 
54
57
  it {
58
+ Vedeu.expects(:trigger).with(:_mouse_event_, input)
55
59
  subject.must_equal("\e[93m[input] \e[39m\e[33mVedeu does not " \
56
60
  "support mouse button '66' yet.\e[39m")
57
61
  }
@@ -22,9 +22,15 @@ module Vedeu
22
22
  }
23
23
  let(:visible) { true }
24
24
  let(:interface) {
25
- Vedeu::Interfaces::Interface.new(style: nil, visible: visible)
25
+ Vedeu::Interfaces::Interface.new(name: 'lithium',
26
+ style: nil,
27
+ visible: visible)
28
+ }
29
+ let(:geometry) {
30
+ Vedeu::Geometry::Geometry.new(name: 'lithium',
31
+ height: 3,
32
+ width: 3)
26
33
  }
27
- let(:geometry) { Vedeu::Geometry::Geometry.new(height: 3, width: 3) }
28
34
  let(:ready) { true }
29
35
 
30
36
  before do
@@ -44,40 +44,6 @@ module Vedeu
44
44
  end
45
45
  end
46
46
 
47
- describe '.input' do
48
- before { Vedeu.stubs(:log) }
49
-
50
- subject { Vedeu::Terminal.input }
51
-
52
- it { described.must_respond_to(:read) }
53
-
54
- context 'when the terminal is in cooked mode' do
55
- let(:mode) { :cooked }
56
- let(:input) { "Some input\r\n" }
57
-
58
- before do
59
- Vedeu::Terminal.stubs(:mode).returns(mode)
60
- console.stubs(:gets).returns(input)
61
- end
62
-
63
- it { subject.must_equal('Some input') }
64
- end
65
-
66
- # context 'when the terminal is in raw mode' do
67
- # let(:mode) { :raw }
68
- # let(:input) { "\e[A" }
69
-
70
- # before do
71
- # Vedeu::Terminal.stubs(:mode).returns(mode)
72
- # # console.stubs(:getch).returns(input)
73
- # # input.stubs(:ord).returns(27)
74
- # # console.stubs(:read_nonblock)
75
- # end
76
-
77
- # it { subject.must_be_instance_of(Symbol) }
78
- # end
79
- end
80
-
81
47
  describe '.output' do
82
48
  before { IO.console.stubs(:print) }
83
49
 
@@ -270,14 +270,12 @@ class VedeuMaterialColoursApp
270
270
  zindex(0)
271
271
  end
272
272
 
273
-
274
-
275
273
  Vedeu.keymap('_global_') do
276
- key(:up) { Vedeu.trigger(:_cursor_up_) }
277
- key(:right) { Vedeu.trigger(:_cursor_right_) }
278
- key(:down) { Vedeu.trigger(:_cursor_down_) }
279
- key(:left) { Vedeu.trigger(:_cursor_left_) }
280
- key(:home) { Vedeu.trigger(:_cursor_top_) }
274
+ key(:up) { Vedeu.trigger(:_cursor_up_) }
275
+ key(:right) { Vedeu.trigger(:_cursor_right_) }
276
+ key(:down) { Vedeu.trigger(:_cursor_down_) }
277
+ key(:left) { Vedeu.trigger(:_cursor_left_) }
278
+ key(:home) { Vedeu.trigger(:_cursor_top_) }
281
279
  key(:end) { Vedeu.trigger(:_cursor_bottom_) }
282
280
 
283
281
  key(:insert) do
@@ -373,7 +371,7 @@ class VedeuMaterialColoursApp
373
371
  end
374
372
 
375
373
  view 'keys_interface' do
376
- # cursor false
374
+ cursor false
377
375
  line {
378
376
  stream {
379
377
  left "\u2190 \u2193 \u2191 \u2192",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.59
4
+ version: 0.6.60
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-17 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -332,7 +332,6 @@ files:
332
332
  - lib/vedeu/borders/border.rb
333
333
  - lib/vedeu/borders/caption.rb
334
334
  - lib/vedeu/borders/dsl.rb
335
- - lib/vedeu/borders/null.rb
336
335
  - lib/vedeu/borders/refresh.rb
337
336
  - lib/vedeu/borders/repository.rb
338
337
  - lib/vedeu/borders/title.rb
@@ -387,7 +386,6 @@ files:
387
386
  - lib/vedeu/dsl/use.rb
388
387
  - lib/vedeu/dsl/view.rb
389
388
  - lib/vedeu/editor/all.rb
390
- - lib/vedeu/editor/capture.rb
391
389
  - lib/vedeu/editor/cropper.rb
392
390
  - lib/vedeu/editor/cursor.rb
393
391
  - lib/vedeu/editor/delete.rb
@@ -537,7 +535,6 @@ files:
537
535
  - test/lib/vedeu/borders/border_test.rb
538
536
  - test/lib/vedeu/borders/caption_test.rb
539
537
  - test/lib/vedeu/borders/dsl_test.rb
540
- - test/lib/vedeu/borders/null_test.rb
541
538
  - test/lib/vedeu/borders/refresh_test.rb
542
539
  - test/lib/vedeu/borders/repository_test.rb
543
540
  - test/lib/vedeu/borders/title_test.rb
@@ -576,7 +573,6 @@ files:
576
573
  - test/lib/vedeu/dsl/text_test.rb
577
574
  - test/lib/vedeu/dsl/use_test.rb
578
575
  - test/lib/vedeu/dsl/view_test.rb
579
- - test/lib/vedeu/editor/capture_test.rb
580
576
  - test/lib/vedeu/editor/cropper_test.rb
581
577
  - test/lib/vedeu/editor/cursor_test.rb
582
578
  - test/lib/vedeu/editor/delete_test.rb
@@ -750,7 +746,6 @@ test_files:
750
746
  - test/lib/vedeu/borders/border_test.rb
751
747
  - test/lib/vedeu/borders/caption_test.rb
752
748
  - test/lib/vedeu/borders/dsl_test.rb
753
- - test/lib/vedeu/borders/null_test.rb
754
749
  - test/lib/vedeu/borders/refresh_test.rb
755
750
  - test/lib/vedeu/borders/repository_test.rb
756
751
  - test/lib/vedeu/borders/title_test.rb
@@ -789,7 +784,6 @@ test_files:
789
784
  - test/lib/vedeu/dsl/text_test.rb
790
785
  - test/lib/vedeu/dsl/use_test.rb
791
786
  - test/lib/vedeu/dsl/view_test.rb
792
- - test/lib/vedeu/editor/capture_test.rb
793
787
  - test/lib/vedeu/editor/cropper_test.rb
794
788
  - test/lib/vedeu/editor/cursor_test.rb
795
789
  - test/lib/vedeu/editor/delete_test.rb
@@ -1,63 +0,0 @@
1
- module Vedeu
2
-
3
- module Borders
4
-
5
- # Provides a non-existent Vedeu::Borders::Border that acts like
6
- # the real thing, but does nothing.
7
- #
8
- # @api private
9
- #
10
- class Null
11
-
12
- extend Forwardable
13
-
14
- def_delegators :geometry,
15
- :bordered_width,
16
- :bordered_height,
17
- :bx,
18
- :bxn,
19
- :by,
20
- :byn,
21
- :x,
22
- :xn,
23
- :y,
24
- :yn
25
-
26
- # @!attribute [r] name
27
- # @return [String|Symbol|NilClass]
28
- attr_reader :name
29
-
30
- # Returns a new instance of Vedeu::Borders::Null.
31
- #
32
- # @param attributes [Hash<Symbol => void>]
33
- # @option attributes name [String|Symbol|NilClass]
34
- # @return [Vedeu::Borders::Null]
35
- def initialize(attributes = {})
36
- @attributes = attributes
37
- @name = @attributes[:name]
38
- end
39
-
40
- # @return [Boolean]
41
- def enabled?
42
- false
43
- end
44
-
45
- # @return [Array]
46
- def render
47
- []
48
- end
49
-
50
- private
51
-
52
- # Returns the geometry for the interface.
53
- #
54
- # @return (see Vedeu::Geometry::Repository#by_name)
55
- def geometry
56
- @geometry ||= Vedeu.geometries.by_name(name)
57
- end
58
-
59
- end # Null
60
-
61
- end # Borders
62
-
63
- end # Vedeu
@@ -1,66 +0,0 @@
1
- module Vedeu
2
-
3
- module Editor
4
-
5
- # Capture input from the terminal via 'getch'.
6
- #
7
- class Capture
8
-
9
- ESCAPE_KEY_CODE = 27 # \e
10
-
11
- # @param console [IO]
12
- # @return [String|Symbol]
13
- def self.read(console)
14
- new(console).read
15
- end
16
-
17
- # Returns a new instance of Vedeu::Editor::Capture.
18
- #
19
- # @param console [IO]
20
- # @return [Vedeu::Editor::Capture]
21
- def initialize(console)
22
- @console = console
23
- end
24
-
25
- # @return [String|Symbol]
26
- def read
27
- Vedeu::Input::Translator.translate(keys)
28
- end
29
-
30
- private
31
-
32
- # @return [String]
33
- def keys
34
- keys = console.getch
35
-
36
- if keys.ord == ESCAPE_KEY_CODE
37
- keys << console.read_nonblock(5) rescue nil
38
- keys << console.read_nonblock(4) rescue nil
39
- keys << console.read_nonblock(3) rescue nil
40
- keys << console.read_nonblock(2) rescue nil
41
- end
42
-
43
- return Vedeu::Input::Mouse.click(keys) if click?(keys)
44
-
45
- keys
46
- end
47
-
48
- # Returns a boolean indicating whether a mouse click was
49
- # received.
50
- #
51
- # @param keys [String]
52
- # @return [Boolean]
53
- def click?(keys)
54
- keys.start_with?("\e[M")
55
- end
56
-
57
- # @return [IO]
58
- def console
59
- @console || Vedeu::Terminal.console
60
- end
61
-
62
- end # Capture
63
-
64
- end # Editor
65
-
66
- end # Vedeu
@@ -1,52 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- module Borders
6
-
7
- describe Null do
8
-
9
- let(:described) { Vedeu::Borders::Null }
10
- let(:instance) { described.new(attributes) }
11
- let(:attributes){
12
- {
13
- name: _name
14
- }
15
- }
16
- let(:_name) { 'null_border' }
17
- let(:geometry) {
18
- Vedeu::Geometry::Geometry.new(name: _name, x: 4, y: 6, xn: 10, yn: 12)
19
- }
20
-
21
- before { Vedeu.geometries.stubs(:by_name).returns(geometry) }
22
-
23
- describe '#initialize' do
24
- it { instance.must_be_instance_of(described) }
25
- it {
26
- instance.instance_variable_get('@attributes').must_equal(attributes)
27
- }
28
- it { instance.instance_variable_get('@name').must_equal(_name) }
29
- end
30
-
31
- describe 'accessors' do
32
- it { instance.must_respond_to(:name) }
33
- end
34
-
35
- describe '#enabled' do
36
- subject { instance.enabled? }
37
-
38
- it { subject.must_equal(false) }
39
- end
40
-
41
- describe '#render' do
42
- subject { instance.render }
43
-
44
- it { subject.must_be_instance_of(Array) }
45
- it { subject.must_equal([]) }
46
- end
47
-
48
- end # Null
49
-
50
- end # Borders
51
-
52
- end # Vedeu
@@ -1,63 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
-
5
- module Editor
6
-
7
- describe Capture do
8
-
9
- let(:described) { Vedeu::Editor::Capture }
10
- let(:instance) { described.new(console) }
11
- let(:console) { mock }
12
-
13
- describe '#initialize' do
14
- it { instance.must_be_instance_of(described) }
15
- it { instance.instance_variable_get('@console').must_equal(console) }
16
- end
17
-
18
- describe '.read' do
19
- subject { described.read(console) }
20
-
21
- before do
22
- Vedeu::Terminal.stubs(:console).returns(console)
23
- console.stubs(:getch).returns(keys)
24
- end
25
-
26
- context 'when nothing is given' do
27
- let(:keys) { nil }
28
- end
29
-
30
- context 'when a single keypress is given' do
31
- let(:keys) { 'a' }
32
-
33
- it { subject.must_equal('a') }
34
- end
35
-
36
- context 'when a ctrl+keypress is given' do
37
- let(:keys) { "\u0001" }
38
-
39
- it { subject.must_equal(:ctrl_a) }
40
- end
41
-
42
- context 'when a shift+keypress is given' do
43
- let(:keys) { 'A' }
44
-
45
- it { subject.must_equal('A') }
46
- end
47
-
48
- context 'when a alt+keypress is given' do
49
- end
50
-
51
- context 'when a super+keypress is given' do
52
- end
53
- end
54
-
55
- describe '#read' do
56
- it { instance.must_respond_to(:read) }
57
- end
58
-
59
- end # Capture
60
-
61
- end # Editor
62
-
63
- end # Vedeu