reline 0.2.8.pre.4 → 0.2.8.pre.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/reline/config.rb +16 -2
- data/lib/reline/general_io.rb +1 -0
- data/lib/reline/key_stroke.rb +56 -4
- data/lib/reline/line_editor.rb +157 -76
- data/lib/reline/line_editor.rb.orig +3199 -0
- data/lib/reline/unicode.rb +9 -8
- data/lib/reline/version.rb +1 -1
- data/lib/reline/windows.rb +2 -0
- data/lib/reline.rb +60 -25
- metadata +3 -2
data/lib/reline/unicode.rb
CHANGED
@@ -101,9 +101,9 @@ class Reline::Unicode
|
|
101
101
|
|
102
102
|
def self.get_mbchar_width(mbchar)
|
103
103
|
ord = mbchar.ord
|
104
|
-
if (0x00 <= ord and ord <= 0x1F)
|
104
|
+
if (0x00 <= ord and ord <= 0x1F) # in EscapedPairs
|
105
105
|
return 2
|
106
|
-
elsif (0x20 <= ord and ord <= 0x7E)
|
106
|
+
elsif (0x20 <= ord and ord <= 0x7E) # printable ASCII chars
|
107
107
|
return 1
|
108
108
|
end
|
109
109
|
m = mbchar.encode(Encoding::UTF_8).match(MBCharWidthRE)
|
@@ -185,10 +185,10 @@ class Reline::Unicode
|
|
185
185
|
[lines, height]
|
186
186
|
end
|
187
187
|
|
188
|
-
# Take a chunk of a String with escape sequences.
|
189
|
-
def self.take_range(str,
|
188
|
+
# Take a chunk of a String cut by width with escape sequences.
|
189
|
+
def self.take_range(str, start_col, max_width, encoding = str.encoding)
|
190
190
|
chunk = String.new(encoding: encoding)
|
191
|
-
|
191
|
+
total_width = 0
|
192
192
|
rest = str.encode(Encoding::UTF_8)
|
193
193
|
in_zero_width = false
|
194
194
|
rest.scan(WIDTH_SCANNER) do |gc|
|
@@ -206,9 +206,10 @@ class Reline::Unicode
|
|
206
206
|
if in_zero_width
|
207
207
|
chunk << gc
|
208
208
|
else
|
209
|
-
|
210
|
-
|
211
|
-
|
209
|
+
mbchar_width = get_mbchar_width(gc)
|
210
|
+
total_width += mbchar_width
|
211
|
+
break if (start_col + max_width) < total_width
|
212
|
+
chunk << gc if start_col < total_width
|
212
213
|
end
|
213
214
|
end
|
214
215
|
end
|
data/lib/reline/version.rb
CHANGED
data/lib/reline/windows.rb
CHANGED
data/lib/reline.rb
CHANGED
@@ -16,9 +16,28 @@ module Reline
|
|
16
16
|
|
17
17
|
class ConfigEncodingConversionError < StandardError; end
|
18
18
|
|
19
|
-
Key = Struct.new('Key', :char, :combined_char, :with_meta)
|
19
|
+
Key = Struct.new('Key', :char, :combined_char, :with_meta) do
|
20
|
+
def match?(key)
|
21
|
+
if key.instance_of?(Reline::Key)
|
22
|
+
(key.char.nil? or char.nil? or char == key.char) and
|
23
|
+
(key.combined_char.nil? or combined_char.nil? or combined_char == key.combined_char) and
|
24
|
+
(key.with_meta.nil? or with_meta.nil? or with_meta == key.with_meta)
|
25
|
+
elsif key.is_a?(Integer) or key.is_a?(Symbol)
|
26
|
+
if not combined_char.nil? and combined_char == key
|
27
|
+
true
|
28
|
+
elsif combined_char.nil? and not char.nil? and char == key
|
29
|
+
true
|
30
|
+
else
|
31
|
+
false
|
32
|
+
end
|
33
|
+
else
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
alias_method :==, :match?
|
38
|
+
end
|
20
39
|
CursorPos = Struct.new(:x, :y)
|
21
|
-
DialogRenderInfo = Struct.new(:pos, :contents, :pointer, :bg_color, :height, keyword_init: true)
|
40
|
+
DialogRenderInfo = Struct.new(:pos, :contents, :pointer, :bg_color, :width, :height, :scrollbar, keyword_init: true)
|
22
41
|
|
23
42
|
class Core
|
24
43
|
ATTR_READER_NAMES = %i(
|
@@ -194,8 +213,8 @@ module Reline
|
|
194
213
|
# Auto complete starts only when edited
|
195
214
|
return nil
|
196
215
|
end
|
197
|
-
pre, target, post= retrieve_completion_block(true)
|
198
|
-
if target.nil? or target.empty
|
216
|
+
pre, target, post = retrieve_completion_block(true)
|
217
|
+
if target.nil? or target.empty? or target.size <= 3
|
199
218
|
return nil
|
200
219
|
end
|
201
220
|
if completion_journey_data and completion_journey_data.list
|
@@ -206,7 +225,7 @@ module Reline
|
|
206
225
|
result = call_completion_proc_with_checking_args(pre, target, post)
|
207
226
|
pointer = nil
|
208
227
|
end
|
209
|
-
if result and result.size == 1 and result[0] == target
|
228
|
+
if result and result.size == 1 and result[0] == target and pointer != 0
|
210
229
|
result = nil
|
211
230
|
end
|
212
231
|
target_width = Reline::Unicode.calculate_width(target)
|
@@ -222,7 +241,7 @@ module Reline
|
|
222
241
|
context.clear
|
223
242
|
context.push(cursor_pos_to_render, result, pointer, dialog)
|
224
243
|
end
|
225
|
-
DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, pointer: pointer, height: 15)
|
244
|
+
DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, pointer: pointer, scrollbar: true, height: 15)
|
226
245
|
}
|
227
246
|
Reline::DEFAULT_DIALOG_CONTEXT = Array.new
|
228
247
|
|
@@ -362,25 +381,9 @@ module Reline
|
|
362
381
|
break
|
363
382
|
when :matching
|
364
383
|
if buffer.size == 1
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
succ_c = Reline::IOGate.getc
|
369
|
-
}
|
370
|
-
rescue Timeout::Error # cancel matching only when first byte
|
371
|
-
block.([Reline::Key.new(c, c, false)])
|
372
|
-
break
|
373
|
-
else
|
374
|
-
if key_stroke.match_status(buffer.dup.push(succ_c)) == :unmatched
|
375
|
-
if c == "\e".ord
|
376
|
-
block.([Reline::Key.new(succ_c, succ_c | 0b10000000, true)])
|
377
|
-
else
|
378
|
-
block.([Reline::Key.new(c, c, false), Reline::Key.new(succ_c, succ_c, false)])
|
379
|
-
end
|
380
|
-
break
|
381
|
-
else
|
382
|
-
Reline::IOGate.ungetc(succ_c)
|
383
|
-
end
|
384
|
+
case read_2nd_character_of_key_sequence(keyseq_timeout, buffer, c, block)
|
385
|
+
when :break then break
|
386
|
+
when :next then next
|
384
387
|
end
|
385
388
|
end
|
386
389
|
when :unmatched
|
@@ -397,6 +400,38 @@ module Reline
|
|
397
400
|
end
|
398
401
|
end
|
399
402
|
|
403
|
+
private def read_2nd_character_of_key_sequence(keyseq_timeout, buffer, c, block)
|
404
|
+
begin
|
405
|
+
succ_c = nil
|
406
|
+
Timeout.timeout(keyseq_timeout / 1000.0) {
|
407
|
+
succ_c = Reline::IOGate.getc
|
408
|
+
}
|
409
|
+
rescue Timeout::Error # cancel matching only when first byte
|
410
|
+
block.([Reline::Key.new(c, c, false)])
|
411
|
+
return :break
|
412
|
+
else
|
413
|
+
case key_stroke.match_status(buffer.dup.push(succ_c))
|
414
|
+
when :unmatched
|
415
|
+
if c == "\e".ord
|
416
|
+
block.([Reline::Key.new(succ_c, succ_c | 0b10000000, true)])
|
417
|
+
else
|
418
|
+
block.([Reline::Key.new(c, c, false), Reline::Key.new(succ_c, succ_c, false)])
|
419
|
+
end
|
420
|
+
return :break
|
421
|
+
when :matching
|
422
|
+
Reline::IOGate.ungetc(succ_c)
|
423
|
+
return :next
|
424
|
+
when :matched
|
425
|
+
buffer << succ_c
|
426
|
+
expanded = key_stroke.expand(buffer).map{ |expanded_c|
|
427
|
+
Reline::Key.new(expanded_c, expanded_c, false)
|
428
|
+
}
|
429
|
+
block.(expanded)
|
430
|
+
return :break
|
431
|
+
end
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
400
435
|
private def read_escaped_key(keyseq_timeout, c, block)
|
401
436
|
begin
|
402
437
|
escaped_c = nil
|
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.
|
4
|
+
version: 0.2.8.pre.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aycabta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: io-console
|
@@ -47,6 +47,7 @@ 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
|
50
51
|
- lib/reline/sibori.rb
|
51
52
|
- lib/reline/terminfo.rb
|
52
53
|
- lib/reline/unicode.rb
|