reline 0.5.9 → 0.5.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -56,51 +56,26 @@ class Reline::Unicode
56
56
 
57
57
  require 'reline/unicode/east_asian_width'
58
58
 
59
- HalfwidthDakutenHandakuten = /[\u{FF9E}\u{FF9F}]/
60
-
61
- MBCharWidthRE = /
62
- (?<width_2_1>
63
- [#{ EscapedChars.map {|c| "\\x%02x" % c.ord }.join }] (?# ^ + char, such as ^M, ^H, ^[, ...)
64
- )
65
- | (?<width_3>^\u{2E3B}) (?# THREE-EM DASH)
66
- | (?<width_0>^\p{M})
67
- | (?<width_2_2>
68
- #{ EastAsianWidth::TYPE_F }
69
- | #{ EastAsianWidth::TYPE_W }
70
- )
71
- | (?<width_1>
72
- #{ EastAsianWidth::TYPE_H }
73
- | #{ EastAsianWidth::TYPE_NA }
74
- | #{ EastAsianWidth::TYPE_N }
75
- )(?!#{ HalfwidthDakutenHandakuten })
76
- | (?<width_2_3>
77
- (?: #{ EastAsianWidth::TYPE_H }
78
- | #{ EastAsianWidth::TYPE_NA }
79
- | #{ EastAsianWidth::TYPE_N })
80
- #{ HalfwidthDakutenHandakuten }
81
- )
82
- | (?<ambiguous_width>
83
- #{EastAsianWidth::TYPE_A}
84
- )
85
- /x
86
-
87
59
  def self.get_mbchar_width(mbchar)
88
60
  ord = mbchar.ord
89
- if (0x00 <= ord and ord <= 0x1F) # in EscapedPairs
61
+ if ord <= 0x1F # in EscapedPairs
90
62
  return 2
91
- elsif (0x20 <= ord and ord <= 0x7E) # printable ASCII chars
63
+ elsif ord <= 0x7E # printable ASCII chars
92
64
  return 1
93
65
  end
94
- m = mbchar.encode(Encoding::UTF_8).match(MBCharWidthRE)
95
- case
96
- when m.nil? then 1 # TODO should be U+FFFD � REPLACEMENT CHARACTER
97
- when m[:width_2_1], m[:width_2_2], m[:width_2_3] then 2
98
- when m[:width_3] then 3
99
- when m[:width_0] then 0
100
- when m[:width_1] then 1
101
- when m[:ambiguous_width] then Reline.ambiguous_width
66
+ utf8_mbchar = mbchar.encode(Encoding::UTF_8)
67
+ ord = utf8_mbchar.ord
68
+ chunk_index = EastAsianWidth::CHUNK_LAST.bsearch_index { |o| ord <= o }
69
+ size = EastAsianWidth::CHUNK_WIDTH[chunk_index]
70
+ if size == -1
71
+ Reline.ambiguous_width
72
+ elsif size == 1 && utf8_mbchar.size >= 2
73
+ second_char_ord = utf8_mbchar[1].ord
74
+ # Halfwidth Dakuten Handakuten
75
+ # Only these two character has Letter Modifier category and can be combined in a single grapheme cluster
76
+ (second_char_ord == 0xFF9E || second_char_ord == 0xFF9F) ? 2 : 1
102
77
  else
103
- nil
78
+ size
104
79
  end
105
80
  end
106
81
 
@@ -1,3 +1,3 @@
1
1
  module Reline
2
- VERSION = '0.5.9'
2
+ VERSION = '0.5.10'
3
3
  end
data/lib/reline.rb CHANGED
@@ -324,14 +324,17 @@ module Reline
324
324
  line_editor.prompt_proc = prompt_proc
325
325
  line_editor.auto_indent_proc = auto_indent_proc
326
326
  line_editor.dig_perfect_match_proc = dig_perfect_match_proc
327
+
328
+ # Readline calls pre_input_hook just after printing the first prompt.
329
+ line_editor.print_nomultiline_prompt
327
330
  pre_input_hook&.call
331
+
328
332
  unless Reline::IOGate.dumb?
329
333
  @dialog_proc_list.each_pair do |name_sym, d|
330
334
  line_editor.add_dialog_proc(name_sym, d.dialog_proc, d.context)
331
335
  end
332
336
  end
333
337
 
334
- line_editor.print_nomultiline_prompt(prompt)
335
338
  line_editor.update_dialogs
336
339
  line_editor.rerender
337
340
 
@@ -343,7 +346,7 @@ module Reline
343
346
  inputs.each do |key|
344
347
  if key.char == :bracketed_paste_start
345
348
  text = io_gate.read_bracketed_paste
346
- line_editor.insert_pasted_text(text)
349
+ line_editor.insert_multiline_text(text)
347
350
  line_editor.scroll_into_view
348
351
  else
349
352
  line_editor.update(key)
@@ -457,8 +460,8 @@ module Reline
457
460
  def_single_delegator :line_editor, :byte_pointer, :point
458
461
  def_single_delegator :line_editor, :byte_pointer=, :point=
459
462
 
460
- def self.insert_text(*args, &block)
461
- line_editor.insert_text(*args, &block)
463
+ def self.insert_text(text)
464
+ line_editor.insert_multiline_text(text)
462
465
  self
463
466
  end
464
467
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.5.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-06-12 00:00:00.000000000 Z
10
+ date: 2024-09-05 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: io-console
@@ -63,7 +62,6 @@ metadata:
63
62
  bug_tracker_uri: https://github.com/ruby/reline/issues
64
63
  changelog_uri: https://github.com/ruby/reline/releases
65
64
  source_code_uri: https://github.com/ruby/reline
66
- post_install_message:
67
65
  rdoc_options: []
68
66
  require_paths:
69
67
  - lib
@@ -78,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
76
  - !ruby/object:Gem::Version
79
77
  version: '0'
80
78
  requirements: []
81
- rubygems_version: 3.5.9
82
- signing_key:
79
+ rubygems_version: 3.6.0.dev
83
80
  specification_version: 4
84
81
  summary: Alternative GNU Readline or Editline implementation by pure Ruby.
85
82
  test_files: []