Class: Reline::LineEditor

Inherits:
Object
  • Object
show all
Defined in:
lib/reline/line_editor.rb

Defined Under Namespace

Modules: CompletionState Classes: CompletionJourneyData, Dialog, DialogProcScope, MenuInfo

Constant Summary collapse

VI_MOTIONS =
%i{
  ed_prev_char
  ed_next_char
  vi_zero
  ed_move_to_beg
  ed_move_to_end
  vi_to_column
  vi_next_char
  vi_prev_char
  vi_next_word
  vi_prev_word
  vi_to_next_char
  vi_to_prev_char
  vi_end_word
  vi_next_big_word
  vi_prev_big_word
  vi_end_big_word
  vi_repeat_next_char
  vi_repeat_prev_char
}
PROMPT_LIST_CACHE_TIMEOUT =
0.5
MINIMUM_SCROLLBAR_HEIGHT =
1
DIALOG_DEFAULT_HEIGHT =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, encoding) ⇒ LineEditor

Returns a new instance of LineEditor.



57
58
59
60
61
# File 'lib/reline/line_editor.rb', line 57

def initialize(config, encoding)
  @config = config
  @completion_append_character = ''
  reset_variables(encoding: encoding)
end

Instance Attribute Details

#auto_indent_procObject

Returns the value of attribute auto_indent_proc.



16
17
18
# File 'lib/reline/line_editor.rb', line 16

def auto_indent_proc
  @auto_indent_proc
end

#byte_pointerObject

Returns the value of attribute byte_pointer.



10
11
12
# File 'lib/reline/line_editor.rb', line 10

def byte_pointer
  @byte_pointer
end

#completion_append_characterObject

Returns the value of attribute completion_append_character.



13
14
15
# File 'lib/reline/line_editor.rb', line 13

def completion_append_character
  @completion_append_character
end

#completion_procObject

Returns the value of attribute completion_proc.



12
13
14
# File 'lib/reline/line_editor.rb', line 12

def completion_proc
  @completion_proc
end

#confirm_multiline_termination_procObject

Returns the value of attribute confirm_multiline_termination_proc.



11
12
13
# File 'lib/reline/line_editor.rb', line 11

def confirm_multiline_termination_proc
  @confirm_multiline_termination_proc
end

#dig_perfect_match_procObject

Returns the value of attribute dig_perfect_match_proc.



18
19
20
# File 'lib/reline/line_editor.rb', line 18

def dig_perfect_match_proc
  @dig_perfect_match_proc
end

#lineObject (readonly)

TODO: undo TODO: Use “private alias_method” idiom after drop Ruby 2.5.



9
10
11
# File 'lib/reline/line_editor.rb', line 9

def line
  @line
end

#output=(value) ⇒ Object (writeonly)

Sets the attribute output

Parameters:

  • value

    the value to set the attribute output to.



19
20
21
# File 'lib/reline/line_editor.rb', line 19

def output=(value)
  @output = value
end

#output_modifier_procObject

Returns the value of attribute output_modifier_proc.



14
15
16
# File 'lib/reline/line_editor.rb', line 14

def output_modifier_proc
  @output_modifier_proc
end

#pre_input_hookObject

Returns the value of attribute pre_input_hook.



17
18
19
# File 'lib/reline/line_editor.rb', line 17

def pre_input_hook
  @pre_input_hook
end

#prompt_procObject

Returns the value of attribute prompt_proc.



15
16
17
# File 'lib/reline/line_editor.rb', line 15

def prompt_proc
  @prompt_proc
end

Instance Method Details

#add_dialog_proc(name, p, context = nil) ⇒ Object



625
626
627
628
629
630
631
632
# File 'lib/reline/line_editor.rb', line 625

def add_dialog_proc(name, p, context = nil)
  dialog = Dialog.new(name, @config, DialogProcScope.new(self, @config, p, context))
  if index = @dialogs.find_index { |d| d.name == name }
    @dialogs[index] = dialog
  else
    @dialogs << dialog
  end
end

#call_completion_procObject



1597
1598
1599
1600
1601
1602
1603
# File 'lib/reline/line_editor.rb', line 1597

def call_completion_proc
  result = retrieve_completion_block(true)
  pre, target, post = result
  result = call_completion_proc_with_checking_args(pre, target, post)
  Reline.core.instance_variable_set(:@completion_quote_character, nil)
  result
end

#call_completion_proc_with_checking_args(pre, target, post) ⇒ Object



1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
# File 'lib/reline/line_editor.rb', line 1605

def call_completion_proc_with_checking_args(pre, target, post)
  if @completion_proc and target
    argnum = @completion_proc.parameters.inject(0) { |result, item|
      case item.first
      when :req, :opt
        result + 1
      when :rest
        break 3
      end
    }
    case argnum
    when 1
      result = @completion_proc.(target)
    when 2
      result = @completion_proc.(target, pre)
    when 3..Float::INFINITY
      result = @completion_proc.(target, pre, post)
    end
  end
  result
end

#confirm_multiline_terminationObject



1744
1745
1746
1747
1748
1749
1750
1751
1752
# File 'lib/reline/line_editor.rb', line 1744

def confirm_multiline_termination
  temp_buffer = @buffer_of_lines.dup
  if @previous_line_index and @line_index == (@buffer_of_lines.size - 1)
    temp_buffer[@previous_line_index] = @line
  else
    temp_buffer[@line_index] = @line
  end
  @confirm_multiline_termination_proc.(temp_buffer.join("\n") + "\n")
end

#delete_text(start = nil, length = nil) ⇒ Object



1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
# File 'lib/reline/line_editor.rb', line 1766

def delete_text(start = nil, length = nil)
  if start.nil? and length.nil?
    if @is_multiline
      if @buffer_of_lines.size == 1
        @line&.clear
        @byte_pointer = 0
        @cursor = 0
        @cursor_max = 0
      elsif @line_index == (@buffer_of_lines.size - 1) and @line_index > 0
        @buffer_of_lines.pop
        @line_index -= 1
        @line = @buffer_of_lines[@line_index]
        @byte_pointer = 0
        @cursor = 0
        @cursor_max = calculate_width(@line)
      elsif @line_index < (@buffer_of_lines.size - 1)
        @buffer_of_lines.delete_at(@line_index)
        @line = @buffer_of_lines[@line_index]
        @byte_pointer = 0
        @cursor = 0
        @cursor_max = calculate_width(@line)
      end
    else
      @line&.clear
      @byte_pointer = 0
      @cursor = 0
      @cursor_max = 0
    end
  elsif not start.nil? and not length.nil?
    if @line
      before = @line.byteslice(0, start)
      after = @line.byteslice(start + length, @line.bytesize)
      @line = before + after
      @byte_pointer = @line.bytesize if @byte_pointer > @line.bytesize
      str = @line.byteslice(0, @byte_pointer)
      @cursor = calculate_width(str)
      @cursor_max = calculate_width(@line)
    end
  elsif start.is_a?(Range)
    range = start
    first = range.first
    last = range.last
    last = @line.bytesize - 1 if last > @line.bytesize
    last += @line.bytesize if last < 0
    first += @line.bytesize if first < 0
    range = range.exclude_end? ? first...last : first..last
    @line = @line.bytes.reject.with_index{ |c, i| range.include?(i) }.map{ |c| c.chr(Encoding::ASCII_8BIT) }.join.force_encoding(@encoding)
    @byte_pointer = @line.bytesize if @byte_pointer > @line.bytesize
    str = @line.byteslice(0, @byte_pointer)
    @cursor = calculate_width(str)
    @cursor_max = calculate_width(@line)
  else
    @line = @line.byteslice(0, start)
    @byte_pointer = @line.bytesize if @byte_pointer > @line.bytesize
    str = @line.byteslice(0, @byte_pointer)
    @cursor = calculate_width(str)
    @cursor_max = calculate_width(@line)
  end
end

#editing_modeObject



1215
1216
1217
# File 'lib/reline/line_editor.rb', line 1215

def editing_mode
  @config.editing_mode
end

#eof?Boolean

Returns:

  • (Boolean)


248
249
250
# File 'lib/reline/line_editor.rb', line 248

def eof?
  @eof
end

#finalizeObject



244
245
246
# File 'lib/reline/line_editor.rb', line 244

def finalize
  Signal.trap('INT', @old_trap)
end

#finishObject



1852
1853
1854
1855
1856
# File 'lib/reline/line_editor.rb', line 1852

def finish
  @finished = true
  @rerender_all = true
  @config.reset
end

#finished?Boolean

Returns:

  • (Boolean)


1848
1849
1850
# File 'lib/reline/line_editor.rb', line 1848

def finished?
  @finished
end

#input_key(key) ⇒ Object



1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
# File 'lib/reline/line_editor.rb', line 1522

def input_key(key)
  @last_key = key
  @config.reset_oneshot_key_bindings
  @dialogs.each do |dialog|
    if key.char.instance_of?(Symbol) and key.char == dialog.name
      return
    end
  end
  @just_cursor_moving = nil
  if key.char.nil?
    if @first_char
      @line = nil
    end
    finish
    return
  end
  old_line = @line.dup
  @first_char = false
  completion_occurs = false
  if @config.editing_mode_is?(:emacs, :vi_insert) and key.char == "\C-i".ord
    unless @config.disable_completion
      result = call_completion_proc
      if result.is_a?(Array)
        completion_occurs = true
        process_insert
        if @config.autocompletion
          move_completed_list(result, :down)
        else
          complete(result)
        end
      end
    end
  elsif @config.editing_mode_is?(:emacs, :vi_insert) and key.char == :completion_journey_up
    if not @config.disable_completion and @config.autocompletion
      result = call_completion_proc
      if result.is_a?(Array)
        completion_occurs = true
        process_insert
        move_completed_list(result, :up)
      end
    end
  elsif not @config.disable_completion and @config.editing_mode_is?(:vi_insert) and ["\C-p".ord, "\C-n".ord].include?(key.char)
    unless @config.disable_completion
      result = call_completion_proc
      if result.is_a?(Array)
        completion_occurs = true
        process_insert
        move_completed_list(result, "\C-p".ord == key.char ? :up : :down)
      end
    end
  elsif Symbol === key.char and respond_to?(key.char, true)
    process_key(key.char, key.char)
  else
    normal_char(key)
  end
  unless completion_occurs
    @completion_state = CompletionState::NORMAL
    @completion_journey_data = nil
  end
  if not @in_pasting and @just_cursor_moving.nil?
    if @previous_line_index and @buffer_of_lines[@previous_line_index] == @line
      @just_cursor_moving = true
    elsif @previous_line_index.nil? and @buffer_of_lines[@line_index] == @line and old_line == @line
      @just_cursor_moving = true
    else
      @just_cursor_moving = false
    end
  else
    @just_cursor_moving = false
  end
  if @is_multiline and @auto_indent_proc and not simplified_rendering?
    process_auto_indent
  end
end

#insert_text(text) ⇒ Object



1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
# File 'lib/reline/line_editor.rb', line 1754

def insert_text(text)
  width = calculate_width(text)
  if @cursor == @cursor_max
    @line += text
  else
    @line = byteinsert(@line, @byte_pointer, text)
  end
  @byte_pointer += text.bytesize
  @cursor += width
  @cursor_max += width
end

#just_move_cursorObject



921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
# File 'lib/reline/line_editor.rb', line 921

def just_move_cursor
  prompt, prompt_width, prompt_list = check_multiline_prompt(@buffer_of_lines)
  move_cursor_up(@started_from)
  new_first_line_started_from =
    if @line_index.zero?
      0
    else
      (@buffer_of_lines[0..(@line_index - 1)], prompt_list || prompt)
    end
  first_line_diff = new_first_line_started_from - @first_line_started_from
  @cursor, @cursor_max, _, @byte_pointer = calculate_nearest_cursor(@buffer_of_lines[@line_index], @cursor, @started_from, @byte_pointer, false)
  new_started_from = calculate_height_by_width(prompt_width + @cursor) - 1
  calculate_scroll_partial_screen(@highest_in_all, new_first_line_started_from + new_started_from)
  @previous_line_index = nil
  @line = @buffer_of_lines[@line_index]
  if @rerender_all
    rerender_all_lines
    @rerender_all = false
    true
  else
    @first_line_started_from = new_first_line_started_from
    @started_from = new_started_from
    move_cursor_down(first_line_diff + @started_from)
    Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last)
    false
  end
end

#multiline_offObject



314
315
316
# File 'lib/reline/line_editor.rb', line 314

def multiline_off
  @is_multiline = false
end

#multiline_onObject



310
311
312
# File 'lib/reline/line_editor.rb', line 310

def multiline_on
  @is_multiline = true
end

#rerenderObject



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/reline/line_editor.rb', line 422

def rerender
  return if @line.nil?
  if @menu_info
    scroll_down(@highest_in_all - @first_line_started_from)
    @rerender_all = true
  end
  if @menu_info
    show_menu
    @menu_info = nil
  end
  prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines)
  cursor_column = (prompt_width + @cursor) % @screen_size.last
  if @cleared
    clear_screen_buffer(prompt, prompt_list, prompt_width)
    @cleared = false
    return
  end
  if @is_multiline and finished? and @scroll_partial_screen
    # Re-output all code higher than the screen when finished.
    Reline::IOGate.move_cursor_up(@first_line_started_from + @started_from - @scroll_partial_screen)
    Reline::IOGate.move_cursor_column(0)
    @scroll_partial_screen = nil
    new_lines = whole_lines
    prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines)
    modify_lines(new_lines).each_with_index do |line, index|
      @output.write "#{prompt_list ? prompt_list[index] : prompt}#{line}\r\n"
      Reline::IOGate.erase_after_cursor
    end
    @output.flush
    clear_dialog(cursor_column)
    return
  end
  new_highest_in_this = calculate_height_by_width(prompt_width + calculate_width(@line.nil? ? '' : @line))
  rendered = false
  if @add_newline_to_end_of_buffer
    clear_dialog_with_trap_key(cursor_column)
    rerender_added_newline(prompt, prompt_width, prompt_list)
    @add_newline_to_end_of_buffer = false
  else
    if @just_cursor_moving and not @rerender_all
      clear_dialog_with_trap_key(cursor_column)
      rendered = just_move_cursor
      @just_cursor_moving = false
      return
    elsif @previous_line_index or new_highest_in_this != @highest_in_this
      clear_dialog_with_trap_key(cursor_column)
      rerender_changed_current_line
      @previous_line_index = nil
      rendered = true
    elsif @rerender_all
      rerender_all_lines
      @rerender_all = false
      rendered = true
    else
    end
  end
  if @is_multiline
    if finished?
      # Always rerender on finish because output_modifier_proc may return a different output.
      new_lines = whole_lines
      line = modify_lines(new_lines)[@line_index]
      clear_dialog(cursor_column)
      prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines)
      render_partial(prompt, prompt_width, line, @first_line_started_from)
      move_cursor_down(@highest_in_all - (@first_line_started_from + @highest_in_this - 1) - 1)
      scroll_down(1)
      Reline::IOGate.move_cursor_column(0)
      Reline::IOGate.erase_after_cursor
    else
      if not rendered and not @in_pasting
        line = modify_lines(whole_lines)[@line_index]
        prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines)
        render_partial(prompt, prompt_width, line, @first_line_started_from)
      end
      render_dialog(cursor_column)
    end
    @buffer_of_lines[@line_index] = @line
    @rest_height = 0 if @scroll_partial_screen
  else
    line = modify_lines(whole_lines)[@line_index]
    render_partial(prompt, prompt_width, line, 0)
    if finished?
      scroll_down(1)
      Reline::IOGate.move_cursor_column(0)
      Reline::IOGate.erase_after_cursor
    end
  end
end

#rerender_allObject



416
417
418
419
420
# File 'lib/reline/line_editor.rb', line 416

def rerender_all
  @rerender_all = true
  process_insert(force: true)
  rerender
end

#reset(prompt = '', encoding:) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/reline/line_editor.rb', line 150

def reset(prompt = '', encoding:)
  @rest_height = (Reline::IOGate.get_screen_size.first - 1) - Reline::IOGate.cursor_pos.y
  @screen_size = Reline::IOGate.get_screen_size
  @screen_height = @screen_size.first
  reset_variables(prompt, encoding: encoding)
  Reline::IOGate.set_winch_handler do
    @resized = true
  end
  if ENV.key?('RELINE_ALT_SCROLLBAR')
    @full_block = '::'
    @upper_half_block = "''"
    @lower_half_block = '..'
    @block_elem_width = 2
  elsif Reline::IOGate.win?
    @full_block = ''
    @upper_half_block = ''
    @lower_half_block = ''
    @block_elem_width = 1
  elsif @encoding == Encoding::UTF_8
    @full_block = ''
    @upper_half_block = ''
    @lower_half_block = ''
    @block_elem_width = Reline::Unicode.calculate_width('')
  else
    @full_block = '::'
    @upper_half_block = "''"
    @lower_half_block = '..'
    @block_elem_width = 2
  end
end

#reset_lineObject



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/reline/line_editor.rb', line 292

def reset_line
  @cursor = 0
  @cursor_max = 0
  @byte_pointer = 0
  @buffer_of_lines = [String.new(encoding: @encoding)]
  @line_index = 0
  @previous_line_index = nil
  @line = @buffer_of_lines[0]
  @first_line_started_from = 0
  @move_up = 0
  @started_from = 0
  @highest_in_this = 1
  @highest_in_all = 1
  @line_backup_in_history = nil
  @multibyte_buffer = String.new(encoding: 'ASCII-8BIT')
  @check_new_auto_indent = false
end

#reset_variables(prompt = '', encoding:) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/reline/line_editor.rb', line 252

def reset_variables(prompt = '', encoding:)
  @prompt = prompt.gsub("\n", "\\n")
  @mark_pointer = nil
  @encoding = encoding
  @is_multiline = false
  @finished = false
  @cleared = false
  @rerender_all = false
  @history_pointer = nil
  @kill_ring ||= Reline::KillRing.new
  @vi_clipboard = ''
  @vi_arg = nil
  @waiting_proc = nil
  @waiting_operator_proc = nil
  @waiting_operator_vi_arg = nil
  @completion_journey_data = nil
  @completion_state = CompletionState::NORMAL
  @perfect_matched = nil
  @menu_info = nil
  @first_prompt = true
  @searching_prompt = nil
  @first_char = true
  @add_newline_to_end_of_buffer = false
  @just_cursor_moving = nil
  @cached_prompt_list = nil
  @prompt_cache_time = nil
  @eof = false
  @continuous_insertion_buffer = String.new(encoding: @encoding)
  @scroll_partial_screen = nil
  @prev_mode_string = nil
  @drop_terminate_spaces = false
  @in_pasting = false
  @auto_indent_proc = nil
  @dialogs = []
  @previous_rendered_dialog_y = 0
  @last_key = nil
  @resized = false
  reset_line
end

#resizeObject



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/reline/line_editor.rb', line 181

def resize
  return unless @resized
  @resized = false
  @rest_height = (Reline::IOGate.get_screen_size.first - 1) - Reline::IOGate.cursor_pos.y
  old_screen_size = @screen_size
  @screen_size = Reline::IOGate.get_screen_size
  @screen_height = @screen_size.first
  if old_screen_size.last < @screen_size.last # columns increase
    @rerender_all = true
    rerender
  else
    back = 0
    new_buffer = whole_lines
    prompt, prompt_width, prompt_list = check_multiline_prompt(new_buffer)
    new_buffer.each_with_index do |line, index|
      prompt_width = calculate_width(prompt_list[index], true) if @prompt_proc
      width = prompt_width + calculate_width(line)
      height = calculate_height_by_width(width)
      back += height
    end
    @highest_in_all = back
    @highest_in_this = calculate_height_by_width(prompt_width + @cursor_max)
    @first_line_started_from =
      if @line_index.zero?
        0
      else
        (@buffer_of_lines[0..(@line_index - 1)], prompt_list || prompt)
      end
    if @prompt_proc
      prompt = prompt_list[@line_index]
      prompt_width = calculate_width(prompt, true)
    end
    calculate_nearest_cursor
    @started_from = calculate_height_by_width(prompt_width + @cursor) - 1
    Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last)
    @highest_in_this = calculate_height_by_width(prompt_width + @cursor_max)
    @rerender_all = true
  end
end

#retrieve_completion_block(set_completion_quote_character = false) ⇒ Object



1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
# File 'lib/reline/line_editor.rb', line 1666

def retrieve_completion_block(set_completion_quote_character = false)
  if Reline.completer_word_break_characters.empty?
    word_break_regexp = nil
  else
    word_break_regexp = /\A[#{Regexp.escape(Reline.completer_word_break_characters)}]/
  end
  if Reline.completer_quote_characters.empty?
    quote_characters_regexp = nil
  else
    quote_characters_regexp = /\A[#{Regexp.escape(Reline.completer_quote_characters)}]/
  end
  before = @line.byteslice(0, @byte_pointer)
  rest = nil
  break_pointer = nil
  quote = nil
  closing_quote = nil
  escaped_quote = nil
  i = 0
  while i < @byte_pointer do
    slice = @line.byteslice(i, @byte_pointer - i)
    unless slice.valid_encoding?
      i += 1
      next
    end
    if quote and slice.start_with?(closing_quote)
      quote = nil
      i += 1
      rest = nil
    elsif quote and slice.start_with?(escaped_quote)
      # skip
      i += 2
    elsif quote_characters_regexp and slice =~ quote_characters_regexp # find new "
      rest = $'
      quote = $&
      closing_quote = /(?!\\)#{Regexp.escape(quote)}/
      escaped_quote = /\\#{Regexp.escape(quote)}/
      i += 1
      break_pointer = i - 1
    elsif word_break_regexp and not quote and slice =~ word_break_regexp
      rest = $'
      i += 1
      before = @line.byteslice(i, @byte_pointer - i)
      break_pointer = i
    else
      i += 1
    end
  end
  postposing = @line.byteslice(@byte_pointer, @line.bytesize - @byte_pointer)
  if rest
    preposing = @line.byteslice(0, break_pointer)
    target = rest
    if set_completion_quote_character and quote
      Reline.core.instance_variable_set(:@completion_quote_character, quote)
      if postposing !~ /(?!\\)#{Regexp.escape(quote)}/ # closing quote
        insert_text(quote)
      end
    end
  else
    preposing = ''
    if break_pointer
      preposing = @line.byteslice(0, break_pointer)
    else
      preposing = ''
    end
    target = before
  end
  if @is_multiline
    lines = whole_lines
    if @line_index > 0
      preposing = lines[0..(@line_index - 1)].join("\n") + "\n" + preposing
    end
    if (lines.size - 1) > @line_index
      postposing = postposing + "\n" + lines[(@line_index + 1)..-1].join("\n")
    end
  end
  [preposing.encode(@encoding), target.encode(@encoding), postposing.encode(@encoding)]
end

#set_pasting_state(in_pasting) ⇒ Object



63
64
65
# File 'lib/reline/line_editor.rb', line 63

def set_pasting_state(in_pasting)
  @in_pasting = in_pasting
end

#set_signal_handlersObject



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/reline/line_editor.rb', line 221

def set_signal_handlers
  @old_trap = Signal.trap('INT') {
    clear_dialog(0)
    if @scroll_partial_screen
      move_cursor_down(@screen_height - (@line_index - @scroll_partial_screen) - 1)
    else
      move_cursor_down(@highest_in_all - @line_index - 1)
    end
    Reline::IOGate.move_cursor_column(0)
    scroll_down(1)
    case @old_trap
    when 'DEFAULT', 'SYSTEM_DEFAULT'
      raise Interrupt
    when 'IGNORE'
      # Do nothing
    when 'EXIT'
      exit
    else
      @old_trap.call if @old_trap.respond_to?(:call)
    end
  }
end

#simplified_rendering?Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
75
# File 'lib/reline/line_editor.rb', line 67

def simplified_rendering?
  if finished?
    false
  elsif @just_cursor_moving and not @rerender_all
    true
  else
    not @rerender_all and not finished? and @in_pasting
  end
end

#whole_bufferObject



1840
1841
1842
1843
1844
1845
1846
# File 'lib/reline/line_editor.rb', line 1840

def whole_buffer
  if @buffer_of_lines.size == 1 and @line.nil?
    nil
  else
    whole_lines.join("\n")
  end
end

#whole_linesObject



1833
1834
1835
1836
1837
1838
# File 'lib/reline/line_editor.rb', line 1833

def whole_lines
  index = @previous_line_index || @line_index
  temp_lines = @buffer_of_lines.dup
  temp_lines[index] = @line
  temp_lines
end

#wrap_method_call(method_symbol, method_obj, key, with_operator = false) ⇒ Object



1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
# File 'lib/reline/line_editor.rb', line 1407

def wrap_method_call(method_symbol, method_obj, key, with_operator = false)
  if @config.editing_mode_is?(:emacs, :vi_insert) and @waiting_proc.nil? and @waiting_operator_proc.nil?
    not_insertion = method_symbol != :ed_insert
    process_insert(force: not_insertion)
  end
  if @vi_arg and argumentable?(method_obj)
    if with_operator and inclusive?(method_obj)
      method_obj.(key, arg: @vi_arg, inclusive: true)
    else
      method_obj.(key, arg: @vi_arg)
    end
  else
    if with_operator and inclusive?(method_obj)
      method_obj.(key, inclusive: true)
    else
      method_obj.(key)
    end
  end
end