reline 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reline.rb +13 -5
- data/lib/reline/ansi.rb +2 -0
- data/lib/reline/key_stroke.rb +1 -1
- data/lib/reline/line_editor.rb +43 -24
- data/lib/reline/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05acbc99c317aaa7f46d205bf73a13cc482bcfba9f6f05562f189f91082b4fd7
|
4
|
+
data.tar.gz: d785c8da605eba1b1440110ccbf197b1c5c654cce78dd18b17192e6686aa62f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d964d8b085973dd17da51e8359c93377c5356b01db720258b3a0a27c3b03b34e77c099d290f2f2fa41d2f8f6da1dd5cdcdcca4f7a18e1bbb199e9a755f6caca
|
7
|
+
data.tar.gz: 8c93e1e261d29ff6e27f0544bf6ddfe3eb41ac573111c59cc68869f508363a109880909c2893ebdc9b281b50d78fe795925667f63a7b4e5e1e26a91f93019adf
|
data/lib/reline.rb
CHANGED
@@ -166,7 +166,7 @@ module Reline
|
|
166
166
|
inner_readline(prompt, add_hist, true, &confirm_multiline_termination)
|
167
167
|
|
168
168
|
whole_buffer = line_editor.whole_buffer.dup
|
169
|
-
whole_buffer.taint
|
169
|
+
whole_buffer.taint if RUBY_VERSION < '2.7'
|
170
170
|
if add_hist and whole_buffer and whole_buffer.chomp.size > 0
|
171
171
|
Reline::HISTORY << whole_buffer
|
172
172
|
end
|
@@ -179,7 +179,7 @@ module Reline
|
|
179
179
|
inner_readline(prompt, add_hist, false)
|
180
180
|
|
181
181
|
line = line_editor.line.dup
|
182
|
-
line.taint
|
182
|
+
line.taint if RUBY_VERSION < '2.7'
|
183
183
|
if add_hist and line and line.chomp.size > 0
|
184
184
|
Reline::HISTORY << line.chomp
|
185
185
|
end
|
@@ -260,7 +260,10 @@ module Reline
|
|
260
260
|
result = key_stroke.match_status(buffer)
|
261
261
|
case result
|
262
262
|
when :matched
|
263
|
-
|
263
|
+
expanded = key_stroke.expand(buffer).map{ |expanded_c|
|
264
|
+
Reline::Key.new(expanded_c, expanded_c, false)
|
265
|
+
}
|
266
|
+
block.(expanded)
|
264
267
|
break
|
265
268
|
when :matching
|
266
269
|
if buffer.size == 1
|
@@ -289,7 +292,10 @@ module Reline
|
|
289
292
|
if buffer.size == 1 and c == "\e".ord
|
290
293
|
read_escaped_key(keyseq_timeout, c, block)
|
291
294
|
else
|
292
|
-
|
295
|
+
expanded = buffer.map{ |expanded_c|
|
296
|
+
Reline::Key.new(expanded_c, expanded_c, false)
|
297
|
+
}
|
298
|
+
block.(expanded)
|
293
299
|
end
|
294
300
|
break
|
295
301
|
end
|
@@ -319,7 +325,7 @@ module Reline
|
|
319
325
|
|
320
326
|
private def may_req_ambiguous_char_width
|
321
327
|
@ambiguous_width = 2 if Reline::IOGate == Reline::GeneralIO or STDOUT.is_a?(File)
|
322
|
-
return if
|
328
|
+
return if ambiguous_width
|
323
329
|
Reline::IOGate.move_cursor_column(0)
|
324
330
|
print "\u{25bd}"
|
325
331
|
@ambiguous_width = Reline::IOGate.cursor_pos.x
|
@@ -342,6 +348,7 @@ module Reline
|
|
342
348
|
def_single_delegators :core, :vi_editing_mode, :emacs_editing_mode
|
343
349
|
def_single_delegators :core, :readline
|
344
350
|
def_instance_delegators self, :readline
|
351
|
+
private :readline
|
345
352
|
|
346
353
|
|
347
354
|
#--------------------------------------------------------
|
@@ -369,6 +376,7 @@ module Reline
|
|
369
376
|
|
370
377
|
def_single_delegators :core, :readmultiline
|
371
378
|
def_instance_delegators self, :readmultiline
|
379
|
+
private :readmultiline
|
372
380
|
|
373
381
|
def self.core
|
374
382
|
@core ||= Core.new { |core|
|
data/lib/reline/ansi.rb
CHANGED
@@ -7,6 +7,8 @@ class Reline::ANSI
|
|
7
7
|
[27, 91, 51, 126] => :key_delete, # Del
|
8
8
|
[27, 91, 49, 126] => :ed_move_to_beg, # Home
|
9
9
|
[27, 91, 52, 126] => :ed_move_to_end, # End
|
10
|
+
[27, 32] => :em_set_mark, # M-<space>
|
11
|
+
[24, 24] => :em_exchange_mark, # C-x C-x TODO also add Windows
|
10
12
|
}
|
11
13
|
|
12
14
|
@@input = STDIN
|
data/lib/reline/key_stroke.rb
CHANGED
@@ -32,7 +32,7 @@ class Reline::KeyStroke
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def expand(input)
|
35
|
-
lhs = key_mapping.keys.select { |
|
35
|
+
lhs = key_mapping.keys.select { |item| input.start_with? item }.sort_by(&:size).reverse.first
|
36
36
|
return input unless lhs
|
37
37
|
rhs = key_mapping[lhs]
|
38
38
|
|
data/lib/reline/line_editor.rb
CHANGED
@@ -113,9 +113,7 @@ class Reline::LineEditor
|
|
113
113
|
if @line_index.zero?
|
114
114
|
0
|
115
115
|
else
|
116
|
-
@buffer_of_lines[0..(@line_index - 1)]
|
117
|
-
result + calculate_height_by_width(prompt_width + calculate_width(line)) # TODO prompt_list
|
118
|
-
}
|
116
|
+
calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list)
|
119
117
|
end
|
120
118
|
if @prompt_proc
|
121
119
|
prompt = prompt_list[@line_index]
|
@@ -140,6 +138,7 @@ class Reline::LineEditor
|
|
140
138
|
|
141
139
|
def reset_variables(prompt = '', encoding = Encoding.default_external)
|
142
140
|
@prompt = prompt
|
141
|
+
@mark_pointer = nil
|
143
142
|
@encoding = encoding
|
144
143
|
@is_multiline = false
|
145
144
|
@finished = false
|
@@ -188,6 +187,16 @@ class Reline::LineEditor
|
|
188
187
|
@is_multiline = false
|
189
188
|
end
|
190
189
|
|
190
|
+
private def calculate_height_by_lines(lines, prompt_list)
|
191
|
+
result = 0
|
192
|
+
lines.each_with_index { |line, i|
|
193
|
+
prompt = ''
|
194
|
+
prompt = prompt_list[i] if prompt_list and prompt_list[i]
|
195
|
+
result += calculate_height_by_width(calculate_width(prompt + line))
|
196
|
+
}
|
197
|
+
result
|
198
|
+
end
|
199
|
+
|
191
200
|
private def insert_new_line(cursor_line, next_line)
|
192
201
|
@line = cursor_line
|
193
202
|
@buffer_of_lines.insert(@line_index + 1, String.new(next_line, encoding: @encoding))
|
@@ -346,9 +355,7 @@ class Reline::LineEditor
|
|
346
355
|
new_lines = whole_lines
|
347
356
|
end
|
348
357
|
prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines, prompt)
|
349
|
-
all_height = new_lines
|
350
|
-
result + calculate_height_by_width(prompt_width + calculate_width(line)) # TODO prompt_list
|
351
|
-
}
|
358
|
+
all_height = calculate_height_by_lines(new_lines, prompt_list)
|
352
359
|
diff = all_height - @highest_in_all
|
353
360
|
move_cursor_down(@highest_in_all - @first_line_started_from - @started_from - 1)
|
354
361
|
if diff > 0
|
@@ -388,9 +395,7 @@ class Reline::LineEditor
|
|
388
395
|
if @line_index.zero?
|
389
396
|
0
|
390
397
|
else
|
391
|
-
@buffer_of_lines[0..(@line_index - 1)]
|
392
|
-
result + calculate_height_by_width(prompt_width + calculate_width(line)) # TODO prompt_list
|
393
|
-
}
|
398
|
+
calculate_height_by_lines(@buffer_of_lines[0..(@line_index - 1)], prompt_list)
|
394
399
|
end
|
395
400
|
if @prompt_proc
|
396
401
|
prompt = prompt_list[@line_index]
|
@@ -449,9 +454,7 @@ class Reline::LineEditor
|
|
449
454
|
if @line_index.zero?
|
450
455
|
0
|
451
456
|
else
|
452
|
-
new_buffer[0..(@line_index - 1)]
|
453
|
-
result + calculate_height_by_width(prompt_width + calculate_width(line)) # TODO prompt_list
|
454
|
-
}
|
457
|
+
calculate_height_by_lines(new_buffer[0..(@line_index - 1)], prompt_list)
|
455
458
|
end
|
456
459
|
@started_from = calculate_height_by_width(prompt_width + @cursor) - 1
|
457
460
|
move_cursor_down(@first_line_started_from + @started_from)
|
@@ -650,9 +653,9 @@ class Reline::LineEditor
|
|
650
653
|
else
|
651
654
|
old_waiting_proc = @waiting_proc
|
652
655
|
old_waiting_operator_proc = @waiting_operator_proc
|
653
|
-
@waiting_proc = proc { |
|
656
|
+
@waiting_proc = proc { |k|
|
654
657
|
old_cursor, old_byte_pointer = @cursor, @byte_pointer
|
655
|
-
old_waiting_proc.(
|
658
|
+
old_waiting_proc.(k)
|
656
659
|
cursor_diff, byte_pointer_diff = @cursor - old_cursor, @byte_pointer - old_byte_pointer
|
657
660
|
@cursor, @byte_pointer = old_cursor, old_byte_pointer
|
658
661
|
@waiting_operator_proc.(cursor_diff, byte_pointer_diff)
|
@@ -994,8 +997,8 @@ class Reline::LineEditor
|
|
994
997
|
end
|
995
998
|
width
|
996
999
|
else
|
997
|
-
str.encode(Encoding::UTF_8).grapheme_clusters.inject(0) { |
|
998
|
-
|
1000
|
+
str.encode(Encoding::UTF_8).grapheme_clusters.inject(0) { |w, gc|
|
1001
|
+
w + Reline::Unicode.get_mbchar_width(gc)
|
999
1002
|
}
|
1000
1003
|
end
|
1001
1004
|
end
|
@@ -1185,8 +1188,8 @@ class Reline::LineEditor
|
|
1185
1188
|
end
|
1186
1189
|
searcher.resume
|
1187
1190
|
@searching_prompt = "(reverse-i-search)`': "
|
1188
|
-
@waiting_proc = ->(
|
1189
|
-
case
|
1191
|
+
@waiting_proc = ->(k) {
|
1192
|
+
case k
|
1190
1193
|
when "\C-j".ord, "\C-?".ord
|
1191
1194
|
if @history_pointer
|
1192
1195
|
@line = Reline::HISTORY[@history_pointer]
|
@@ -1206,9 +1209,9 @@ class Reline::LineEditor
|
|
1206
1209
|
@cursor_max = calculate_width(@line)
|
1207
1210
|
@cursor = @byte_pointer = 0
|
1208
1211
|
else
|
1209
|
-
chr =
|
1210
|
-
if chr.match?(/[[:print:]]/) or
|
1211
|
-
searcher.resume(
|
1212
|
+
chr = k.is_a?(String) ? k : k.chr(Encoding::ASCII_8BIT)
|
1213
|
+
if chr.match?(/[[:print:]]/) or k == "\C-h".ord or k == 127
|
1214
|
+
searcher.resume(k)
|
1212
1215
|
else
|
1213
1216
|
if @history_pointer
|
1214
1217
|
line = Reline::HISTORY[@history_pointer]
|
@@ -1861,13 +1864,13 @@ class Reline::LineEditor
|
|
1861
1864
|
end
|
1862
1865
|
|
1863
1866
|
private def vi_replace_char(key, arg: 1)
|
1864
|
-
@waiting_proc = ->(
|
1867
|
+
@waiting_proc = ->(k) {
|
1865
1868
|
if arg == 1
|
1866
1869
|
byte_size = Reline::Unicode.get_next_mbchar_size(@line, @byte_pointer)
|
1867
1870
|
before = @line.byteslice(0, @byte_pointer)
|
1868
1871
|
remaining_point = @byte_pointer + byte_size
|
1869
1872
|
after = @line.byteslice(remaining_point, @line.size - remaining_point)
|
1870
|
-
@line = before +
|
1873
|
+
@line = before + k.chr + after
|
1871
1874
|
@cursor_max = calculate_width(@line)
|
1872
1875
|
@waiting_proc = nil
|
1873
1876
|
elsif arg > 1
|
@@ -1878,7 +1881,7 @@ class Reline::LineEditor
|
|
1878
1881
|
before = @line.byteslice(0, @byte_pointer)
|
1879
1882
|
remaining_point = @byte_pointer + byte_size
|
1880
1883
|
after = @line.byteslice(remaining_point, @line.size - remaining_point)
|
1881
|
-
replaced =
|
1884
|
+
replaced = k.chr * arg
|
1882
1885
|
@line = before + replaced + after
|
1883
1886
|
@byte_pointer += replaced.bytesize
|
1884
1887
|
@cursor += calculate_width(replaced)
|
@@ -1939,4 +1942,20 @@ class Reline::LineEditor
|
|
1939
1942
|
arg -= 1
|
1940
1943
|
vi_join_lines(key, arg: arg) if arg > 0
|
1941
1944
|
end
|
1945
|
+
|
1946
|
+
private def em_set_mark(key)
|
1947
|
+
@mark_pointer = [@byte_pointer, @line_index]
|
1948
|
+
end
|
1949
|
+
alias_method :set_mark, :em_set_mark
|
1950
|
+
|
1951
|
+
private def em_exchange_mark(key)
|
1952
|
+
new_pointer = [@byte_pointer, @line_index]
|
1953
|
+
@previous_line_index = @line_index
|
1954
|
+
@byte_pointer, @line_index = @mark_pointer
|
1955
|
+
@byte_pointer, @line_index = @mark_pointer
|
1956
|
+
@cursor = calculate_width(@line.byteslice(0, @byte_pointer))
|
1957
|
+
@cursor_max = calculate_width(@line)
|
1958
|
+
@mark_pointer = new_pointer
|
1959
|
+
end
|
1960
|
+
alias_method :exchange_point_and_mark, :em_exchange_mark
|
1942
1961
|
end
|
data/lib/reline/version.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aycabta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
|
-
rubygems_version: 3.0.
|
101
|
+
rubygems_version: 3.0.3
|
102
102
|
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: Alternative GNU Readline or Editline implementation by pure Ruby.
|