reline 0.3.7 → 0.3.8

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
  SHA256:
3
- metadata.gz: 67ad796ede485308abba9038bb03672537e8cba1409ef61e921d165db277846d
4
- data.tar.gz: 9692f5e08f6ed30722262d70c89e413b4f7d7651f98698d6253f720aea600125
3
+ metadata.gz: 709b8943f16732f771d45da031e9676dc01c8b75f0410134a8b1fa8ab590d294
4
+ data.tar.gz: 04aa52c6ea6a8939402a1554b42bce891bd65a13be6b76cbfd3f4859df1455d4
5
5
  SHA512:
6
- metadata.gz: 4d69f27ac94aecc2f9628e824d4ded200cf0e0e1939b00d28db99b30f5b21baed78bba0edc7ab68105af327803c0e5f8f03853fb629079ae9017be6016bff0d7
7
- data.tar.gz: 62af3574af7223c038e3b078708b116af92bcecf1ec9301e32f8653c008fdfea082253f9308aa99067f60aa9c98deecb5382552deee6847966f4e4ceb387f8f3
6
+ metadata.gz: ab8a124f732cfa4b8522f397a546fc89ea93f188ca9f44f7f560ea2afb00abbe3b95486c17a20b826d360a8bb064ca441bd357acffe1eb4ec371fbf6380cd37d
7
+ data.tar.gz: e756e58d4ae8929045998b8278fcee48ba1867741cc4d47bd72beb3e3a74902938d4c8a9dcd4c0452f20b25f5b4fe05eb96929bc39c28f326dc88c9bdf7be458
data/lib/reline/ansi.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'io/console'
2
2
  require 'io/wait'
3
- require 'timeout'
4
3
  require_relative 'terminfo'
5
4
 
6
5
  class Reline::ANSI
@@ -154,11 +153,13 @@ class Reline::ANSI
154
153
  end
155
154
 
156
155
  @@buf = []
157
- def self.inner_getc
156
+ def self.inner_getc(timeout_second)
158
157
  unless @@buf.empty?
159
158
  return @@buf.shift
160
159
  end
161
160
  until c = @@input.raw(intr: true) { @@input.wait_readable(0.1) && @@input.getbyte }
161
+ timeout_second -= 0.1
162
+ return nil if timeout_second <= 0
162
163
  Reline.core.line_editor.resize
163
164
  end
164
165
  (c == 0x16 && @@input.raw(min: 0, time: 0, &:getbyte)) || c
@@ -172,40 +173,38 @@ class Reline::ANSI
172
173
  @@in_bracketed_paste_mode = false
173
174
  START_BRACKETED_PASTE = String.new("\e[200~,", encoding: Encoding::ASCII_8BIT)
174
175
  END_BRACKETED_PASTE = String.new("\e[200~.", encoding: Encoding::ASCII_8BIT)
175
- def self.getc_with_bracketed_paste
176
+ def self.getc_with_bracketed_paste(timeout_second)
176
177
  buffer = String.new(encoding: Encoding::ASCII_8BIT)
177
- buffer << inner_getc
178
+ buffer << inner_getc(timeout_second)
178
179
  while START_BRACKETED_PASTE.start_with?(buffer) or END_BRACKETED_PASTE.start_with?(buffer) do
179
180
  if START_BRACKETED_PASTE == buffer
180
181
  @@in_bracketed_paste_mode = true
181
- return inner_getc
182
+ return inner_getc(timeout_second)
182
183
  elsif END_BRACKETED_PASTE == buffer
183
184
  @@in_bracketed_paste_mode = false
184
185
  ungetc(-1)
185
- return inner_getc
186
+ return inner_getc(timeout_second)
186
187
  end
187
- begin
188
- succ_c = nil
189
- Timeout.timeout(Reline.core.config.keyseq_timeout * 100) {
190
- succ_c = inner_getc
191
- }
192
- rescue Timeout::Error
193
- break
194
- else
188
+ succ_c = inner_getc(Reline.core.config.keyseq_timeout)
189
+
190
+ if succ_c
195
191
  buffer << succ_c
192
+ else
193
+ break
196
194
  end
197
195
  end
198
196
  buffer.bytes.reverse_each do |ch|
199
197
  ungetc ch
200
198
  end
201
- inner_getc
199
+ inner_getc(timeout_second)
202
200
  end
203
201
 
204
- def self.getc
202
+ # if the usage expects to wait indefinitely, use Float::INFINITY for timeout_second
203
+ def self.getc(timeout_second)
205
204
  if Reline.core.config.enable_bracketed_paste
206
- getc_with_bracketed_paste
205
+ getc_with_bracketed_paste(timeout_second)
207
206
  else
208
- inner_getc
207
+ inner_getc(timeout_second)
209
208
  end
210
209
  end
211
210
 
@@ -1,4 +1,3 @@
1
- require 'timeout'
2
1
  require 'io/wait'
3
2
 
4
3
  class Reline::GeneralIO
@@ -35,7 +34,7 @@ class Reline::GeneralIO
35
34
  yield
36
35
  end
37
36
 
38
- def self.getc
37
+ def self.getc(_timeout_second)
39
38
  unless @@buf.empty?
40
39
  return @@buf.shift
41
40
  end
@@ -2696,6 +2696,7 @@ class Reline::LineEditor
2696
2696
  @cursor_max -= width
2697
2697
  end
2698
2698
  end
2699
+ alias_method :kill_word, :em_delete_next_word
2699
2700
 
2700
2701
  private def ed_delete_prev_word(key)
2701
2702
  if @byte_pointer > 0
@@ -2707,6 +2708,7 @@ class Reline::LineEditor
2707
2708
  @cursor_max -= width
2708
2709
  end
2709
2710
  end
2711
+ alias_method :backward_kill_word, :ed_delete_prev_word
2710
2712
 
2711
2713
  private def ed_transpose_chars(key)
2712
2714
  if @byte_pointer > 0
@@ -1,3 +1,3 @@
1
1
  module Reline
2
- VERSION = '0.3.7'
2
+ VERSION = '0.3.8'
3
3
  end
@@ -295,7 +295,7 @@ class Reline::Windows
295
295
  yield
296
296
  end
297
297
 
298
- def self.getc
298
+ def self.getc(_timeout_second)
299
299
  check_input_event
300
300
  @@output_buf.shift
301
301
  end
data/lib/reline.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'io/console'
2
- require 'timeout'
3
2
  require 'forwardable'
4
3
  require 'reline/version'
5
4
  require 'reline/config'
@@ -397,7 +396,7 @@ module Reline
397
396
  private def read_io(keyseq_timeout, &block)
398
397
  buffer = []
399
398
  loop do
400
- c = io_gate.getc
399
+ c = io_gate.getc(Float::INFINITY)
401
400
  if c == -1
402
401
  result = :unmatched
403
402
  @bracketed_paste_finished = true
@@ -434,15 +433,8 @@ module Reline
434
433
  end
435
434
 
436
435
  private def read_2nd_character_of_key_sequence(keyseq_timeout, buffer, c, block)
437
- begin
438
- succ_c = nil
439
- Timeout.timeout(keyseq_timeout / 1000.0) {
440
- succ_c = io_gate.getc
441
- }
442
- rescue Timeout::Error # cancel matching only when first byte
443
- block.([Reline::Key.new(c, c, false)])
444
- return :break
445
- else
436
+ succ_c = io_gate.getc(keyseq_timeout.fdiv(1000))
437
+ if succ_c
446
438
  case key_stroke.match_status(buffer.dup.push(succ_c))
447
439
  when :unmatched
448
440
  if c == "\e".ord
@@ -462,27 +454,23 @@ module Reline
462
454
  block.(expanded)
463
455
  return :break
464
456
  end
457
+ else
458
+ block.([Reline::Key.new(c, c, false)])
459
+ return :break
465
460
  end
466
461
  end
467
462
 
468
463
  private def read_escaped_key(keyseq_timeout, c, block)
469
- begin
470
- escaped_c = nil
471
- Timeout.timeout(keyseq_timeout / 1000.0) {
472
- escaped_c = io_gate.getc
473
- }
474
- rescue Timeout::Error # independent ESC
464
+ escaped_c = io_gate.getc(keyseq_timeout.fdiv(1000))
465
+
466
+ if escaped_c.nil?
475
467
  block.([Reline::Key.new(c, c, false)])
468
+ elsif escaped_c >= 128 # maybe, first byte of multi byte
469
+ block.([Reline::Key.new(c, c, false), Reline::Key.new(escaped_c, escaped_c, false)])
470
+ elsif escaped_c == "\e".ord # escape twice
471
+ block.([Reline::Key.new(c, c, false), Reline::Key.new(c, c, false)])
476
472
  else
477
- if escaped_c.nil?
478
- block.([Reline::Key.new(c, c, false)])
479
- elsif escaped_c >= 128 # maybe, first byte of multi byte
480
- block.([Reline::Key.new(c, c, false), Reline::Key.new(escaped_c, escaped_c, false)])
481
- elsif escaped_c == "\e".ord # escape twice
482
- block.([Reline::Key.new(c, c, false), Reline::Key.new(c, c, false)])
483
- else
484
- block.([Reline::Key.new(escaped_c, escaped_c | 0b10000000, true)])
485
- end
473
+ block.([Reline::Key.new(escaped_c, escaped_c | 0b10000000, true)])
486
474
  end
487
475
  end
488
476
 
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.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-27 00:00:00.000000000 Z
11
+ date: 2023-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: io-console
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  requirements: []
75
- rubygems_version: 3.4.13
75
+ rubygems_version: 3.4.10
76
76
  signing_key:
77
77
  specification_version: 4
78
78
  summary: Alternative GNU Readline or Editline implementation by pure Ruby.