vedeu 0.2.10 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/events.md +6 -0
- data/examples/{cursor_app/cursor_app.rb → cursor_app.rb} +1 -1
- data/examples/{lines_app/lines_app.rb → lines_app.rb} +1 -1
- data/lib/vedeu.rb +48 -28
- data/lib/vedeu/api/api.rb +8 -95
- data/lib/vedeu/application.rb +6 -2
- data/lib/vedeu/{models → colours}/background.rb +1 -1
- data/lib/vedeu/{models → colours}/colour.rb +0 -0
- data/lib/vedeu/{models → colours}/foreground.rb +2 -2
- data/lib/vedeu/{support/colour_translator.rb → colours/translator.rb} +7 -7
- data/lib/vedeu/input/input.rb +13 -5
- data/lib/vedeu/models/geometry.rb +30 -2
- data/lib/vedeu/models/key.rb +39 -0
- data/lib/vedeu/output/compositor.rb +30 -76
- data/lib/vedeu/output/output.rb +74 -0
- data/lib/vedeu/output/viewport.rb +36 -44
- data/lib/vedeu/repositories/buffers.rb +5 -18
- data/lib/vedeu/repositories/cursors.rb +16 -8
- data/lib/vedeu/repositories/events.rb +96 -9
- data/lib/vedeu/repositories/focus.rb +21 -20
- data/lib/vedeu/repositories/groups.rb +3 -11
- data/lib/vedeu/repositories/interfaces.rb +6 -9
- data/lib/vedeu/repositories/keymaps.rb +8 -3
- data/lib/vedeu/repositories/menus.rb +6 -21
- data/lib/vedeu/{models → repositories/models}/buffer.rb +62 -28
- data/lib/vedeu/{models → repositories/models}/cursor.rb +8 -2
- data/lib/vedeu/{models → repositories/models}/event.rb +7 -0
- data/lib/vedeu/repositories/models/group.rb +56 -0
- data/lib/vedeu/{models → repositories/models}/interface.rb +6 -0
- data/lib/vedeu/{models → repositories/models}/keymap.rb +7 -1
- data/lib/vedeu/{models → repositories/models}/menu.rb +9 -0
- data/lib/vedeu/{models → repositories/models}/offset.rb +8 -1
- data/lib/vedeu/repositories/offsets.rb +17 -12
- data/lib/vedeu/support/bounding_area.rb +127 -0
- data/lib/vedeu/support/common.rb +8 -0
- data/lib/vedeu/support/exceptions.rb +2 -12
- data/lib/vedeu/support/model.rb +14 -0
- data/lib/vedeu/support/refresh.rb +8 -7
- data/lib/vedeu/support/registrar.rb +7 -1
- data/lib/vedeu/support/repository.rb +31 -10
- data/lib/vedeu/support/sentence.rb +67 -0
- data/lib/vedeu/support/terminal.rb +19 -0
- data/lib/vedeu/support/trace.rb +2 -5
- data/test/integration/api/api_test.rb +97 -0
- data/test/integration/api_dsl/dsl_api_test.rb +4 -0
- data/test/integration/api_dsl/dsl_composition_test.rb +4 -0
- data/test/integration/api_dsl/dsl_defined_test.rb +4 -0
- data/test/integration/api_dsl/dsl_helpers_test.rb +4 -0
- data/test/integration/api_dsl/dsl_interface_test.rb +4 -0
- data/test/integration/api_dsl/dsl_keymap.rb +4 -0
- data/test/integration/api_dsl/dsl_line_test.rb +4 -0
- data/test/integration/api_dsl/dsl_menu_test.rb +4 -0
- data/test/integration/api_dsl/dsl_stream_test.rb +138 -0
- data/test/lib/vedeu/api/api_test.rb +1 -25
- data/test/lib/vedeu/api/helpers_test.rb +0 -10
- data/test/lib/vedeu/{models → colours}/background_test.rb +0 -0
- data/test/lib/vedeu/{models → colours}/colour_test.rb +0 -0
- data/test/lib/vedeu/{models → colours}/foreground_test.rb +0 -0
- data/test/lib/vedeu/{support/colour_translator_test.rb → colours/translator_test.rb} +3 -3
- data/test/lib/vedeu/input/input_test.rb +16 -47
- data/test/lib/vedeu/models/geometry_test.rb +46 -0
- data/test/lib/vedeu/models/group_test.rb +99 -0
- data/test/lib/vedeu/models/key_test.rb +41 -0
- data/test/lib/vedeu/output/compositor_test.rb +25 -101
- data/test/lib/vedeu/output/output_test.rb +108 -0
- data/test/lib/vedeu/repositories/buffers_test.rb +0 -8
- data/test/lib/vedeu/repositories/cursors_test.rb +34 -0
- data/test/lib/vedeu/repositories/focus_test.rb +37 -28
- data/test/lib/vedeu/repositories/interfaces_test.rb +1 -1
- data/test/lib/vedeu/repositories/keymaps_test.rb +6 -20
- data/test/lib/vedeu/repositories/menus_test.rb +0 -6
- data/test/lib/vedeu/{models → repositories/models}/buffer_test.rb +24 -27
- data/test/lib/vedeu/{models → repositories/models}/cursor_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/event_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/interface_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/keymap_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/menu_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/offset_test.rb +0 -0
- data/test/lib/vedeu/support/bounding_area_test.rb +139 -0
- data/test/lib/vedeu/support/coercions_test.rb +6 -17
- data/test/lib/vedeu/support/grid_test.rb +1 -1
- data/test/lib/vedeu/support/model_test.rb +23 -0
- data/test/lib/vedeu/support/presentation_test.rb +0 -10
- data/test/lib/vedeu/support/refresh_test.rb +2 -2
- data/test/lib/vedeu/support/repository_test.rb +63 -64
- data/test/lib/vedeu/support/sentence_test.rb +48 -0
- data/test/lib/vedeu/support/terminal_test.rb +86 -6
- data/test/support/test_classes/all.rb +5 -0
- data/test/support/test_classes/coercions.rb +16 -0
- data/test/support/test_classes/helpers.rb +19 -0
- data/test/support/test_classes/model.rb +23 -0
- data/test/support/test_classes/presentation.rb +16 -0
- data/test/support/test_classes/repositories.rb +26 -0
- data/test/support/test_modules/all.rb +1 -0
- data/test/support/test_modules/repository.rb +16 -0
- data/test/test_helper.rb +4 -0
- data/vedeu.gemspec +3 -3
- metadata +95 -50
- data/lib/vedeu/output/clear.rb +0 -88
- data/lib/vedeu/output/render.rb +0 -50
- data/lib/vedeu/repositories/positional.rb +0 -23
- data/test/lib/vedeu/output/clear_test.rb +0 -56
- data/test/lib/vedeu/output/render_test.rb +0 -100
- data/test/lib/vedeu/repositories/positional_test.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2e18e1de7f428b1890aacc71abffae0ea935431
|
4
|
+
data.tar.gz: 3c32f191ff6dfead712551de9c4375261d46dc54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b2dc0ebd0bfa591774ead8d58fdd090ca80152619545226230a02d72c2b9a0f991aa0813eec3bffeee38070091cedfce8a0e6df2648a8a740ffe6589bfe6c18
|
7
|
+
data.tar.gz: a785503d6086eaa2b8a4d1c4aa882f99d03ff4a791c42828fef352e053d0f146b67b4b6fa0e6bb2f9f87b46be82d8e1c42100e4d64c6d059263cff3cd9d9c01a
|
data/docs/events.md
CHANGED
@@ -156,6 +156,12 @@ applications can listen for this event and perform some action(s), like render
|
|
156
156
|
the first screen, interface or make a sound. When Vedeu triggers this event,
|
157
157
|
the :_refresh_ event is also triggered automatically.
|
158
158
|
|
159
|
+
### `:_tick_`
|
160
|
+
|
161
|
+
Each time Vedeu completes one cycle in the application loop
|
162
|
+
(Application#run_many), it triggers the `:_tick_` event. This can be used by the
|
163
|
+
client application for timing amongst other things.
|
164
|
+
|
159
165
|
#### How to define user events
|
160
166
|
|
161
167
|
```ruby
|
data/lib/vedeu.rb
CHANGED
@@ -15,6 +15,21 @@ module Vedeu
|
|
15
15
|
receiver.extend(API)
|
16
16
|
end
|
17
17
|
|
18
|
+
# Write a message to the Vedeu log file.
|
19
|
+
#
|
20
|
+
# @param message [String] The message you wish to emit to the log
|
21
|
+
# file, useful for debugging.
|
22
|
+
# @param force [Boolean] When evaluates to true will attempt to
|
23
|
+
# write to the log file regardless of the Configuration setting.
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# Vedeu.log('A useful debugging message: Error!')
|
27
|
+
#
|
28
|
+
# @return [TrueClass]
|
29
|
+
def self.log(message, force = false)
|
30
|
+
Vedeu::Log.logger.debug(message) if Configuration.debug? || force
|
31
|
+
end
|
32
|
+
|
18
33
|
end # Vedeu
|
19
34
|
|
20
35
|
$LIB_DIR = File.dirname(__FILE__) + '/../lib'
|
@@ -29,8 +44,10 @@ require 'set'
|
|
29
44
|
require 'singleton'
|
30
45
|
require 'time'
|
31
46
|
|
32
|
-
require 'vedeu/support/exceptions'
|
33
47
|
require 'vedeu/support/common'
|
48
|
+
require 'vedeu/support/exceptions'
|
49
|
+
require 'vedeu/support/model'
|
50
|
+
|
34
51
|
require 'vedeu/configuration/cli'
|
35
52
|
require 'vedeu/configuration/api'
|
36
53
|
require 'vedeu/configuration/configuration'
|
@@ -38,36 +55,36 @@ require 'vedeu/configuration/configuration'
|
|
38
55
|
require 'vedeu/support/log'
|
39
56
|
require 'vedeu/support/trace'
|
40
57
|
|
41
|
-
require 'vedeu/
|
58
|
+
require 'vedeu/support/repository'
|
59
|
+
require 'vedeu/repositories/models/event'
|
60
|
+
require 'vedeu/repositories/events'
|
61
|
+
require 'vedeu/repositories/keymaps'
|
62
|
+
require 'vedeu/repositories/models/keymap'
|
42
63
|
require 'vedeu/api/keymap'
|
43
64
|
require 'vedeu/api/api'
|
44
65
|
|
45
|
-
require 'vedeu/
|
46
|
-
require 'vedeu/
|
47
|
-
require 'vedeu/
|
48
|
-
require 'vedeu/
|
49
|
-
require 'vedeu/support/presentation'
|
50
|
-
require 'vedeu/models/composition'
|
66
|
+
require 'vedeu/colours/translator'
|
67
|
+
require 'vedeu/colours/background'
|
68
|
+
require 'vedeu/colours/foreground'
|
69
|
+
require 'vedeu/colours/colour'
|
51
70
|
|
52
|
-
require 'vedeu/support/
|
53
|
-
require 'vedeu/support/position'
|
71
|
+
require 'vedeu/support/coercions'
|
54
72
|
require 'vedeu/support/esc'
|
73
|
+
require 'vedeu/support/position'
|
74
|
+
require 'vedeu/support/presentation'
|
75
|
+
require 'vedeu/support/sentence'
|
55
76
|
require 'vedeu/support/terminal'
|
56
77
|
|
57
|
-
require 'vedeu/models/buffer'
|
58
78
|
require 'vedeu/models/char'
|
59
|
-
require 'vedeu/models/
|
60
|
-
require 'vedeu/models/cursor'
|
61
|
-
require 'vedeu/models/event'
|
79
|
+
require 'vedeu/models/composition'
|
62
80
|
require 'vedeu/models/geometry'
|
63
|
-
require 'vedeu/models/
|
81
|
+
require 'vedeu/models/key'
|
64
82
|
require 'vedeu/models/line'
|
65
|
-
require 'vedeu/models/menu'
|
66
|
-
require 'vedeu/models/offset'
|
67
83
|
require 'vedeu/models/stream'
|
68
84
|
require 'vedeu/models/style'
|
69
85
|
|
70
|
-
require 'vedeu/repositories/
|
86
|
+
require 'vedeu/repositories/models/interface'
|
87
|
+
require 'vedeu/repositories/interfaces'
|
71
88
|
|
72
89
|
require 'vedeu/api/defined'
|
73
90
|
require 'vedeu/api/composition'
|
@@ -77,27 +94,30 @@ require 'vedeu/api/line'
|
|
77
94
|
require 'vedeu/api/menu'
|
78
95
|
require 'vedeu/api/stream'
|
79
96
|
|
97
|
+
require 'vedeu/repositories/models/buffer'
|
98
|
+
require 'vedeu/repositories/models/cursor'
|
99
|
+
require 'vedeu/repositories/models/group'
|
100
|
+
require 'vedeu/repositories/models/menu'
|
101
|
+
require 'vedeu/repositories/models/offset'
|
102
|
+
|
80
103
|
require 'vedeu/support/keymap_validator'
|
81
|
-
|
82
|
-
require 'vedeu/repositories/offsets'
|
83
|
-
require 'vedeu/repositories/menus'
|
84
|
-
require 'vedeu/repositories/keymaps'
|
85
|
-
require 'vedeu/repositories/interfaces'
|
86
|
-
require 'vedeu/repositories/groups'
|
87
|
-
require 'vedeu/repositories/focus'
|
88
|
-
require 'vedeu/repositories/events'
|
104
|
+
|
89
105
|
require 'vedeu/repositories/buffers'
|
90
106
|
require 'vedeu/repositories/cursors'
|
107
|
+
require 'vedeu/repositories/focus'
|
108
|
+
require 'vedeu/repositories/groups'
|
109
|
+
require 'vedeu/repositories/menus'
|
110
|
+
require 'vedeu/repositories/offsets'
|
91
111
|
|
92
112
|
require 'vedeu/support/registrar'
|
93
113
|
require 'vedeu/support/refresh'
|
94
114
|
|
95
|
-
require 'vedeu/output/clear'
|
96
115
|
require 'vedeu/output/compositor'
|
97
|
-
require 'vedeu/output/
|
116
|
+
require 'vedeu/output/output'
|
98
117
|
require 'vedeu/output/view'
|
99
118
|
require 'vedeu/output/viewport'
|
100
119
|
|
120
|
+
require 'vedeu/support/bounding_area'
|
101
121
|
require 'vedeu/support/grid'
|
102
122
|
|
103
123
|
require 'vedeu/input/input'
|
data/lib/vedeu/api/api.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'vedeu/support/terminal'
|
2
|
+
|
1
3
|
module Vedeu
|
2
4
|
|
3
5
|
# Provides the API to Vedeu. Methods therein, and classes belonging to this
|
@@ -8,7 +10,11 @@ module Vedeu
|
|
8
10
|
|
9
11
|
extend Forwardable
|
10
12
|
|
11
|
-
|
13
|
+
# @see Vedeu::Events#add
|
14
|
+
def_delegators Events, :event
|
15
|
+
def_delegators Keymap, :keys
|
16
|
+
def_delegators Keymaps, :keypress
|
17
|
+
def_delegators Vedeu::Terminal, :height, :width
|
12
18
|
|
13
19
|
# Configure Vedeu using a simple configuration DSL.
|
14
20
|
#
|
@@ -31,72 +37,16 @@ module Vedeu
|
|
31
37
|
Vedeu::API::Defined
|
32
38
|
end
|
33
39
|
|
34
|
-
# Register an event by name with optional delay (throttling) which when
|
35
|
-
# triggered will execute the code contained within the passed block.
|
36
|
-
#
|
37
|
-
# @param name [Symbol] The name of the event which will be triggered later.
|
38
|
-
# @param [Hash] opts The options to register the event with.
|
39
|
-
# @option opts :delay [Fixnum|Float] Limits the execution of the
|
40
|
-
# triggered event to only execute when first triggered, with subsequent
|
41
|
-
# triggering being ignored until the delay has expired.
|
42
|
-
# @option opts :debounce [Fixnum|Float] Limits the execution of the
|
43
|
-
# triggered event to only execute once the debounce has expired.
|
44
|
-
# Subsequent triggers before debounce expiry are ignored.
|
45
|
-
# @param block [Proc] The event to be executed when triggered. This block
|
46
|
-
# could be a method call, or the triggering of another event, or sequence
|
47
|
-
# of either/both.
|
48
|
-
#
|
49
|
-
# @example
|
50
|
-
# Vedeu.event :my_event do |some, args|
|
51
|
-
# ... some code here ...
|
52
|
-
#
|
53
|
-
# Vedeu.trigger(:my_other_event)
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# T = Triggered, X = Executed, i = Ignored.
|
57
|
-
#
|
58
|
-
# 0.0.....0.2.....0.4.....0.6.....0.8.....1.0.....1.2.....1.4.....1.6...
|
59
|
-
# .T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T
|
60
|
-
# .X...i...i...i...i...X...i...i...i...i...X...i...i...i...i...i...i...i
|
61
|
-
#
|
62
|
-
# Vedeu.event(:my_delayed_event, { delay: 0.5 })
|
63
|
-
# ... some code here ...
|
64
|
-
# end
|
65
|
-
#
|
66
|
-
# T = Triggered, X = Executed, i = Ignored.
|
67
|
-
#
|
68
|
-
# 0.0.....0.2.....0.4.....0.6.....0.8.....1.0.....1.2.....1.4.....1.6...
|
69
|
-
# .T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T...T
|
70
|
-
# .i...i...i...i...i...i...i...X...i...i...i...i...i...i...X...i...i...i
|
71
|
-
#
|
72
|
-
# Vedeu.event(:my_debounced_event, { debounce: 0.7 })
|
73
|
-
# ... some code here ...
|
74
|
-
# end
|
75
|
-
#
|
76
|
-
# @return [Hash]
|
77
|
-
def event(name, opts = {}, &block)
|
78
|
-
Events.add(name, opts, &block)
|
79
|
-
end
|
80
|
-
|
81
40
|
# Used after defining an interface or interfaces to set the initially
|
82
41
|
# focussed interface.
|
83
42
|
#
|
84
43
|
# @param name [String] The interface to focus; must be defined.
|
85
44
|
# @return [String] The name of the interface now in focus.
|
86
|
-
# @raise [
|
45
|
+
# @raise [ModelNotFound] When the interface cannot be found.
|
87
46
|
def focus(name)
|
88
47
|
Vedeu.trigger(:_focus_by_name_, name)
|
89
48
|
end
|
90
49
|
|
91
|
-
# Find out how many lines the current terminal is able to display.
|
92
|
-
#
|
93
|
-
# @example
|
94
|
-
# Vedeu.height
|
95
|
-
#
|
96
|
-
# @return [Fixnum] The total height of the current terminal.
|
97
|
-
def height
|
98
|
-
Terminal.height
|
99
|
-
end
|
100
50
|
|
101
51
|
# Register an interface by name which will display output from a event or
|
102
52
|
# command. This provides the means for you to define your application's
|
@@ -121,33 +71,6 @@ module Vedeu
|
|
121
71
|
API::Interface.define({ name: name }, &block)
|
122
72
|
end
|
123
73
|
|
124
|
-
# Simulate a keypress.
|
125
|
-
#
|
126
|
-
# @todo Replace with: def_delegators Keymaps, :keypress
|
127
|
-
#
|
128
|
-
# @example
|
129
|
-
# Vedeu.keypress('s')
|
130
|
-
#
|
131
|
-
# @see Vedeu::Keymaps.use
|
132
|
-
def keypress(key)
|
133
|
-
Vedeu::Keymaps.use(key)
|
134
|
-
end
|
135
|
-
|
136
|
-
# Write a message to the Vedeu log file.
|
137
|
-
#
|
138
|
-
# @param message [String] The message you wish to emit to the log
|
139
|
-
# file, useful for debugging.
|
140
|
-
# @param force [Boolean] When evaluates to true will attempt to
|
141
|
-
# write to the log file regardless of the Configuration setting.
|
142
|
-
#
|
143
|
-
# @example
|
144
|
-
# Vedeu.log('A useful debugging message: Error!')
|
145
|
-
#
|
146
|
-
# @return [TrueClass]
|
147
|
-
def log(message, force = false)
|
148
|
-
Vedeu::Log.logger.debug(message) if Configuration.debug? || force
|
149
|
-
end
|
150
|
-
|
151
74
|
# Register a menu by name which will display a collection of items for your
|
152
75
|
# users to select; and provide interactivity within your application.
|
153
76
|
#
|
@@ -307,16 +230,6 @@ module Vedeu
|
|
307
230
|
end
|
308
231
|
alias_method :composition, :views
|
309
232
|
|
310
|
-
# Find out how many columns the current terminal is able to display.
|
311
|
-
#
|
312
|
-
# @example
|
313
|
-
# Vedeu.width
|
314
|
-
#
|
315
|
-
# @return [Fixnum] The total width of the current terminal.
|
316
|
-
def width
|
317
|
-
Terminal.width
|
318
|
-
end
|
319
|
-
|
320
233
|
end # API
|
321
234
|
|
322
235
|
extend API
|
data/lib/vedeu/application.rb
CHANGED
@@ -80,7 +80,7 @@ module Vedeu
|
|
80
80
|
# @return []
|
81
81
|
def main_sequence
|
82
82
|
if Configuration.interactive?
|
83
|
-
Input.capture
|
83
|
+
Input.capture(Terminal)
|
84
84
|
|
85
85
|
else
|
86
86
|
Vedeu.trigger(:_standalone_)
|
@@ -94,7 +94,11 @@ module Vedeu
|
|
94
94
|
#
|
95
95
|
# @return []
|
96
96
|
def run_many
|
97
|
-
loop
|
97
|
+
loop do
|
98
|
+
Vedeu.trigger(:_tick_)
|
99
|
+
yield
|
100
|
+
|
101
|
+
end
|
98
102
|
|
99
103
|
rescue ModeSwitch
|
100
104
|
Terminal.switch_mode!
|
File without changes
|
@@ -4,7 +4,7 @@ module Vedeu
|
|
4
4
|
# {Vedeu::Background}) of a terminal colour escape sequence.
|
5
5
|
#
|
6
6
|
# @api private
|
7
|
-
class Foreground <
|
7
|
+
class Foreground < Translator
|
8
8
|
|
9
9
|
private
|
10
10
|
|
@@ -39,7 +39,7 @@ module Vedeu
|
|
39
39
|
end
|
40
40
|
|
41
41
|
# Produces the foreground named colour escape sequence hash from
|
42
|
-
# {Vedeu::
|
42
|
+
# {Vedeu::Translator#codes}
|
43
43
|
#
|
44
44
|
# @return [Hash]
|
45
45
|
def foreground_codes
|
@@ -20,26 +20,26 @@ module Vedeu
|
|
20
20
|
#
|
21
21
|
# @todo More documentation required (create a fancy chart!)
|
22
22
|
# @api private
|
23
|
-
class
|
23
|
+
class Translator
|
24
24
|
|
25
25
|
# Convert a CSS/HTML colour string into a terminal escape sequence.
|
26
26
|
#
|
27
|
-
# @param colour [String]
|
27
|
+
# @param colour [Fixnum|String|Symbol]
|
28
28
|
# @return [String]
|
29
29
|
def self.escape_sequence(colour = '')
|
30
30
|
new(colour).escape_sequence
|
31
31
|
end
|
32
32
|
|
33
|
-
# Return a new instance of
|
33
|
+
# Return a new instance of Translator.
|
34
34
|
#
|
35
|
-
# @param colour [String]
|
36
|
-
# @return [
|
35
|
+
# @param colour [Fixnum|String|Symbol]
|
36
|
+
# @return [Translator]
|
37
37
|
def initialize(colour = '')
|
38
38
|
@colour = colour
|
39
39
|
end
|
40
40
|
|
41
41
|
# @return [String]
|
42
|
-
# @see Vedeu::
|
42
|
+
# @see Vedeu::Translator
|
43
43
|
def escape_sequence
|
44
44
|
if no_colour?
|
45
45
|
''
|
@@ -183,6 +183,6 @@ module Vedeu
|
|
183
183
|
(css_to_rgb[2] / 51) * 1
|
184
184
|
end
|
185
185
|
|
186
|
-
end #
|
186
|
+
end # Translator
|
187
187
|
|
188
188
|
end # Vedeu
|
data/lib/vedeu/input/input.rb
CHANGED
@@ -8,30 +8,38 @@ module Vedeu
|
|
8
8
|
|
9
9
|
# Instantiate Input and capture keypress(es).
|
10
10
|
#
|
11
|
+
# @param reader [IO] An object that responds to `#read`. Typically, this is
|
12
|
+
# Vedeu::Terminal.
|
11
13
|
# @return [String|Symbol]
|
12
|
-
def self.capture
|
13
|
-
new.capture
|
14
|
+
def self.capture(reader)
|
15
|
+
new(reader).capture
|
14
16
|
end
|
15
17
|
|
16
18
|
# Returns a new instance of Input.
|
17
19
|
#
|
20
|
+
# @param reader [IO] An object that responds to `#read`. Typically, this is
|
21
|
+
# Vedeu::Terminal.
|
18
22
|
# @return [Input]
|
19
|
-
def initialize
|
23
|
+
def initialize(reader)
|
24
|
+
@reader = reader
|
25
|
+
end
|
20
26
|
|
21
27
|
# Triggers the keypress event with the key(s) pressed.
|
22
28
|
#
|
23
|
-
# @return []
|
29
|
+
# @return [Array|String|Symbol]
|
24
30
|
def capture
|
25
31
|
Vedeu.trigger(:_keypress_, keypress)
|
26
32
|
end
|
27
33
|
|
28
34
|
private
|
29
35
|
|
36
|
+
attr_reader :reader
|
37
|
+
|
30
38
|
# Returns the input from the terminal.
|
31
39
|
#
|
32
40
|
# @return [String]
|
33
41
|
def input
|
34
|
-
@_input ||=
|
42
|
+
@_input ||= reader.read
|
35
43
|
end
|
36
44
|
|
37
45
|
# Returns the translated (if possible) keypress(es) as either a String or a
|