reline 0.2.8.pre.7 → 0.2.8.pre.11

Sign up to get free protection for your applications and to get access to all the features.
data/lib/reline.rb CHANGED
@@ -17,14 +17,23 @@ module Reline
17
17
  class ConfigEncodingConversionError < StandardError; end
18
18
 
19
19
  Key = Struct.new('Key', :char, :combined_char, :with_meta) do
20
- def match?(key)
21
- (key.char.nil? or char.nil? or char == key.char) and
22
- (key.combined_char.nil? or combined_char.nil? or combined_char == key.combined_char) and
23
- (key.with_meta.nil? or with_meta.nil? or with_meta == key.with_meta)
20
+ def match?(other)
21
+ case other
22
+ when Reline::Key
23
+ (other.char.nil? or char.nil? or char == other.char) and
24
+ (other.combined_char.nil? or combined_char.nil? or combined_char == other.combined_char) and
25
+ (other.with_meta.nil? or with_meta.nil? or with_meta == other.with_meta)
26
+ when Integer, Symbol
27
+ (combined_char and combined_char == other) or
28
+ (combined_char.nil? and char and char == other)
29
+ else
30
+ false
31
+ end
24
32
  end
33
+ alias_method :==, :match?
25
34
  end
26
35
  CursorPos = Struct.new(:x, :y)
27
- DialogRenderInfo = Struct.new(:pos, :contents, :pointer, :bg_color, :width, :height, keyword_init: true)
36
+ DialogRenderInfo = Struct.new(:pos, :contents, :bg_color, :width, :height, :scrollbar, keyword_init: true)
28
37
 
29
38
  class Core
30
39
  ATTR_READER_NAMES = %i(
@@ -201,7 +210,7 @@ module Reline
201
210
  return nil
202
211
  end
203
212
  pre, target, post = retrieve_completion_block(true)
204
- if target.nil? or target.empty? or target.size <= 3
213
+ if target.nil? or target.empty? or (completion_journey_data&.pointer == -1 and target.size <= 3)
205
214
  return nil
206
215
  end
207
216
  if completion_journey_data and completion_journey_data.list
@@ -228,7 +237,8 @@ module Reline
228
237
  context.clear
229
238
  context.push(cursor_pos_to_render, result, pointer, dialog)
230
239
  end
231
- DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, pointer: pointer, height: 15)
240
+ dialog.pointer = pointer
241
+ DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, scrollbar: true, height: 15)
232
242
  }
233
243
  Reline::DEFAULT_DIALOG_CONTEXT = Array.new
234
244
 
@@ -368,25 +378,9 @@ module Reline
368
378
  break
369
379
  when :matching
370
380
  if buffer.size == 1
371
- begin
372
- succ_c = nil
373
- Timeout.timeout(keyseq_timeout / 1000.0) {
374
- succ_c = Reline::IOGate.getc
375
- }
376
- rescue Timeout::Error # cancel matching only when first byte
377
- block.([Reline::Key.new(c, c, false)])
378
- break
379
- else
380
- if key_stroke.match_status(buffer.dup.push(succ_c)) == :unmatched
381
- if c == "\e".ord
382
- block.([Reline::Key.new(succ_c, succ_c | 0b10000000, true)])
383
- else
384
- block.([Reline::Key.new(c, c, false), Reline::Key.new(succ_c, succ_c, false)])
385
- end
386
- break
387
- else
388
- Reline::IOGate.ungetc(succ_c)
389
- end
381
+ case read_2nd_character_of_key_sequence(keyseq_timeout, buffer, c, block)
382
+ when :break then break
383
+ when :next then next
390
384
  end
391
385
  end
392
386
  when :unmatched
@@ -403,6 +397,38 @@ module Reline
403
397
  end
404
398
  end
405
399
 
400
+ private def read_2nd_character_of_key_sequence(keyseq_timeout, buffer, c, block)
401
+ begin
402
+ succ_c = nil
403
+ Timeout.timeout(keyseq_timeout / 1000.0) {
404
+ succ_c = Reline::IOGate.getc
405
+ }
406
+ rescue Timeout::Error # cancel matching only when first byte
407
+ block.([Reline::Key.new(c, c, false)])
408
+ return :break
409
+ else
410
+ case key_stroke.match_status(buffer.dup.push(succ_c))
411
+ when :unmatched
412
+ if c == "\e".ord
413
+ block.([Reline::Key.new(succ_c, succ_c | 0b10000000, true)])
414
+ else
415
+ block.([Reline::Key.new(c, c, false), Reline::Key.new(succ_c, succ_c, false)])
416
+ end
417
+ return :break
418
+ when :matching
419
+ Reline::IOGate.ungetc(succ_c)
420
+ return :next
421
+ when :matched
422
+ buffer << succ_c
423
+ expanded = key_stroke.expand(buffer).map{ |expanded_c|
424
+ Reline::Key.new(expanded_c, expanded_c, false)
425
+ }
426
+ block.(expanded)
427
+ return :break
428
+ end
429
+ end
430
+ end
431
+
406
432
  private def read_escaped_key(keyseq_timeout, c, block)
407
433
  begin
408
434
  escaped_c = nil
@@ -454,7 +480,7 @@ module Reline
454
480
  #--------------------------------------------------------
455
481
 
456
482
  (Core::ATTR_READER_NAMES).each { |name|
457
- def_single_delegators :core, "#{name}", "#{name}="
483
+ def_single_delegators :core, :"#{name}", :"#{name}="
458
484
  }
459
485
  def_single_delegators :core, :input=, :output=
460
486
  def_single_delegators :core, :vi_editing_mode, :emacs_editing_mode
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8.pre.7
4
+ version: 0.2.8.pre.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-03 00:00:00.000000000 Z
11
+ date: 2021-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: io-console
@@ -47,7 +47,6 @@ files:
47
47
  - lib/reline/key_stroke.rb
48
48
  - lib/reline/kill_ring.rb
49
49
  - lib/reline/line_editor.rb
50
- - lib/reline/line_editor.rb.orig
51
50
  - lib/reline/sibori.rb
52
51
  - lib/reline/terminfo.rb
53
52
  - lib/reline/unicode.rb
@@ -74,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
73
  - !ruby/object:Gem::Version
75
74
  version: 1.3.1
76
75
  requirements: []
77
- rubygems_version: 3.2.22
76
+ rubygems_version: 3.1.6
78
77
  signing_key:
79
78
  specification_version: 4
80
79
  summary: Alternative GNU Readline or Editline implementation by pure Ruby.