tty-reader 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +10 -0
- data/README.md +25 -9
- data/appveyor.yml +2 -0
- data/lib/tty/reader.rb +37 -0
- data/lib/tty/reader/keys.rb +13 -11
- data/lib/tty/reader/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c03f74e7241085592fa20639a1e611fcc67236e0
|
4
|
+
data.tar.gz: 4e86e58a736ac624efcbb11bd4d4d09a7e80e7ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce215884478b45022b5e44a0f464906880dedcfb059f8f265ac6a016a41a622385ef2c899bb370c8f63d3417fac4ebcfb9ac284d819e7e97220c3ad0d52ee8bf
|
7
|
+
data.tar.gz: 7bf7f7e083acfefef98c5806f54c4e14398d286cb7e926f79a41ef7b4216f77d3d312074d1703a306bd4b280bccccc8e17ceb648d37e1419fada48aac10ab868
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## [v0.3.0] - 2018-04-29
|
4
|
+
|
5
|
+
### Added
|
6
|
+
* Add Reader#unsubscribe to allow stop listening to local key events
|
7
|
+
|
8
|
+
### Changed
|
9
|
+
* Change Reader#subscribe to allow to listening for key events only inside a block
|
10
|
+
* Change to group xterm keys for navigation
|
11
|
+
|
3
12
|
## [v0.2.0] - 2018-01-01
|
4
13
|
|
5
14
|
### Added
|
@@ -24,5 +33,6 @@
|
|
24
33
|
|
25
34
|
* Initial implementation and release
|
26
35
|
|
36
|
+
[v0.3.0]: https://github.com/piotrmurach/tty-reader/compare/v0.2.0...v0.3.0
|
27
37
|
[v0.2.0]: https://github.com/piotrmurach/tty-reader/compare/v0.1.0...v0.2.0
|
28
38
|
[v0.1.0]: https://github.com/piotrmurach/tty-reader/compare/v0.1.0
|
data/README.md
CHANGED
@@ -60,8 +60,9 @@ Or install it yourself as:
|
|
60
60
|
* [2.3 read_multiline](#23-read_multiline)
|
61
61
|
* [2.4 on](#24-on)
|
62
62
|
* [2.5 subscribe](#25-subscribe)
|
63
|
-
* [2.6
|
64
|
-
* [2.7
|
63
|
+
* [2.6 unsubscribe](#26-unsubscribe)
|
64
|
+
* [2.7 trigger](#27-trigger)
|
65
|
+
* [2.8 supported events](#28-supported-events)
|
65
66
|
* [3. Configuration](#3-configuration)
|
66
67
|
* [3.1 :interrupt](#31-interrupt)
|
67
68
|
* [3.2 :track_history](#32-track_history)
|
@@ -178,10 +179,10 @@ prompt.on(:keypress) { |key| ... }
|
|
178
179
|
|
179
180
|
You can subscribe any object to listen for the emitted [key events](#27-supported-events) using the `subscribe` message. The listener would need to implement a method for every event it wishes to receive.
|
180
181
|
|
181
|
-
For example, if a `
|
182
|
+
For example, if a `MyListener` class wishes to only listen for `keypress` event:
|
182
183
|
|
183
184
|
```ruby
|
184
|
-
class
|
185
|
+
class MyListener
|
185
186
|
def keypress(event)
|
186
187
|
...
|
187
188
|
end
|
@@ -191,11 +192,26 @@ end
|
|
191
192
|
Then subcribing is done:
|
192
193
|
|
193
194
|
```ruby
|
194
|
-
|
195
|
-
reader.subscribe(context)
|
195
|
+
reader.subscribe(MyListener.new)
|
196
196
|
```
|
197
197
|
|
198
|
-
|
198
|
+
Alternatively, `subscribe` allows you to listen to events only for the dueration of block execution like so:
|
199
|
+
|
200
|
+
```ruby
|
201
|
+
reader.subscribe(MyListener) do
|
202
|
+
...
|
203
|
+
end
|
204
|
+
```
|
205
|
+
|
206
|
+
### 2.6 unsubscribe
|
207
|
+
|
208
|
+
You can unsubscribe any object from listening to the key events using the `unsubscribe` message:
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
reader.unsubscribe(my_listener)
|
212
|
+
```
|
213
|
+
|
214
|
+
### 2.7 trigger
|
199
215
|
|
200
216
|
The signature for triggering key events is `trigger(event, args...)`. The first argument is a [key event name](#27-supported-events) followed by any number of actual values related to the event being triggered.
|
201
217
|
|
@@ -213,12 +229,12 @@ reader.on(:keypress) do |event|
|
|
213
229
|
reader.trigger(:keydown)
|
214
230
|
end
|
215
231
|
if evevnt.value == 'k'
|
216
|
-
reader.trigger(:
|
232
|
+
reader.trigger(:keyup)
|
217
233
|
end
|
218
234
|
end
|
219
235
|
```
|
220
236
|
|
221
|
-
### 2.
|
237
|
+
### 2.8 supported events
|
222
238
|
|
223
239
|
The available key events for character input are:
|
224
240
|
|
data/appveyor.yml
CHANGED
data/lib/tty/reader.rb
CHANGED
@@ -91,6 +91,43 @@ module TTY
|
|
91
91
|
subscribe(self)
|
92
92
|
end
|
93
93
|
|
94
|
+
alias old_subcribe subscribe
|
95
|
+
|
96
|
+
# Subscribe to receive key events
|
97
|
+
#
|
98
|
+
# @example
|
99
|
+
# reader.subscribe(MyListener.new)
|
100
|
+
#
|
101
|
+
# @return [self|yield]
|
102
|
+
#
|
103
|
+
# @api public
|
104
|
+
def subscribe(listener, options = {})
|
105
|
+
old_subcribe(listener, options)
|
106
|
+
object = self
|
107
|
+
if block_given?
|
108
|
+
object = yield
|
109
|
+
unsubscribe(listener)
|
110
|
+
end
|
111
|
+
object
|
112
|
+
end
|
113
|
+
|
114
|
+
# Unsubscribe from receiving key events
|
115
|
+
#
|
116
|
+
# @example
|
117
|
+
# reader.unsubscribe(my_listener)
|
118
|
+
#
|
119
|
+
# @return [void]
|
120
|
+
#
|
121
|
+
# @api public
|
122
|
+
def unsubscribe(listener)
|
123
|
+
registry = send(:local_registrations)
|
124
|
+
registry.each do |object|
|
125
|
+
if object.listener.equal?(listener)
|
126
|
+
registry.delete(object)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
94
131
|
# Select appropriate console
|
95
132
|
#
|
96
133
|
# @api private
|
data/lib/tty/reader/keys.rb
CHANGED
@@ -69,15 +69,22 @@ module TTY
|
|
69
69
|
"\e[D" => :left,
|
70
70
|
"\e[E" => :clear,
|
71
71
|
"\e[H" => :home,
|
72
|
-
"\eOH" => :home,
|
73
72
|
"\e[F" => :end,
|
74
|
-
"\eOF" => :end,
|
75
73
|
"\e[Z" => :back_tab, # shift + tab
|
76
74
|
|
77
|
-
|
78
|
-
"\
|
79
|
-
"\
|
80
|
-
"\
|
75
|
+
# xterm/gnome
|
76
|
+
"\eOA" => :up,
|
77
|
+
"\eOB" => :down,
|
78
|
+
"\eOC" => :right,
|
79
|
+
"\eOD" => :left,
|
80
|
+
"\eOE" => :clear,
|
81
|
+
"\eOF" => :end,
|
82
|
+
"\eOH" => :home,
|
83
|
+
|
84
|
+
"\eOP" => :f1, # xterm
|
85
|
+
"\eOQ" => :f2, # xterm
|
86
|
+
"\eOR" => :f3, # xterm
|
87
|
+
"\eOS" => :f4, # xterm
|
81
88
|
"\e[[A" => :f1, # linux
|
82
89
|
"\e[[B" => :f2, # linux
|
83
90
|
"\e[[C" => :f3, # linux
|
@@ -115,11 +122,6 @@ module TTY
|
|
115
122
|
"\e[21;2~" => :f22,
|
116
123
|
"\e[23;2~" => :f23,
|
117
124
|
"\e[24;2~" => :f24,
|
118
|
-
|
119
|
-
"\eOA" => :up,
|
120
|
-
"\eOB" => :down,
|
121
|
-
"\eOC" => :right,
|
122
|
-
"\eOD" => :left
|
123
125
|
}
|
124
126
|
end
|
125
127
|
module_function :keys
|
data/lib/tty/reader/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wisper
|