reline 0.5.0 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -80,23 +80,11 @@ module Reline::Terminfo
80
80
  def self.setupterm(term, fildes)
81
81
  errret_int = Fiddle::Pointer.malloc(Fiddle::SIZEOF_INT)
82
82
  ret = @setupterm.(term, fildes, errret_int)
83
- errret = errret_int[0, Fiddle::SIZEOF_INT].unpack1('i')
84
83
  case ret
85
84
  when 0 # OK
86
- 0
85
+ @term_supported = true
87
86
  when -1 # ERR
88
- case errret
89
- when 1
90
- raise TerminfoError.new('The terminal is hardcopy, cannot be used for curses applications.')
91
- when 0
92
- raise TerminfoError.new('The terminal could not be found, or that it is a generic type, having too little information for curses applications to run.')
93
- when -1
94
- raise TerminfoError.new('The terminfo database could not be found.')
95
- else # unknown
96
- -1
97
- end
98
- else # unknown
99
- -2
87
+ @term_supported = false
100
88
  end
101
89
  end
102
90
 
@@ -148,9 +136,14 @@ module Reline::Terminfo
148
136
  num
149
137
  end
150
138
 
139
+ # NOTE: This means Fiddle and curses are enabled.
151
140
  def self.enabled?
152
141
  true
153
142
  end
143
+
144
+ def self.term_supported?
145
+ @term_supported
146
+ end
154
147
  end if Reline::Terminfo.curses_dl
155
148
 
156
149
  module Reline::Terminfo
@@ -128,10 +128,10 @@ class Reline::Unicode
128
128
  end
129
129
  end
130
130
 
131
- def self.split_by_width(str, max_width, encoding = str.encoding)
131
+ def self.split_by_width(str, max_width, encoding = str.encoding, offset: 0)
132
132
  lines = [String.new(encoding: encoding)]
133
133
  height = 1
134
- width = 0
134
+ width = offset
135
135
  rest = str.encode(Encoding::UTF_8)
136
136
  in_zero_width = false
137
137
  seq = String.new(encoding: encoding)
@@ -1,3 +1,3 @@
1
1
  module Reline
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.3'
3
3
  end
@@ -259,7 +259,7 @@ class Reline::Windows
259
259
  def self.check_input_event
260
260
  num_of_events = 0.chr * 8
261
261
  while @@output_buf.empty?
262
- Reline.core.line_editor.resize
262
+ Reline.core.line_editor.handle_signal
263
263
  if @@WaitForSingleObject.(@@hConsoleInputHandle, 100) != 0 # max 0.1 sec
264
264
  # prevent for background consolemode change
265
265
  @@legacy_console = (getconsolemode() & ENABLE_VIRTUAL_TERMINAL_PROCESSING == 0)
data/lib/reline.rb CHANGED
@@ -75,6 +75,7 @@ module Reline
75
75
 
76
76
  def initialize
77
77
  self.output = STDOUT
78
+ @mutex = Mutex.new
78
79
  @dialog_proc_list = {}
79
80
  yield self
80
81
  @completion_quote_character = nil
@@ -219,26 +220,16 @@ module Reline
219
220
 
220
221
  Reline::DEFAULT_DIALOG_PROC_AUTOCOMPLETE = ->() {
221
222
  # autocomplete
222
- return nil unless config.autocompletion
223
- if just_cursor_moving and completion_journey_data.nil?
224
- # Auto complete starts only when edited
225
- return nil
226
- end
227
- pre, target, post = retrieve_completion_block(true)
228
- if target.nil? or target.empty? or (completion_journey_data&.pointer == -1 and target.size <= 3)
229
- return nil
230
- end
231
- if completion_journey_data and completion_journey_data.list
232
- result = completion_journey_data.list.dup
233
- result.shift
234
- pointer = completion_journey_data.pointer - 1
235
- else
236
- result = call_completion_proc_with_checking_args(pre, target, post)
237
- pointer = nil
238
- end
239
- if result and result.size == 1 and result[0] == target and pointer != 0
240
- result = nil
241
- end
223
+ return unless config.autocompletion
224
+
225
+ journey_data = completion_journey_data
226
+ return unless journey_data
227
+
228
+ target = journey_data.list[journey_data.pointer]
229
+ result = journey_data.list.drop(1)
230
+ pointer = journey_data.pointer - 1
231
+ return if target.empty? || (result == [target] && pointer < 0)
232
+
242
233
  target_width = Reline::Unicode.calculate_width(target)
243
234
  x = cursor_pos.x - target_width
244
235
  if x < 0
@@ -264,12 +255,15 @@ module Reline
264
255
  Reline::DEFAULT_DIALOG_CONTEXT = Array.new
265
256
 
266
257
  def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
267
- Reline.update_iogate
268
- io_gate.with_raw_input do
258
+ @mutex.synchronize do
269
259
  unless confirm_multiline_termination
270
260
  raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
271
261
  end
272
- inner_readline(prompt, add_hist, true, &confirm_multiline_termination)
262
+
263
+ Reline.update_iogate
264
+ io_gate.with_raw_input do
265
+ inner_readline(prompt, add_hist, true, &confirm_multiline_termination)
266
+ end
273
267
 
274
268
  whole_buffer = line_editor.whole_buffer.dup
275
269
  whole_buffer.taint if RUBY_VERSION < '2.7'
@@ -288,17 +282,21 @@ module Reline
288
282
  end
289
283
 
290
284
  def readline(prompt = '', add_hist = false)
291
- Reline.update_iogate
292
- inner_readline(prompt, add_hist, false)
285
+ @mutex.synchronize do
286
+ Reline.update_iogate
287
+ io_gate.with_raw_input do
288
+ inner_readline(prompt, add_hist, false)
289
+ end
293
290
 
294
- line = line_editor.line.dup
295
- line.taint if RUBY_VERSION < '2.7'
296
- if add_hist and line and line.chomp("\n").size > 0
297
- Reline::HISTORY << line.chomp("\n")
298
- end
291
+ line = line_editor.line.dup
292
+ line.taint if RUBY_VERSION < '2.7'
293
+ if add_hist and line and line.chomp("\n").size > 0
294
+ Reline::HISTORY << line.chomp("\n")
295
+ end
299
296
 
300
- line_editor.reset_line if line_editor.line.nil?
301
- line
297
+ line_editor.reset_line if line_editor.line.nil?
298
+ line
299
+ end
302
300
  end
303
301
 
304
302
  private def inner_readline(prompt, add_hist, multiline, &confirm_multiline_termination)
@@ -365,19 +363,10 @@ module Reline
365
363
  io_gate.move_cursor_column(0)
366
364
  rescue Errno::EIO
367
365
  # Maybe the I/O has been closed.
368
- rescue StandardError => e
369
- line_editor.finalize
370
- io_gate.deprep(otio)
371
- raise e
372
- rescue Exception
373
- # Including Interrupt
366
+ ensure
374
367
  line_editor.finalize
375
368
  io_gate.deprep(otio)
376
- raise
377
369
  end
378
-
379
- line_editor.finalize
380
- io_gate.deprep(otio)
381
370
  end
382
371
 
383
372
  # GNU Readline waits for "keyseq-timeout" milliseconds to see if the ESC
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.5.0
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-25 00:00:00.000000000 Z
11
+ date: 2024-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: io-console