reline 0.1.10 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99b4f2cf521a3b774a0c763517fc373fdc2bf1603e64ab8e853513ed64946074
4
- data.tar.gz: 4665d8f6c3db58c573186b4fb245478a1190fdb5da5f9c5f0d569bcfb2cba2f4
3
+ metadata.gz: 2a20f90b83534916dd8575a842ef2cbe968879cc4b2d1826b5374137f554249a
4
+ data.tar.gz: add41e0e8f89fa39b8064c9d45bc0f17ac1b374578ae25872e24c50cb2e0e761
5
5
  SHA512:
6
- metadata.gz: 7b66388f8b9008f5008902e662133312006263622cf7d12d458f5611446b536baf7ff66197209e7b82ada8d34d1b0c8d6eb40c6be35315134c289ded8cc421f7
7
- data.tar.gz: 74ce2b03a99eb548c25050f606140a9fd62351e2cbe20037977f416cc20153f3d711e946c84c4857e66b078a33b7dd12a359f429a2c31091ece7e8f776204931
6
+ metadata.gz: ebd4286538633a6bb87dd2007bdd6bf389ef87aa5dd7406288ae8f52cacc1e0d7f87c4d3ae4bbac3fa125004d5f65b5740c6b8d2ec014e130160d7bd22c6ec1e
7
+ data.tar.gz: 3a418c2aa202ac4710bb7d90d0017870c066e17ece72c644f90e4d37b9faadb02636150d332c00845c5ca60a421abd1394255f77e95be7626cfce046705b7ed0
@@ -36,7 +36,6 @@ module Reline
36
36
  attr_accessor :config
37
37
  attr_accessor :key_stroke
38
38
  attr_accessor :line_editor
39
- attr_accessor :ambiguous_width
40
39
  attr_accessor :last_incremental_search
41
40
  attr_reader :output
42
41
 
@@ -356,9 +355,14 @@ module Reline
356
355
  end
357
356
  end
358
357
 
358
+ def ambiguous_width
359
+ may_req_ambiguous_char_width unless defined? @ambiguous_width
360
+ @ambiguous_width
361
+ end
362
+
359
363
  private def may_req_ambiguous_char_width
360
364
  @ambiguous_width = 2 if Reline::IOGate == Reline::GeneralIO or STDOUT.is_a?(File)
361
- return if ambiguous_width
365
+ return if @ambiguous_width
362
366
  Reline::IOGate.move_cursor_column(0)
363
367
  begin
364
368
  output.write "\u{25bd}"
@@ -38,6 +38,7 @@ class Reline::Config
38
38
  vi-ins-mode-icon
39
39
  emacs-mode-string
40
40
  enable-bracketed-paste
41
+ isearch-terminators
41
42
  }
42
43
  VARIABLE_NAME_SYMBOLS = VARIABLE_NAMES.map { |v| :"#{v.tr(?-, ?_)}" }
43
44
  VARIABLE_NAME_SYMBOLS.each do |v|
@@ -238,7 +239,7 @@ class Reline::Config
238
239
  when 'completion-query-items'
239
240
  @completion_query_items = value.to_i
240
241
  when 'isearch-terminators'
241
- @isearch_terminators = instance_eval(value)
242
+ @isearch_terminators = retrieve_string(value)
242
243
  when 'editing-mode'
243
244
  case value
244
245
  when 'emacs'
@@ -68,6 +68,26 @@ class Reline::LineEditor
68
68
  end
69
69
  end
70
70
 
71
+ private def check_mode_icon
72
+ mode_icon = nil
73
+ if @config.show_mode_in_prompt
74
+ if @config.editing_mode_is?(:vi_command)
75
+ mode_icon = @config.vi_cmd_mode_icon
76
+ elsif @config.editing_mode_is?(:vi_insert)
77
+ mode_icon = @config.vi_ins_mode_icon
78
+ elsif @config.editing_mode_is?(:emacs)
79
+ mode_icon = @config.emacs_mode_string
80
+ else
81
+ mode_icon = '?'
82
+ end
83
+ end
84
+ if mode_icon != @prev_mode_icon
85
+ @rerender_all = true
86
+ end
87
+ @prev_mode_icon = mode_icon
88
+ mode_icon
89
+ end
90
+
71
91
  private def check_multiline_prompt(buffer, prompt)
72
92
  if @vi_arg
73
93
  prompt = "(arg: #{@vi_arg}) "
@@ -78,7 +98,11 @@ class Reline::LineEditor
78
98
  else
79
99
  prompt = @prompt
80
100
  end
81
- return [prompt, calculate_width(prompt, true), [prompt] * buffer.size] if simplified_rendering?
101
+ if simplified_rendering?
102
+ mode_icon = check_mode_icon
103
+ prompt = mode_icon + prompt if mode_icon
104
+ return [prompt, calculate_width(prompt, true), [prompt] * buffer.size]
105
+ end
82
106
  if @prompt_proc
83
107
  use_cached_prompt_list = false
84
108
  if @cached_prompt_list
@@ -95,35 +119,16 @@ class Reline::LineEditor
95
119
  @prompt_cache_time = Time.now.to_f
96
120
  end
97
121
  prompt_list.map!{ prompt } if @vi_arg or @searching_prompt
98
- if @config.show_mode_in_prompt
99
- if @config.editing_mode_is?(:vi_command)
100
- mode_icon = @config.vi_cmd_mode_icon
101
- elsif @config.editing_mode_is?(:vi_insert)
102
- mode_icon = @config.vi_ins_mode_icon
103
- elsif @config.editing_mode_is?(:emacs)
104
- mode_icon = @config.emacs_mode_string
105
- else
106
- mode_icon = '?'
107
- end
108
- prompt_list.map!{ |pr| mode_icon + pr }
109
- end
122
+ mode_icon = check_mode_icon
123
+ prompt_list = prompt_list.map{ |pr| mode_icon + pr } if mode_icon
110
124
  prompt = prompt_list[@line_index]
125
+ prompt = prompt_list[0] if prompt.nil?
111
126
  prompt_width = calculate_width(prompt, true)
112
127
  [prompt, prompt_width, prompt_list]
113
128
  else
129
+ mode_icon = check_mode_icon
130
+ prompt = mode_icon + prompt if mode_icon
114
131
  prompt_width = calculate_width(prompt, true)
115
- if @config.show_mode_in_prompt
116
- if @config.editing_mode_is?(:vi_command)
117
- mode_icon = @config.vi_cmd_mode_icon
118
- elsif @config.editing_mode_is?(:vi_insert)
119
- mode_icon = @config.vi_ins_mode_icon
120
- elsif @config.editing_mode_is?(:emacs)
121
- mode_icon = @config.emacs_mode_string
122
- else
123
- mode_icon = '?'
124
- end
125
- prompt = mode_icon + prompt
126
- end
127
132
  [prompt, prompt_width, nil]
128
133
  end
129
134
  end
@@ -213,6 +218,8 @@ class Reline::LineEditor
213
218
  @eof = false
214
219
  @continuous_insertion_buffer = String.new(encoding: @encoding)
215
220
  @scroll_partial_screen = nil
221
+ @prev_mode_icon = nil
222
+ @drop_terminate_spaces = false
216
223
  reset_line
217
224
  end
218
225
 
@@ -1593,9 +1600,11 @@ class Reline::LineEditor
1593
1600
  searcher = generate_searcher
1594
1601
  searcher.resume(key)
1595
1602
  @searching_prompt = "(reverse-i-search)`': "
1603
+ termination_keys = ["\C-j".ord]
1604
+ termination_keys.concat(@config.isearch_terminators&.chars&.map(&:ord)) if @config.isearch_terminators
1596
1605
  @waiting_proc = ->(k) {
1597
1606
  case k
1598
- when "\C-j".ord
1607
+ when *termination_keys
1599
1608
  if @history_pointer
1600
1609
  buffer = Reline::HISTORY[@history_pointer]
1601
1610
  else
@@ -1614,6 +1623,8 @@ class Reline::LineEditor
1614
1623
  @waiting_proc = nil
1615
1624
  @cursor_max = calculate_width(@line)
1616
1625
  @cursor = @byte_pointer = 0
1626
+ @rerender_all = true
1627
+ @cached_prompt_list = nil
1617
1628
  searcher.resume(-1)
1618
1629
  when "\C-g".ord
1619
1630
  if @is_multiline
@@ -1657,6 +1668,8 @@ class Reline::LineEditor
1657
1668
  @waiting_proc = nil
1658
1669
  @cursor_max = calculate_width(@line)
1659
1670
  @cursor = @byte_pointer = 0
1671
+ @rerender_all = true
1672
+ @cached_prompt_list = nil
1660
1673
  searcher.resume(-1)
1661
1674
  end
1662
1675
  end
@@ -2176,7 +2189,7 @@ class Reline::LineEditor
2176
2189
 
2177
2190
  private def vi_next_word(key, arg: 1)
2178
2191
  if @line.bytesize > @byte_pointer
2179
- byte_size, width = Reline::Unicode.vi_forward_word(@line, @byte_pointer)
2192
+ byte_size, width = Reline::Unicode.vi_forward_word(@line, @byte_pointer, @drop_terminate_spaces)
2180
2193
  @byte_pointer += byte_size
2181
2194
  @cursor += width
2182
2195
  end
@@ -2304,6 +2317,7 @@ class Reline::LineEditor
2304
2317
  end
2305
2318
 
2306
2319
  private def vi_change_meta(key, arg: 1)
2320
+ @drop_terminate_spaces = true
2307
2321
  @waiting_operator_proc = proc { |cursor_diff, byte_pointer_diff|
2308
2322
  if byte_pointer_diff > 0
2309
2323
  @line, cut = byteslice!(@line, @byte_pointer, byte_pointer_diff)
@@ -2315,6 +2329,7 @@ class Reline::LineEditor
2315
2329
  @cursor_max -= cursor_diff.abs
2316
2330
  @byte_pointer += byte_pointer_diff if byte_pointer_diff < 0
2317
2331
  @config.editing_mode = :vi_insert
2332
+ @drop_terminate_spaces = false
2318
2333
  }
2319
2334
  @waiting_operator_vi_arg = arg
2320
2335
  end
@@ -2466,7 +2481,7 @@ class Reline::LineEditor
2466
2481
  byte_size = Reline::Unicode.get_next_mbchar_size(@line, @byte_pointer)
2467
2482
  before = @line.byteslice(0, @byte_pointer)
2468
2483
  remaining_point = @byte_pointer + byte_size
2469
- after = @line.byteslice(remaining_point, @line.size - remaining_point)
2484
+ after = @line.byteslice(remaining_point, @line.bytesize - remaining_point)
2470
2485
  @line = before + k.chr + after
2471
2486
  @cursor_max = calculate_width(@line)
2472
2487
  @waiting_proc = nil
@@ -2477,7 +2492,7 @@ class Reline::LineEditor
2477
2492
  end
2478
2493
  before = @line.byteslice(0, @byte_pointer)
2479
2494
  remaining_point = @byte_pointer + byte_size
2480
- after = @line.byteslice(remaining_point, @line.size - remaining_point)
2495
+ after = @line.byteslice(remaining_point, @line.bytesize - remaining_point)
2481
2496
  replaced = k.chr * arg
2482
2497
  @line = before + replaced + after
2483
2498
  @byte_pointer += replaced.bytesize
@@ -458,8 +458,8 @@ class Reline::Unicode
458
458
  [byte_size, width]
459
459
  end
460
460
 
461
- def self.vi_forward_word(line, byte_pointer)
462
- if (line.bytesize - 1) > byte_pointer
461
+ def self.vi_forward_word(line, byte_pointer, drop_terminate_spaces = false)
462
+ if line.bytesize > byte_pointer
463
463
  size = get_next_mbchar_size(line, byte_pointer)
464
464
  mbchar = line.byteslice(byte_pointer, size)
465
465
  if mbchar =~ /\w/
@@ -474,7 +474,7 @@ class Reline::Unicode
474
474
  else
475
475
  return [0, 0]
476
476
  end
477
- while (line.bytesize - 1) > (byte_pointer + byte_size)
477
+ while line.bytesize > (byte_pointer + byte_size)
478
478
  size = get_next_mbchar_size(line, byte_pointer + byte_size)
479
479
  mbchar = line.byteslice(byte_pointer + byte_size, size)
480
480
  case started_by
@@ -488,7 +488,8 @@ class Reline::Unicode
488
488
  width += get_mbchar_width(mbchar)
489
489
  byte_size += size
490
490
  end
491
- while (line.bytesize - 1) > (byte_pointer + byte_size)
491
+ return [byte_size, width] if drop_terminate_spaces
492
+ while line.bytesize > (byte_pointer + byte_size)
492
493
  size = get_next_mbchar_size(line, byte_pointer + byte_size)
493
494
  mbchar = line.byteslice(byte_pointer + byte_size, size)
494
495
  break if mbchar =~ /\S/
@@ -1,3 +1,3 @@
1
1
  module Reline
2
- VERSION = '0.1.10'
2
+ VERSION = '0.2.0'
3
3
  end
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.1.10
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-20 00:00:00.000000000 Z
11
+ date: 2020-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: io-console