reline 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,75 @@
1
+ require 'timeout'
2
+
3
+ class Reline::GeneralIO
4
+ def self.encoding
5
+ RUBY_PLATFORM =~ /mswin|mingw/ ? Encoding::UTF_8 : Encoding::default_external
6
+ end
7
+
8
+ def self.win?
9
+ false
10
+ end
11
+
12
+ RAW_KEYSTROKE_CONFIG = {}
13
+
14
+ @@buf = []
15
+
16
+ def self.input=(val)
17
+ @@input = val
18
+ end
19
+
20
+ def self.getc
21
+ unless @@buf.empty?
22
+ return @@buf.shift
23
+ end
24
+ c = nil
25
+ loop do
26
+ result = select([@@input], [], [], 0.1)
27
+ next if result.nil?
28
+ c = @@input.read(1)
29
+ break
30
+ end
31
+ c&.ord
32
+ end
33
+
34
+ def self.ungetc(c)
35
+ @@buf.unshift(c)
36
+ end
37
+
38
+ def self.get_screen_size
39
+ [1, 1]
40
+ end
41
+
42
+ def self.cursor_pos
43
+ Reline::CursorPos.new(1, 1)
44
+ end
45
+
46
+ def self.move_cursor_column(val)
47
+ end
48
+
49
+ def self.move_cursor_up(val)
50
+ end
51
+
52
+ def self.move_cursor_down(val)
53
+ end
54
+
55
+ def self.erase_after_cursor
56
+ end
57
+
58
+ def self.scroll_down(val)
59
+ end
60
+
61
+ def self.clear_screen
62
+ end
63
+
64
+ def self.set_screen_size(rows, columns)
65
+ end
66
+
67
+ def self.set_winch_handler(&handler)
68
+ end
69
+
70
+ def self.prep
71
+ end
72
+
73
+ def self.deprep(otio)
74
+ end
75
+ end
@@ -0,0 +1,56 @@
1
+ class Reline::History < Array
2
+ def initialize(config)
3
+ @config = config
4
+ end
5
+
6
+ def to_s
7
+ 'HISTORY'
8
+ end
9
+
10
+ def delete_at(index)
11
+ index = check_index(index)
12
+ super(index)
13
+ end
14
+
15
+ def [](index)
16
+ index = check_index(index) unless index.is_a?(Range)
17
+ super(index)
18
+ end
19
+
20
+ def []=(index, val)
21
+ index = check_index(index)
22
+ super(index, String.new(val, encoding: Reline.encoding_system_needs))
23
+ end
24
+
25
+ def concat(*val)
26
+ val.each do |v|
27
+ push(*v)
28
+ end
29
+ end
30
+
31
+ def push(*val)
32
+ diff = size + val.size - @config.history_size
33
+ if diff > 0
34
+ if diff <= size
35
+ shift(diff)
36
+ else
37
+ diff -= size
38
+ clear
39
+ val.shift(diff)
40
+ end
41
+ end
42
+ super(*(val.map{ |v| String.new(v, encoding: Reline.encoding_system_needs) }))
43
+ end
44
+
45
+ def <<(val)
46
+ shift if size + 1 > @config.history_size
47
+ super(String.new(val, encoding: Reline.encoding_system_needs))
48
+ end
49
+
50
+ private def check_index(index)
51
+ index += size if index < 0
52
+ raise RangeError.new("index=<#{index}>") if index < -@config.history_size or @config.history_size < index
53
+ raise IndexError.new("index=<#{index}>") if index < 0 or size <= index
54
+ index
55
+ end
56
+ end
@@ -0,0 +1,7 @@
1
+ module Reline::KeyActor
2
+ end
3
+
4
+ require 'reline/key_actor/base'
5
+ require 'reline/key_actor/emacs'
6
+ require 'reline/key_actor/vi_command'
7
+ require 'reline/key_actor/vi_insert'
@@ -0,0 +1,7 @@
1
+ class Reline::KeyActor::Base
2
+ MAPPING = Array.new(256)
3
+
4
+ def get_method(key)
5
+ self.class::MAPPING[key]
6
+ end
7
+ end
@@ -0,0 +1,517 @@
1
+ class Reline::KeyActor::Emacs < Reline::KeyActor::Base
2
+ MAPPING = [
3
+ # 0 ^@
4
+ :em_set_mark,
5
+ # 1 ^A
6
+ :ed_move_to_beg,
7
+ # 2 ^B
8
+ :ed_prev_char,
9
+ # 3 ^C
10
+ :ed_ignore,
11
+ # 4 ^D
12
+ :em_delete,
13
+ # 5 ^E
14
+ :ed_move_to_end,
15
+ # 6 ^F
16
+ :ed_next_char,
17
+ # 7 ^G
18
+ :ed_unassigned,
19
+ # 8 ^H
20
+ :em_delete_prev_char,
21
+ # 9 ^I
22
+ :ed_unassigned,
23
+ # 10 ^J
24
+ :ed_newline,
25
+ # 11 ^K
26
+ :ed_kill_line,
27
+ # 12 ^L
28
+ :ed_clear_screen,
29
+ # 13 ^M
30
+ :ed_newline,
31
+ # 14 ^N
32
+ :ed_next_history,
33
+ # 15 ^O
34
+ :ed_ignore,
35
+ # 16 ^P
36
+ :ed_prev_history,
37
+ # 17 ^Q
38
+ :ed_quoted_insert,
39
+ # 18 ^R
40
+ :ed_search_prev_history,
41
+ # 19 ^S
42
+ :ed_search_next_history,
43
+ # 20 ^T
44
+ :ed_transpose_chars,
45
+ # 21 ^U
46
+ :em_kill_line,
47
+ # 22 ^V
48
+ :ed_quoted_insert,
49
+ # 23 ^W
50
+ :em_kill_region,
51
+ # 24 ^X
52
+ :ed_sequence_lead_in,
53
+ # 25 ^Y
54
+ :em_yank,
55
+ # 26 ^Z
56
+ :ed_ignore,
57
+ # 27 ^[
58
+ :em_meta_next,
59
+ # 28 ^\
60
+ :ed_ignore,
61
+ # 29 ^]
62
+ :ed_ignore,
63
+ # 30 ^^
64
+ :ed_unassigned,
65
+ # 31 ^_
66
+ :ed_unassigned,
67
+ # 32 SPACE
68
+ :ed_insert,
69
+ # 33 !
70
+ :ed_insert,
71
+ # 34 "
72
+ :ed_insert,
73
+ # 35 #
74
+ :ed_insert,
75
+ # 36 $
76
+ :ed_insert,
77
+ # 37 %
78
+ :ed_insert,
79
+ # 38 &
80
+ :ed_insert,
81
+ # 39 '
82
+ :ed_insert,
83
+ # 40 (
84
+ :ed_insert,
85
+ # 41 )
86
+ :ed_insert,
87
+ # 42 *
88
+ :ed_insert,
89
+ # 43 +
90
+ :ed_insert,
91
+ # 44 ,
92
+ :ed_insert,
93
+ # 45 -
94
+ :ed_insert,
95
+ # 46 .
96
+ :ed_insert,
97
+ # 47 /
98
+ :ed_insert,
99
+ # 48 0
100
+ :ed_digit,
101
+ # 49 1
102
+ :ed_digit,
103
+ # 50 2
104
+ :ed_digit,
105
+ # 51 3
106
+ :ed_digit,
107
+ # 52 4
108
+ :ed_digit,
109
+ # 53 5
110
+ :ed_digit,
111
+ # 54 6
112
+ :ed_digit,
113
+ # 55 7
114
+ :ed_digit,
115
+ # 56 8
116
+ :ed_digit,
117
+ # 57 9
118
+ :ed_digit,
119
+ # 58 :
120
+ :ed_insert,
121
+ # 59 ;
122
+ :ed_insert,
123
+ # 60 <
124
+ :ed_insert,
125
+ # 61 =
126
+ :ed_insert,
127
+ # 62 >
128
+ :ed_insert,
129
+ # 63 ?
130
+ :ed_insert,
131
+ # 64 @
132
+ :ed_insert,
133
+ # 65 A
134
+ :ed_insert,
135
+ # 66 B
136
+ :ed_insert,
137
+ # 67 C
138
+ :ed_insert,
139
+ # 68 D
140
+ :ed_insert,
141
+ # 69 E
142
+ :ed_insert,
143
+ # 70 F
144
+ :ed_insert,
145
+ # 71 G
146
+ :ed_insert,
147
+ # 72 H
148
+ :ed_insert,
149
+ # 73 I
150
+ :ed_insert,
151
+ # 74 J
152
+ :ed_insert,
153
+ # 75 K
154
+ :ed_insert,
155
+ # 76 L
156
+ :ed_insert,
157
+ # 77 M
158
+ :ed_insert,
159
+ # 78 N
160
+ :ed_insert,
161
+ # 79 O
162
+ :ed_insert,
163
+ # 80 P
164
+ :ed_insert,
165
+ # 81 Q
166
+ :ed_insert,
167
+ # 82 R
168
+ :ed_insert,
169
+ # 83 S
170
+ :ed_insert,
171
+ # 84 T
172
+ :ed_insert,
173
+ # 85 U
174
+ :ed_insert,
175
+ # 86 V
176
+ :ed_insert,
177
+ # 87 W
178
+ :ed_insert,
179
+ # 88 X
180
+ :ed_insert,
181
+ # 89 Y
182
+ :ed_insert,
183
+ # 90 Z
184
+ :ed_insert,
185
+ # 91 [
186
+ :ed_insert,
187
+ # 92 \
188
+ :ed_insert,
189
+ # 93 ]
190
+ :ed_insert,
191
+ # 94 ^
192
+ :ed_insert,
193
+ # 95 _
194
+ :ed_insert,
195
+ # 96 `
196
+ :ed_insert,
197
+ # 97 a
198
+ :ed_insert,
199
+ # 98 b
200
+ :ed_insert,
201
+ # 99 c
202
+ :ed_insert,
203
+ # 100 d
204
+ :ed_insert,
205
+ # 101 e
206
+ :ed_insert,
207
+ # 102 f
208
+ :ed_insert,
209
+ # 103 g
210
+ :ed_insert,
211
+ # 104 h
212
+ :ed_insert,
213
+ # 105 i
214
+ :ed_insert,
215
+ # 106 j
216
+ :ed_insert,
217
+ # 107 k
218
+ :ed_insert,
219
+ # 108 l
220
+ :ed_insert,
221
+ # 109 m
222
+ :ed_insert,
223
+ # 110 n
224
+ :ed_insert,
225
+ # 111 o
226
+ :ed_insert,
227
+ # 112 p
228
+ :ed_insert,
229
+ # 113 q
230
+ :ed_insert,
231
+ # 114 r
232
+ :ed_insert,
233
+ # 115 s
234
+ :ed_insert,
235
+ # 116 t
236
+ :ed_insert,
237
+ # 117 u
238
+ :ed_insert,
239
+ # 118 v
240
+ :ed_insert,
241
+ # 119 w
242
+ :ed_insert,
243
+ # 120 x
244
+ :ed_insert,
245
+ # 121 y
246
+ :ed_insert,
247
+ # 122 z
248
+ :ed_insert,
249
+ # 123 {
250
+ :ed_insert,
251
+ # 124 |
252
+ :ed_insert,
253
+ # 125 }
254
+ :ed_insert,
255
+ # 126 ~
256
+ :ed_insert,
257
+ # 127 ^?
258
+ :em_delete_prev_char,
259
+ # 128 M-^@
260
+ :ed_unassigned,
261
+ # 129 M-^A
262
+ :ed_unassigned,
263
+ # 130 M-^B
264
+ :ed_unassigned,
265
+ # 131 M-^C
266
+ :ed_unassigned,
267
+ # 132 M-^D
268
+ :ed_unassigned,
269
+ # 133 M-^E
270
+ :ed_unassigned,
271
+ # 134 M-^F
272
+ :ed_unassigned,
273
+ # 135 M-^G
274
+ :ed_unassigned,
275
+ # 136 M-^H
276
+ :ed_delete_prev_word,
277
+ # 137 M-^I
278
+ :ed_unassigned,
279
+ # 138 M-^J
280
+ :key_newline,
281
+ # 139 M-^K
282
+ :ed_unassigned,
283
+ # 140 M-^L
284
+ :ed_clear_screen,
285
+ # 141 M-^M
286
+ :key_newline,
287
+ # 142 M-^N
288
+ :ed_unassigned,
289
+ # 143 M-^O
290
+ :ed_unassigned,
291
+ # 144 M-^P
292
+ :ed_unassigned,
293
+ # 145 M-^Q
294
+ :ed_unassigned,
295
+ # 146 M-^R
296
+ :ed_unassigned,
297
+ # 147 M-^S
298
+ :ed_unassigned,
299
+ # 148 M-^T
300
+ :ed_unassigned,
301
+ # 149 M-^U
302
+ :ed_unassigned,
303
+ # 150 M-^V
304
+ :ed_unassigned,
305
+ # 151 M-^W
306
+ :ed_unassigned,
307
+ # 152 M-^X
308
+ :ed_unassigned,
309
+ # 153 M-^Y
310
+ :ed_unassigned,
311
+ # 154 M-^Z
312
+ :ed_unassigned,
313
+ # 155 M-^[
314
+ :ed_unassigned,
315
+ # 156 M-^\
316
+ :ed_unassigned,
317
+ # 157 M-^]
318
+ :ed_unassigned,
319
+ # 158 M-^^
320
+ :ed_unassigned,
321
+ # 159 M-^_
322
+ :em_copy_prev_word,
323
+ # 160 M-SPACE
324
+ :ed_unassigned,
325
+ # 161 M-!
326
+ :ed_unassigned,
327
+ # 162 M-"
328
+ :ed_unassigned,
329
+ # 163 M-#
330
+ :ed_unassigned,
331
+ # 164 M-$
332
+ :ed_unassigned,
333
+ # 165 M-%
334
+ :ed_unassigned,
335
+ # 166 M-&
336
+ :ed_unassigned,
337
+ # 167 M-'
338
+ :ed_unassigned,
339
+ # 168 M-(
340
+ :ed_unassigned,
341
+ # 169 M-)
342
+ :ed_unassigned,
343
+ # 170 M-*
344
+ :ed_unassigned,
345
+ # 171 M-+
346
+ :ed_unassigned,
347
+ # 172 M-,
348
+ :ed_unassigned,
349
+ # 173 M--
350
+ :ed_unassigned,
351
+ # 174 M-.
352
+ :ed_unassigned,
353
+ # 175 M-/
354
+ :ed_unassigned,
355
+ # 176 M-0
356
+ :ed_argument_digit,
357
+ # 177 M-1
358
+ :ed_argument_digit,
359
+ # 178 M-2
360
+ :ed_argument_digit,
361
+ # 179 M-3
362
+ :ed_argument_digit,
363
+ # 180 M-4
364
+ :ed_argument_digit,
365
+ # 181 M-5
366
+ :ed_argument_digit,
367
+ # 182 M-6
368
+ :ed_argument_digit,
369
+ # 183 M-7
370
+ :ed_argument_digit,
371
+ # 184 M-8
372
+ :ed_argument_digit,
373
+ # 185 M-9
374
+ :ed_argument_digit,
375
+ # 186 M-:
376
+ :ed_unassigned,
377
+ # 187 M-;
378
+ :ed_unassigned,
379
+ # 188 M-<
380
+ :ed_unassigned,
381
+ # 189 M-=
382
+ :ed_unassigned,
383
+ # 190 M->
384
+ :ed_unassigned,
385
+ # 191 M-?
386
+ :ed_unassigned,
387
+ # 192 M-@
388
+ :ed_unassigned,
389
+ # 193 M-A
390
+ :ed_unassigned,
391
+ # 194 M-B
392
+ :ed_prev_word,
393
+ # 195 M-C
394
+ :em_capitol_case,
395
+ # 196 M-D
396
+ :em_delete_next_word,
397
+ # 197 M-E
398
+ :ed_unassigned,
399
+ # 198 M-F
400
+ :em_next_word,
401
+ # 199 M-G
402
+ :ed_unassigned,
403
+ # 200 M-H
404
+ :ed_unassigned,
405
+ # 201 M-I
406
+ :ed_unassigned,
407
+ # 202 M-J
408
+ :ed_unassigned,
409
+ # 203 M-K
410
+ :ed_unassigned,
411
+ # 204 M-L
412
+ :em_lower_case,
413
+ # 205 M-M
414
+ :ed_unassigned,
415
+ # 206 M-N
416
+ :ed_search_next_history,
417
+ # 207 M-O
418
+ :ed_sequence_lead_in,
419
+ # 208 M-P
420
+ :ed_search_prev_history,
421
+ # 209 M-Q
422
+ :ed_unassigned,
423
+ # 210 M-R
424
+ :ed_unassigned,
425
+ # 211 M-S
426
+ :ed_unassigned,
427
+ # 212 M-T
428
+ :ed_unassigned,
429
+ # 213 M-U
430
+ :em_upper_case,
431
+ # 214 M-V
432
+ :ed_unassigned,
433
+ # 215 M-W
434
+ :em_copy_region,
435
+ # 216 M-X
436
+ :ed_command,
437
+ # 217 M-Y
438
+ :ed_unassigned,
439
+ # 218 M-Z
440
+ :ed_unassigned,
441
+ # 219 M-[
442
+ :ed_sequence_lead_in,
443
+ # 220 M-\
444
+ :ed_unassigned,
445
+ # 221 M-]
446
+ :ed_unassigned,
447
+ # 222 M-^
448
+ :ed_unassigned,
449
+ # 223 M-_
450
+ :ed_unassigned,
451
+ # 224 M-`
452
+ :ed_unassigned,
453
+ # 225 M-a
454
+ :ed_unassigned,
455
+ # 226 M-b
456
+ :ed_prev_word,
457
+ # 227 M-c
458
+ :em_capitol_case,
459
+ # 228 M-d
460
+ :em_delete_next_word,
461
+ # 229 M-e
462
+ :ed_unassigned,
463
+ # 230 M-f
464
+ :em_next_word,
465
+ # 231 M-g
466
+ :ed_unassigned,
467
+ # 232 M-h
468
+ :ed_unassigned,
469
+ # 233 M-i
470
+ :ed_unassigned,
471
+ # 234 M-j
472
+ :ed_unassigned,
473
+ # 235 M-k
474
+ :ed_unassigned,
475
+ # 236 M-l
476
+ :em_lower_case,
477
+ # 237 M-m
478
+ :ed_unassigned,
479
+ # 238 M-n
480
+ :ed_search_next_history,
481
+ # 239 M-o
482
+ :ed_unassigned,
483
+ # 240 M-p
484
+ :ed_search_prev_history,
485
+ # 241 M-q
486
+ :ed_unassigned,
487
+ # 242 M-r
488
+ :ed_unassigned,
489
+ # 243 M-s
490
+ :ed_unassigned,
491
+ # 244 M-t
492
+ :ed_transpose_words,
493
+ # 245 M-u
494
+ :em_upper_case,
495
+ # 246 M-v
496
+ :ed_unassigned,
497
+ # 247 M-w
498
+ :em_copy_region,
499
+ # 248 M-x
500
+ :ed_command,
501
+ # 249 M-y
502
+ :ed_unassigned,
503
+ # 250 M-z
504
+ :ed_unassigned,
505
+ # 251 M-{
506
+ :ed_unassigned,
507
+ # 252 M-|
508
+ :ed_unassigned,
509
+ # 253 M-}
510
+ :ed_unassigned,
511
+ # 254 M-~
512
+ :ed_unassigned,
513
+ # 255 M-^?
514
+ :ed_delete_prev_word
515
+ # EOF
516
+ ]
517
+ end