reline 0.2.5 → 0.2.8.pre.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/reline.rb CHANGED
@@ -7,12 +7,15 @@ require 'reline/key_actor'
7
7
  require 'reline/key_stroke'
8
8
  require 'reline/line_editor'
9
9
  require 'reline/history'
10
+ require 'reline/terminfo'
10
11
  require 'rbconfig'
11
12
 
12
13
  module Reline
13
14
  FILENAME_COMPLETION_PROC = nil
14
15
  USERNAME_COMPLETION_PROC = nil
15
16
 
17
+ class ConfigEncodingConversionError < StandardError; end
18
+
16
19
  Key = Struct.new('Key', :char, :combined_char, :with_meta)
17
20
  CursorPos = Struct.new(:x, :y)
18
21
 
@@ -41,6 +44,7 @@ module Reline
41
44
 
42
45
  def initialize
43
46
  self.output = STDOUT
47
+ @dialog_proc_list = []
44
48
  yield self
45
49
  @completion_quote_character = nil
46
50
  @bracketed_paste_finished = false
@@ -103,6 +107,14 @@ module Reline
103
107
  @completion_proc = p
104
108
  end
105
109
 
110
+ def autocompletion
111
+ @config.autocompletion
112
+ end
113
+
114
+ def autocompletion=(val)
115
+ @config.autocompletion = val
116
+ end
117
+
106
118
  def output_modifier_proc=(p)
107
119
  raise ArgumentError unless p.respond_to?(:call) or p.nil?
108
120
  @output_modifier_proc = p
@@ -127,6 +139,12 @@ module Reline
127
139
  @dig_perfect_match_proc = p
128
140
  end
129
141
 
142
+ def add_dialog_proc(name_sym, p, context = nil)
143
+ raise ArgumentError unless p.respond_to?(:call) or p.nil?
144
+ raise ArgumentError unless name_sym.instance_of?(Symbol)
145
+ @dialog_proc_list << [name_sym, p, context]
146
+ end
147
+
130
148
  def input=(val)
131
149
  raise TypeError unless val.respond_to?(:getc) or val.nil?
132
150
  if val.respond_to?(:getc)
@@ -168,6 +186,45 @@ module Reline
168
186
  Reline::IOGate.get_screen_size
169
187
  end
170
188
 
189
+ Reline::DEFAULT_DIALOG_PROC_AUTOCOMPLETE = ->() {
190
+ # autocomplete
191
+ return nil unless config.autocompletion
192
+ if just_cursor_moving and completion_journey_data.nil?
193
+ # Auto complete starts only when edited
194
+ return nil
195
+ end
196
+ pre, target, post= retrieve_completion_block(true)
197
+ if target.nil? or target.empty?# or target.size <= 3
198
+ return nil
199
+ end
200
+ if completion_journey_data and completion_journey_data.list
201
+ result = completion_journey_data.list.dup
202
+ result.shift
203
+ pointer = completion_journey_data.pointer - 1
204
+ else
205
+ result = call_completion_proc_with_checking_args(pre, target, post)
206
+ pointer = nil
207
+ end
208
+ if result and result.size == 1 and result[0] == target
209
+ result = nil
210
+ end
211
+ target_width = Reline::Unicode.calculate_width(target)
212
+ x = cursor_pos.x - target_width
213
+ if x < 0
214
+ x = screen_width + x
215
+ y = -1
216
+ else
217
+ y = 0
218
+ end
219
+ cursor_pos_to_render = Reline::CursorPos.new(x, y)
220
+ if context and context.is_a?(Array)
221
+ context.clear
222
+ context.push(cursor_pos_to_render, result, pointer)
223
+ end
224
+ [cursor_pos_to_render, result, pointer, nil]
225
+ }
226
+ Reline::DEFAULT_DIALOG_CONTEXT = Array.new
227
+
171
228
  def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
172
229
  unless confirm_multiline_termination
173
230
  raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
@@ -227,13 +284,15 @@ module Reline
227
284
  line_editor.auto_indent_proc = auto_indent_proc
228
285
  line_editor.dig_perfect_match_proc = dig_perfect_match_proc
229
286
  line_editor.pre_input_hook = pre_input_hook
287
+ @dialog_proc_list.each do |d|
288
+ name_sym, dialog_proc, context = d
289
+ line_editor.add_dialog_proc(name_sym, dialog_proc, context)
290
+ end
230
291
 
231
292
  unless config.test_mode
232
293
  config.read
233
294
  config.reset_default_key_bindings
234
- Reline::IOGate::RAW_KEYSTROKE_CONFIG.each_pair do |key, func|
235
- config.add_default_key_binding(key, func)
236
- end
295
+ Reline::IOGate.set_default_key_bindings(config)
237
296
  end
238
297
 
239
298
  line_editor.rerender
@@ -273,11 +332,12 @@ module Reline
273
332
  Reline::IOGate.deprep(otio)
274
333
  end
275
334
 
276
- # Keystrokes of GNU Readline will timeout it with the specification of
277
- # "keyseq-timeout" when waiting for the 2nd character after the 1st one.
278
- # If the 2nd character comes after 1st ESC without timeout it has a
279
- # meta-property of meta-key to discriminate modified key with meta-key
280
- # from multibyte characters that come with 8th bit on.
335
+ # GNU Readline waits for "keyseq-timeout" milliseconds to see if the ESC
336
+ # is followed by a character, and times out and treats it as a standalone
337
+ # ESC if the second character does not arrive. If the second character
338
+ # comes before timed out, it is treated as a modifier key with the
339
+ # meta-property of meta-key, so that it can be distinguished from
340
+ # multibyte characters with the 8th bit turned on.
281
341
  #
282
342
  # GNU Readline will wait for the 2nd character with "keyseq-timeout"
283
343
  # milli-seconds but wait forever after 3rd characters.
@@ -422,6 +482,7 @@ module Reline
422
482
  def_single_delegators :core, :ambiguous_width
423
483
  def_single_delegators :core, :last_incremental_search
424
484
  def_single_delegators :core, :last_incremental_search=
485
+ def_single_delegators :core, :add_dialog_proc
425
486
 
426
487
  def_single_delegators :core, :readmultiline
427
488
  def_instance_delegators self, :readmultiline
@@ -443,6 +504,7 @@ module Reline
443
504
  core.completer_quote_characters = '"\''
444
505
  core.filename_quote_characters = ""
445
506
  core.special_prefixes = ""
507
+ core.add_dialog_proc(:autocomplete, Reline::DEFAULT_DIALOG_PROC_AUTOCOMPLETE, Reline::DEFAULT_DIALOG_CONTEXT)
446
508
  }
447
509
  end
448
510
 
@@ -455,17 +517,25 @@ module Reline
455
517
  end
456
518
  end
457
519
 
520
+ require 'reline/general_io'
458
521
  if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
459
522
  require 'reline/windows'
460
523
  if Reline::Windows.msys_tty?
461
- require 'reline/ansi'
462
- Reline::IOGate = Reline::ANSI
524
+ Reline::IOGate = if ENV['TERM'] == 'dumb'
525
+ Reline::GeneralIO
526
+ else
527
+ require 'reline/ansi'
528
+ Reline::ANSI
529
+ end
463
530
  else
464
531
  Reline::IOGate = Reline::Windows
465
532
  end
466
533
  else
467
- require 'reline/ansi'
468
- Reline::IOGate = Reline::ANSI
534
+ Reline::IOGate = if $stdout.isatty
535
+ require 'reline/ansi'
536
+ Reline::ANSI
537
+ else
538
+ Reline::GeneralIO
539
+ end
469
540
  end
470
541
  Reline::HISTORY = Reline::History.new(Reline.core.config)
471
- require 'reline/general_io'
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.5
4
+ version: 0.2.8.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-02 00:00:00.000000000 Z
11
+ date: 2021-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: io-console
@@ -24,62 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.5'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: test-unit
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: yamatanooroti
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: 0.0.6
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 0.0.6
83
27
  description: Alternative GNU Readline or Editline implementation by pure Ruby.
84
28
  email:
85
29
  - aycabta@gmail.com
@@ -104,6 +48,7 @@ files:
104
48
  - lib/reline/kill_ring.rb
105
49
  - lib/reline/line_editor.rb
106
50
  - lib/reline/sibori.rb
51
+ - lib/reline/terminfo.rb
107
52
  - lib/reline/unicode.rb
108
53
  - lib/reline/unicode/east_asian_width.rb
109
54
  - lib/reline/version.rb
@@ -124,11 +69,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
124
69
  version: '2.5'
125
70
  required_rubygems_version: !ruby/object:Gem::Requirement
126
71
  requirements:
127
- - - ">="
72
+ - - ">"
128
73
  - !ruby/object:Gem::Version
129
- version: '0'
74
+ version: 1.3.1
130
75
  requirements: []
131
- rubygems_version: 3.2.0.rc.1
76
+ rubygems_version: 3.2.22
132
77
  signing_key:
133
78
  specification_version: 4
134
79
  summary: Alternative GNU Readline or Editline implementation by pure Ruby.