Class: Reline::LineEditor
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Classes:
| |
Inherits: | Object |
Defined in: | lib/reline/line_editor.rb |
Constant Summary
-
DIALOG_DEFAULT_HEIGHT =
# File 'lib/reline/line_editor.rb', line 70020
-
MINIMUM_SCROLLBAR_HEIGHT =
# File 'lib/reline/line_editor.rb', line 731
-
VI_MOTIONS =
# File 'lib/reline/line_editor.rb', line 19%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 }
Class Method Summary
- .new(config, encoding) ⇒ LineEditor constructor
Instance Attribute Summary
- #auto_indent_proc rw
-
#byte_pointer
rw
TODO: undo TODO: Use “private alias_method” idiom after drop Ruby 2.5.
- #byte_pointer=(val) rw
- #completion_append_character rw
- #completion_proc rw
- #confirm_multiline_termination_proc rw
- #dig_perfect_match_proc rw
- #eof? ⇒ Boolean readonly
- #finished? ⇒ Boolean readonly
- #output=(value) writeonly
- #output_modifier_proc rw
- #prompt_proc rw
Instance Method Summary
- #add_dialog_proc(name, p, context = nil)
-
#backward_char(key, arg: 1)
Alias for #ed_prev_char.
-
#backward_delete_char(key, arg: 1)
Alias for #em_delete_prev_char.
-
#backward_kill_word(key)
Alias for #ed_delete_prev_word.
-
#backward_word(key)
Alias for #ed_prev_word.
-
#beginning_of_line(key)
Alias for #ed_move_to_beg.
- #calculate_overlay_levels(overlay_levels)
- #call_completion_proc
- #call_completion_proc_with_checking_args(pre, target, post)
-
#capitalize_word(key)
Alias for #em_capitol_case.
- #clear_dialogs
- #clear_rendered_lines
-
#clear_screen(key)
Alias for #ed_clear_screen.
- #confirm_multiline_termination
- #current_byte_pointer_cursor
- #current_line
-
#delete_char(key)
Alias for #em_delete.
-
#delete_char_or_list(key)
Alias for #em_delete_or_list.
- #delete_text(start = nil, length = nil)
- #dialog_proc_scope_completion_journey_data
-
#downcase_word(key)
Alias for #em_lower_case.
-
#ed_digit(key)
Alias for #ed_insert.
- #editing_mode
-
#end_of_line(key)
Alias for #ed_move_to_end.
-
#exchange_point_and_mark(key)
Alias for #em_exchange_mark.
- #finalize
- #finish
-
#forward_char(key, arg: 1)
Alias for #ed_next_char.
-
#forward_search_history(key)
Alias for #vi_search_next.
-
#forward_word(key)
Alias for #em_next_word.
- #handle_signal
-
#history_search_backward(key, arg: 1)
Alias for #ed_search_prev_history.
-
#history_search_forward(key, arg: 1)
Alias for #ed_search_next_history.
- #input_key(key)
- #insert_text(text)
- #io_gate
-
#kill_line(key)
Alias for #ed_kill_line.
-
#kill_whole_line(key)
Alias for #em_kill_line.
-
#kill_word(key)
Alias for #em_delete_next_word.
- #line
-
#menu_complete_backward(key)
Alias for #completion_journey_up.
- #modified_lines
- #multiline_off
- #multiline_on
-
#next_history(key, arg: 1)
Alias for #ed_next_history.
-
#previous_history(key, arg: 1)
Alias for #ed_prev_history.
- #print_nomultiline_prompt(prompt)
- #prompt_list
-
#quoted_insert(str, arg: 1)
Alias for #ed_quoted_insert.
- #render_differential
- #render_finished
- #render_full_content
- #render_line_differential(old_items, new_items)
- #rerender
- #reset(prompt = '', encoding:)
- #reset_line
- #reset_variables(prompt = '', encoding:)
- #rest_height(wrapped_cursor_y)
- #retrieve_completion_block(set_completion_quote_character = false)
-
#reverse_search_history(key)
Alias for #vi_search_prev.
- #screen_height
- #screen_scroll_top
- #screen_width
- #scroll_into_view
-
#self_insert(key)
Alias for #ed_insert.
- #set_current_line(line, byte_pointer = nil)
-
#set_mark(key)
Alias for #em_set_mark.
- #set_pasting_state(in_pasting)
- #set_signal_handlers
-
#transpose_chars(key)
Alias for #ed_transpose_chars.
-
#transpose_words(key)
Alias for #ed_transpose_words.
-
#unix_line_discard(key)
Alias for #vi_kill_line_prev.
-
#unix_word_rubout(key)
Alias for #em_kill_region.
-
#upcase_word(key)
Alias for #em_upper_case.
- #update(key)
- #update_dialogs(key = nil)
- #upper_space_height(wrapped_cursor_y)
-
#vi_end_of_transmission(key)
Alias for #vi_list_or_eof.
-
#vi_eof_maybe(key)
Alias for #vi_list_or_eof.
-
#vi_movement_mode(key)
Alias for #vi_command_mode.
-
#vi_zero(key)
Alias for #ed_move_to_beg.
- #whole_buffer
- #whole_lines
- #with_cache(key, *deps)
- #wrap_method_call(method_symbol, method_obj, key, with_operator = false)
-
#wrapped_cursor_position
Calculate cursor position in word wrapped content.
- #wrapped_prompt_and_input_lines
-
#yank(key)
Alias for #em_yank.
-
#yank_pop(key)
Alias for #em_yank_pop.
- #argumentable?(method_obj) ⇒ Boolean private
- #byteinsert(str, byte_pointer, other) private
- #byteslice!(str, byte_pointer, size) private
- #calculate_nearest_cursor(cursor) private
- #calculate_width(str, allow_escape_code = false) private
- #check_mode_string private
- #check_multiline_prompt(buffer, mode_string) private
- #cleanup_waiting private
- #complete(list, just_show_list) private
- #complete_internal_proc(list, is_menu) private
- #completion_journey_up(key) (also: #menu_complete_backward) private
- #copy_for_vi(text) private
- #dialog_range(dialog, dialog_y) private
- #ed_argument_digit(key) private
- #ed_clear_screen(key) (also: #clear_screen) private
- #ed_delete_next_char(key, arg: 1) private
- #ed_delete_prev_char(key, arg: 1) private
- #ed_delete_prev_word(key) (also: #backward_kill_word) private
-
#ed_insert(key)
(also: #ed_digit, #self_insert)
private
- Editline
ed-insert
(vi input: almost all; emacs: printable characters).
-
#ed_kill_line(key)
(also: #kill_line)
private
- Editline
ed-kill-line
(vi command:D
,Ctrl-K
; emacs:Ctrl-K
,.
- #ed_move_to_beg(key) (also: #beginning_of_line, #vi_zero) private
- #ed_move_to_end(key) (also: #end_of_line) private
- #ed_newline(key) private
- #ed_next_char(key, arg: 1) (also: #forward_char) private
- #ed_next_history(key, arg: 1) (also: #next_history) private
- #ed_prev_char(key, arg: 1) (also: #backward_char) private
- #ed_prev_history(key, arg: 1) (also: #previous_history) private
- #ed_prev_word(key) (also: #backward_word) private
- #ed_quoted_insert(str, arg: 1) (also: #quoted_insert) private
- #ed_search_next_history(key, arg: 1) (also: #history_search_forward) private
- #ed_search_prev_history(key, arg: 1) (also: #history_search_backward) private
- #ed_transpose_chars(key) (also: #transpose_chars) private
- #ed_transpose_words(key) (also: #transpose_words) private
-
#ed_unassigned(key)
private
do nothing.
- #em_capitol_case(key) (also: #capitalize_word) private
- #em_delete(key) (also: #delete_char) private
- #em_delete_next_word(key) (also: #kill_word) private
- #em_delete_or_list(key) (also: #delete_char_or_list) private
- #em_delete_prev_char(key, arg: 1) (also: #backward_delete_char) private
- #em_exchange_mark(key) (also: #exchange_point_and_mark) private
-
#em_kill_line(key)
(also: #kill_whole_line)
private
- Editline
em-kill-line
(not bound) Delete the entire contents of the.
- #em_kill_region(key) (also: #unix_word_rubout) private
- #em_lower_case(key) (also: #downcase_word) private
- #em_next_word(key) (also: #forward_word) private
- #em_set_mark(key) (also: #set_mark) private
- #em_upper_case(key) (also: #upcase_word) private
- #em_yank(key) (also: #yank) private
- #em_yank_pop(key) (also: #yank_pop) private
- #emacs_editing_mode(key) private
- #generate_searcher(search_key) private
- #handle_interrupted private
- #handle_resized private
- #inclusive?(method_obj) ⇒ Boolean private
- #incremental_search_history(key) private
- #insert_new_line(cursor_line, next_line) private
- #key_delete(key) private
- #key_newline(key) private
- #menu(_target, list) private
- #modify_lines(before, complete) private
- #move_completed_list(direction) private
- #move_history(history_pointer, line:, cursor:, save_buffer: true) private
- #normal_char(key) private
- #padding_space_with_escape_sequences(str, width) private
- #process_auto_indent(line_index = @line_index, cursor_dependent: true, add_newline: false) private
- #process_insert(force: false) private
- #process_key(key, method_symbol) private
- #retrieve_completion_journey_state private
- #run_for_operators(key, method_symbol, &block) private
- #search_history(prefix, pointer_range) private
- #search_next_char(key, arg, need_prev_char: false, inclusive: false) private
- #search_prev_char(key, arg, need_next_char = false) private
- #split_by_width(str, max_width, offset: 0) private
- #update_each_dialog(dialog, cursor_column, cursor_row, key = nil) private
- #vi_add(key) private
- #vi_add_at_eol(key) private
- #vi_change_meta(key, arg: nil) private
- #vi_change_meta_confirm(byte_pointer_diff) private
-
#vi_change_to_eol(key)
private
- Editline
vi_change_to_eol
(vi command:C
) + Kill and change from the cursor to the end of the line.
- #vi_command_mode(key) (also: #vi_movement_mode) private
- #vi_delete_meta(key, arg: nil) private
- #vi_delete_meta_confirm(byte_pointer_diff) private
- #vi_delete_prev_char(key) private
- #vi_editing_mode(key) private
- #vi_end_big_word(key, arg: 1, inclusive: false) private
- #vi_end_word(key, arg: 1, inclusive: false) private
- #vi_first_print(key) private
- #vi_histedit(key) private
- #vi_insert(key) private
- #vi_insert_at_bol(key) private
- #vi_join_lines(key, arg: 1) private
-
#vi_kill_line_prev(key)
(also: #unix_line_discard)
private
- Editline
vi-kill-line-prev
(vi:Ctrl-U
) Delete the string from the.
- #vi_list_or_eof(key) (also: #vi_end_of_transmission, #vi_eof_maybe) private
- #vi_next_big_word(key, arg: 1) private
- #vi_next_char(key, arg: 1, inclusive: false) private
- #vi_next_word(key, arg: 1) private
- #vi_paste_next(key, arg: 1) private
- #vi_paste_prev(key, arg: 1) private
- #vi_prev_big_word(key, arg: 1) private
- #vi_prev_char(key, arg: 1) private
- #vi_prev_word(key, arg: 1) private
- #vi_replace_char(key, arg: 1) private
- #vi_search_next(key) (also: #forward_search_history) private
- #vi_search_prev(key) (also: #reverse_search_history) private
- #vi_to_column(key, arg: 0) private
- #vi_to_history_line(key) private
- #vi_to_next_char(key, arg: 1, inclusive: false) private
- #vi_to_prev_char(key, arg: 1) private
- #vi_yank(key, arg: nil) private
- #vi_yank_confirm(byte_pointer_diff) private
Constructor Details
.new(config, encoding) ⇒ LineEditor
# File 'lib/reline/line_editor.rb', line 75
def initialize(config, encoding) @config = config @completion_append_character = '' @screen_size = Reline::IOGate.get_screen_size reset_variables(encoding: encoding) end
Instance Attribute Details
#auto_indent_proc (rw)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 15
attr_accessor :auto_indent_proc
#byte_pointer (rw)
TODO: undo TODO: Use “private alias_method” idiom after drop Ruby 2.5.
# File 'lib/reline/line_editor.rb', line 9
attr_reader :byte_pointer
#byte_pointer=(val) (rw)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1379
def byte_pointer=(val) @byte_pointer = val end
#completion_append_character (rw)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 12
attr_accessor :completion_append_character
#completion_proc (rw)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 11
attr_accessor :completion_proc
#confirm_multiline_termination_proc (rw)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 10
attr_accessor :confirm_multiline_termination_proc
#dig_perfect_match_proc (rw)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 16
attr_accessor :dig_perfect_match_proc
#eof? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/reline/line_editor.rb', line 219
def eof? @eof end
#finished? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/reline/line_editor.rb', line 1391
def finished? @finished end
#output=(value) (writeonly)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 17
attr_writer :output
#output_modifier_proc (rw)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 13
attr_accessor :output_modifier_proc
#prompt_proc (rw)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 14
attr_accessor :prompt_proc
Instance Method Details
#add_dialog_proc(name, p, context = nil)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 691
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
#argumentable?(method_obj) ⇒ Boolean
(private)
# File 'lib/reline/line_editor.rb', line 968
private def argumentable?(method_obj) method_obj and method_obj.parameters.any? { |param| param[0] == :key and param[1] == :arg } end
#backward_char(key, arg: 1)
Alias for #ed_prev_char.
# File 'lib/reline/line_editor.rb', line 1532
alias_method :backward_char, :ed_prev_char
#backward_delete_char(key, arg: 1)
Alias for #em_delete_prev_char.
# File 'lib/reline/line_editor.rb', line 1836
alias_method :backward_delete_char, :em_delete_prev_char
#backward_kill_word(key)
Alias for #ed_delete_prev_word.
# File 'lib/reline/line_editor.rb', line 1973
alias_method :backward_kill_word, :ed_delete_prev_word
#backward_word(key)
Alias for #ed_prev_word.
# File 'lib/reline/line_editor.rb', line 1953
alias_method :backward_word, :ed_prev_word
#beginning_of_line(key)
Alias for #ed_move_to_beg.
# File 'lib/reline/line_editor.rb', line 1541
alias_method :beginning_of_line, :ed_move_to_beg
#byteinsert(str, byte_pointer, other) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1406
private def byteinsert(str, byte_pointer, other) new_str = str.byteslice(0, byte_pointer) new_str << other new_str << str.byteslice(byte_pointer, str.bytesize) new_str end
#byteslice!(str, byte_pointer, size) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1400
private def byteslice!(str, byte_pointer, size) new_str = str.byteslice(0, byte_pointer) new_str << str.byteslice(byte_pointer + size, str.bytesize) [new_str, str.byteslice(byte_pointer, size)] end
#calculate_nearest_cursor(cursor) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 306
private def calculate_nearest_cursor(cursor) line_to_calc = current_line new_cursor_max = calculate_width(line_to_calc) new_cursor = 0 new_byte_pointer = 0 height = 1 max_width = screen_width if @config.editing_mode_is?(:vi_command) last_byte_size = Reline::Unicode.get_prev_mbchar_size(line_to_calc, line_to_calc.bytesize) if last_byte_size > 0 last_mbchar = line_to_calc.byteslice(line_to_calc.bytesize - last_byte_size, last_byte_size) last_width = Reline::Unicode.get_mbchar_width(last_mbchar) end_of_line_cursor = new_cursor_max - last_width else end_of_line_cursor = new_cursor_max end else end_of_line_cursor = new_cursor_max end line_to_calc.grapheme_clusters.each do |gc| mbchar = gc.encode(Encoding::UTF_8) mbchar_width = Reline::Unicode.get_mbchar_width(mbchar) now = new_cursor + mbchar_width if now > end_of_line_cursor or now > cursor break end new_cursor += mbchar_width if new_cursor > max_width * height height += 1 end new_byte_pointer += gc.bytesize end @byte_pointer = new_byte_pointer end
#calculate_overlay_levels(overlay_levels)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 396
def ( ) levels = [] .each do |x, w, l| levels.fill(l, x, w) end levels end
#calculate_width(str, allow_escape_code = false) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1413
private def calculate_width(str, allow_escape_code = false) Reline::Unicode.calculate_width(str, allow_escape_code) end
#call_completion_proc
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1188
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)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1196
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
#capitalize_word(key)
Alias for #em_capitol_case.
# File 'lib/reline/line_editor.rb', line 2013
alias_method :capitalize_word, :em_capitol_case
#check_mode_string (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 93
private def check_mode_string if @config.show_mode_in_prompt if @config.editing_mode_is?(:vi_command) @config.vi_cmd_mode_string elsif @config.editing_mode_is?(:vi_insert) @config.vi_ins_mode_string elsif @config.editing_mode_is?(:emacs) @config.emacs_mode_string else '?' end end end
#check_multiline_prompt(buffer, mode_string) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 107
private def check_multiline_prompt(buffer, mode_string) if @vi_arg prompt = "(arg: #{@vi_arg}) " elsif @searching_prompt prompt = @searching_prompt else prompt = @prompt end if !@is_multiline mode_string = check_mode_string prompt = mode_string + prompt if mode_string [prompt] + [''] * (buffer.size - 1) elsif @prompt_proc prompt_list = @prompt_proc.(buffer).map { |pr| pr.gsub("\n", "\\n") } prompt_list.map!{ prompt } if @vi_arg or @searching_prompt prompt_list = [prompt] if prompt_list.empty? prompt_list = prompt_list.map{ |pr| mode_string + pr } if mode_string prompt = prompt_list[@line_index] prompt = prompt_list[0] if prompt.nil? prompt = prompt_list.last if prompt.nil? if buffer.size > prompt_list.size (buffer.size - prompt_list.size).times do prompt_list << prompt_list.last end end prompt_list else prompt = mode_string + prompt if mode_string [prompt] * buffer.size end end
#cleanup_waiting (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 998
private def cleanup_waiting @waiting_proc = nil @vi_waiting_operator = nil @vi_waiting_operator_arg = nil @searching_prompt = nil @drop_terminate_spaces = false end
#clear_dialogs
[ GitHub ]# File 'lib/reline/line_editor.rb', line 439
def clear_dialogs @dialogs.each do |dialog| dialog.contents = nil dialog.trap_key = nil end end
#clear_rendered_lines
[ GitHub ]# File 'lib/reline/line_editor.rb', line 459
def clear_rendered_lines Reline::IOGate.move_cursor_up @rendered_screen.cursor_y Reline::IOGate.move_cursor_column 0 num_lines = @rendered_screen.lines.size return unless num_lines && num_lines >= 1 Reline::IOGate.move_cursor_down num_lines - 1 (num_lines - 1).times do Reline::IOGate.erase_after_cursor Reline::IOGate.move_cursor_up 1 end Reline::IOGate.erase_after_cursor @rendered_screen.lines = [] @rendered_screen.cursor_y = 0 end
#clear_screen(key)
Alias for #ed_clear_screen.
# File 'lib/reline/line_editor.rb', line 1937
alias_method :clear_screen, :ed_clear_screen
#complete(list, just_show_list) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 861
private def complete(list, just_show_list) case @completion_state when CompletionState::NORMAL @completion_state = CompletionState::COMPLETION when CompletionState::PERFECT_MATCH @dig_perfect_match_proc&.(@perfect_matched) end if just_show_list = true elsif @completion_state == CompletionState::MENU = true elsif @completion_state == CompletionState::MENU_WITH_PERFECT_MATCH = true else = false end result = complete_internal_proc(list, ) if @completion_state == CompletionState::MENU_WITH_PERFECT_MATCH @completion_state = CompletionState::PERFECT_MATCH end return if result.nil? target, preposing, completed, postposing = result return if completed.nil? if target <= completed and (@completion_state == CompletionState::COMPLETION) if list.include?(completed) if list.one? @completion_state = CompletionState::PERFECT_MATCH else @completion_state = CompletionState::MENU_WITH_PERFECT_MATCH complete(list, true) if @config.show_all_if_ambiguous end @perfect_matched = completed else @completion_state = CompletionState::MENU complete(list, true) if @config.show_all_if_ambiguous end if not just_show_list and target < completed @buffer_of_lines[@line_index] = (preposing + completed + completion_append_character.to_s + postposing).split("\n")[@line_index] || String.new(encoding: @encoding) line_to_pointer = (preposing + completed + completion_append_character.to_s).split("\n")[@line_index] || String.new(encoding: @encoding) @byte_pointer = line_to_pointer.bytesize end end end
#complete_internal_proc(list, is_menu) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 815
private def complete_internal_proc(list, ) preposing, target, postposing = retrieve_completion_block list = list.select { |i| if i and not Encoding.compatible?(target.encoding, i.encoding) raise Encoding::CompatibilityError, "#{target.encoding.name} is not compatible with #{i.encoding.name}" end if @config.completion_ignore_case i&.downcase&.start_with?(target.downcase) else i&.start_with?(target) end }.uniq if (target, list) return nil end completed = list.inject { |memo, item| begin memo_mbchars = memo.unicode_normalize.grapheme_clusters item_mbchars = item.unicode_normalize.grapheme_clusters rescue Encoding::CompatibilityError memo_mbchars = memo.grapheme_clusters item_mbchars = item.grapheme_clusters end size = [memo_mbchars.size, item_mbchars.size].min result = +'' size.times do |i| if @config.completion_ignore_case if memo_mbchars[i].casecmp?(item_mbchars[i]) result << memo_mbchars[i] else break end else if memo_mbchars[i] == item_mbchars[i] result << memo_mbchars[i] else break end end end result } [target, preposing, completed, postposing] end
#completion_journey_up(key) (private) Also known as: #menu_complete_backward
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1433
private def completion_journey_up(key) if not @config.disable_completion and @config.autocompletion @completion_state = CompletionState::NORMAL @completion_occurs = move_completed_list(:up) end end
#confirm_multiline_termination
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1330
def confirm_multiline_termination temp_buffer = @buffer_of_lines.dup @confirm_multiline_termination_proc.(temp_buffer.join("\n") + "\n") end
#copy_for_vi(text) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2051
private def copy_for_vi(text) if @config.editing_mode_is?(:vi_insert) or @config.editing_mode_is?(:vi_command) @vi_clipboard = text end end
#current_byte_pointer_cursor
[ GitHub ]# File 'lib/reline/line_editor.rb', line 302
def current_byte_pointer_cursor calculate_width(current_line.byteslice(0, @byte_pointer)) end
#current_line
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1239
def current_line @buffer_of_lines[@line_index] end
#delete_char(key)
Alias for #em_delete.
# File 'lib/reline/line_editor.rb', line 1900
alias_method :delete_char, :em_delete
#delete_char_or_list(key)
Alias for #em_delete_or_list.
# File 'lib/reline/line_editor.rb', line 1912
alias_method :delete_char_or_list, :em_delete_or_list
#delete_text(start = nil, length = nil)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1345
def delete_text(start = nil, length = nil) if start.nil? and length.nil? if @buffer_of_lines.size == 1 @buffer_of_lines[@line_index] = '' @byte_pointer = 0 elsif @line_index == (@buffer_of_lines.size - 1) and @line_index > 0 @buffer_of_lines.pop @line_index -= 1 @byte_pointer = 0 elsif @line_index < (@buffer_of_lines.size - 1) @buffer_of_lines.delete_at(@line_index) @byte_pointer = 0 end elsif not start.nil? and not length.nil? if current_line before = current_line.byteslice(0, start) after = current_line.byteslice(start + length, current_line.bytesize) set_current_line(before + after) end elsif start.is_a?(Range) range = start first = range.first last = range.last last = current_line.bytesize - 1 if last > current_line.bytesize last += current_line.bytesize if last < 0 first += current_line.bytesize if first < 0 range = range.exclude_end? ? first...last : first..last line = current_line.bytes.reject.with_index{ |c, i| range.include?(i) }.map{ |c| c.chr(Encoding::ASCII_8BIT) }.join.force_encoding(@encoding) set_current_line(line) else set_current_line(current_line.byteslice(0, start)) end end
#dialog_proc_scope_completion_journey_data
[ GitHub ]# File 'lib/reline/line_editor.rb', line 905
def dialog_proc_scope_completion_journey_data return nil unless @completion_journey_state line_index = @completion_journey_state.line_index pre_lines = @buffer_of_lines[0...line_index].map { |line| line + "\n" } post_lines = @buffer_of_lines[(line_index + 1)..-1].map { |line| line + "\n" } DialogProcScope::CompletionJourneyData.new( pre_lines.join + @completion_journey_state.pre, @completion_journey_state.post + post_lines.join, @completion_journey_state.list, @completion_journey_state.pointer ) end
#dialog_range(dialog, dialog_y) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 709
private def dialog_range(dialog, dialog_y) x_range = dialog.column...dialog.column + dialog.width y_range = dialog_y + dialog.vertical_offset...dialog_y + dialog.vertical_offset + dialog.contents.size [x_range, y_range] end
#downcase_word(key)
Alias for #em_lower_case.
# File 'lib/reline/line_editor.rb', line 2026
alias_method :downcase_word, :em_lower_case
#ed_argument_digit(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2301
private def ed_argument_digit(key) if @vi_arg.nil? if key.chr.to_i.zero? if key.anybits?(0b10000000) unescaped_key = key ^ 0b10000000 unless unescaped_key.chr.to_i.zero? @vi_arg = unescaped_key.chr.to_i end end else @vi_arg = key.chr.to_i end else @vi_arg = @vi_arg * 10 + key.chr.to_i end end
#ed_clear_screen(key) (private) Also known as: #clear_screen
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1930
private def ed_clear_screen(key) Reline::IOGate.clear_screen @screen_size = Reline::IOGate.get_screen_size @rendered_screen.lines = [] @rendered_screen.base_y = 0 @rendered_screen.cursor_y = 0 end
#ed_delete_next_char(key, arg: 1) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2247
private def ed_delete_next_char(key, arg: 1) byte_size = Reline::Unicode.get_next_mbchar_size(current_line, @byte_pointer) unless current_line.empty? || byte_size == 0 line, mbchar = byteslice!(current_line, @byte_pointer, byte_size) copy_for_vi(mbchar) if @byte_pointer > 0 && current_line.bytesize == @byte_pointer + byte_size byte_size = Reline::Unicode.get_prev_mbchar_size(line, @byte_pointer) set_current_line(line, @byte_pointer - byte_size) else set_current_line(line, @byte_pointer) end end arg -= 1 ed_delete_next_char(key, arg: arg) if arg > 0 end
#ed_delete_prev_char(key, arg: 1) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2162
private def ed_delete_prev_char(key, arg: 1) deleted = +'' arg.times do if @byte_pointer > 0 byte_size = Reline::Unicode.get_prev_mbchar_size(current_line, @byte_pointer) @byte_pointer -= byte_size line, mbchar = byteslice!(current_line, @byte_pointer, byte_size) set_current_line(line) deleted.prepend(mbchar) end end copy_for_vi(deleted) end
#ed_delete_prev_word(key) (private) Also known as: #backward_kill_word
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1965
private def ed_delete_prev_word(key) if @byte_pointer > 0 byte_size, _ = Reline::Unicode.em_backward_word(current_line, @byte_pointer) line, word = byteslice!(current_line, @byte_pointer - byte_size, byte_size) set_current_line(line, @byte_pointer - byte_size) @kill_ring.append(word, true) end end
#ed_digit(key)
Alias for #ed_insert.
# File 'lib/reline/line_editor.rb', line 1489
alias_method :ed_digit, :ed_insert
#ed_insert(key) (private) Also known as: #ed_digit, #self_insert
- Editline
-
ed-insert
(vi input: almost all; emacs: printable characters) In insert mode, insert the input character left of the cursor position. In replace mode, overwrite the character at the cursor and move the cursor to the right by one character position. Accept an argument to do this repeatedly. It is an error if the input character is the NUL character (Ctrl-@
). Failure to enlarge the edit buffer also results in an error. - Editline
-
ed-digit
(emacs: 0 to 9) If in argument input mode, append the input digit to the argument being read. Otherwise, called-insert
. It is an error if the input character is not a digit or if the existing argument is already greater than a million. - GNU Readline
-
self-insert
(a, b, A, 1, !, …) Insert yourself.
# File 'lib/reline/line_editor.rb', line 1464
private def ed_insert(key) if key.instance_of?(String) begin key.encode(Encoding::UTF_8) rescue Encoding::UndefinedConversionError return end str = key else begin key.chr.encode(Encoding::UTF_8) rescue Encoding::UndefinedConversionError return end str = key.chr end if @in_pasting @continuous_insertion_buffer << str return elsif not @continuous_insertion_buffer.empty? process_insert end insert_text(str) end
#ed_kill_line(key) (private) Also known as: #kill_line
- Editline
-
ed-kill-line
(vi command:D
,Ctrl-K
; emacs:Ctrl-K
,Ctrl-U
) + Kill from the cursor to the end of the line. - GNU Readline
-
kill-line
(C-k
) Kill the text from point to the end of the line. With a negative numeric argument, kill backward from the cursor to the beginning of the current line.
# File 'lib/reline/line_editor.rb', line 1843
private def ed_kill_line(key) if current_line.bytesize > @byte_pointer line, deleted = byteslice!(current_line, @byte_pointer, current_line.bytesize - @byte_pointer) set_current_line(line, line.bytesize) @kill_ring.append(deleted) elsif @byte_pointer == current_line.bytesize and @buffer_of_lines.size > @line_index + 1 set_current_line(current_line + @buffer_of_lines.delete_at(@line_index + 1), current_line.bytesize) end end
#ed_move_to_beg(key) (private) Also known as: #beginning_of_line, #vi_zero
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1538
private def ed_move_to_beg(key) @byte_pointer = 0 end
#ed_move_to_end(key) (private) Also known as: #end_of_line
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1544
private def ed_move_to_end(key) @byte_pointer = current_line.bytesize end
#ed_newline(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1793
private def ed_newline(key) process_insert(force: true) if @is_multiline if @config.editing_mode_is?(:vi_command) if @line_index < (@buffer_of_lines.size - 1) ed_next_history(key) # means cursor down else # should check confirm_multiline_termination to finish? finish end else if @line_index == (@buffer_of_lines.size - 1) if confirm_multiline_termination finish else key_newline(key) end else # should check confirm_multiline_termination to finish? @line_index = @buffer_of_lines.size - 1 @byte_pointer = current_line.bytesize finish end end else finish end end
#ed_next_char(key, arg: 1) (private) Also known as: #forward_char
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1508
private def ed_next_char(key, arg: 1) byte_size = Reline::Unicode.get_next_mbchar_size(current_line, @byte_pointer) if (@byte_pointer < current_line.bytesize) @byte_pointer += byte_size elsif @config.editing_mode_is?(:emacs) and @byte_pointer == current_line.bytesize and @line_index < @buffer_of_lines.size - 1 @byte_pointer = 0 @line_index += 1 end arg -= 1 ed_next_char(key, arg: arg) if arg > 0 end
#ed_next_history(key, arg: 1) (private) Also known as: #next_history
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1776
private def ed_next_history(key, arg: 1) if @line_index < (@buffer_of_lines.size - 1) cursor = current_byte_pointer_cursor @line_index += 1 calculate_nearest_cursor(cursor) return end move_history( (@history_pointer || Reline::HISTORY.size) + 1, line: :start, cursor: @config.editing_mode_is?(:vi_command) ? :start : :end, ) arg -= 1 ed_next_history(key, arg: arg) if arg > 0 end
#ed_prev_char(key, arg: 1) (private) Also known as: #backward_char
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1521
private def ed_prev_char(key, arg: 1) if @byte_pointer > 0 byte_size = Reline::Unicode.get_prev_mbchar_size(current_line, @byte_pointer) @byte_pointer -= byte_size elsif @config.editing_mode_is?(:emacs) and @byte_pointer == 0 and @line_index > 0 @line_index -= 1 @byte_pointer = current_line.bytesize end arg -= 1 ed_prev_char(key, arg: arg) if arg > 0 end
#ed_prev_history(key, arg: 1) (private) Also known as: #previous_history
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1759
private def ed_prev_history(key, arg: 1) if @line_index > 0 cursor = current_byte_pointer_cursor @line_index -= 1 calculate_nearest_cursor(cursor) return end move_history( (@history_pointer || Reline::HISTORY.size) - 1, line: :end, cursor: @config.editing_mode_is?(:vi_command) ? :start : :end, ) arg -= 1 ed_prev_history(key, arg: arg) if arg > 0 end
#ed_prev_word(key) (private) Also known as: #backward_word
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1947
private def ed_prev_word(key) if @byte_pointer > 0 byte_size, _ = Reline::Unicode.em_backward_word(current_line, @byte_pointer) @byte_pointer -= byte_size end end
#ed_quoted_insert(str, arg: 1) (private) Also known as: #quoted_insert
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1492
private def ed_quoted_insert(str, arg: 1) @waiting_proc = proc { |key| arg.times do if key == "\C-j".ord or key == "\C-m".ord key_newline(key) elsif key == 0 # Ignore NUL. else ed_insert(key) end end @waiting_proc = nil } end
#ed_search_next_history(key, arg: 1) (private) Also known as: #history_search_forward
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1723
private def ed_search_next_history(key, arg: 1) substr = current_line.byteslice(0, @byte_pointer) return if @history_pointer.nil? history_range = @history_pointer + 1...Reline::HISTORY.size h_pointer, line_index = search_history(substr, history_range) return if h_pointer.nil? and not substr.empty? move_history(h_pointer, line: line_index || :start, cursor: @byte_pointer) arg -= 1 ed_search_next_history(key, arg: arg) if arg > 0 end
#ed_search_prev_history(key, arg: 1) (private) Also known as: #history_search_backward
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1709
private def ed_search_prev_history(key, arg: 1) substr = current_line.byteslice(0, @byte_pointer) return if @history_pointer == 0 return if @history_pointer.nil? && substr.empty? && !current_line.empty? history_range = 0...(@history_pointer || Reline::HISTORY.size) h_pointer, line_index = search_history(substr, history_range.reverse_each) return unless h_pointer move_history(h_pointer, line: line_index || :start, cursor: @byte_pointer) arg -= 1 ed_search_prev_history(key, arg: arg) if arg > 0 end
#ed_transpose_chars(key) (private) Also known as: #transpose_chars
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1975
private def ed_transpose_chars(key) if @byte_pointer > 0 if @byte_pointer < current_line.bytesize byte_size = Reline::Unicode.get_next_mbchar_size(current_line, @byte_pointer) @byte_pointer += byte_size end back1_byte_size = Reline::Unicode.get_prev_mbchar_size(current_line, @byte_pointer) if (@byte_pointer - back1_byte_size) > 0 back2_byte_size = Reline::Unicode.get_prev_mbchar_size(current_line, @byte_pointer - back1_byte_size) back2_pointer = @byte_pointer - back1_byte_size - back2_byte_size line, back2_mbchar = byteslice!(current_line, back2_pointer, back2_byte_size) set_current_line(byteinsert(line, @byte_pointer - back2_byte_size, back2_mbchar)) end end end
#ed_transpose_words(key) (private) Also known as: #transpose_words
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1992
private def ed_transpose_words(key) left_word_start, middle_start, right_word_start, after_start = Reline::Unicode.ed_transpose_words(current_line, @byte_pointer) before = current_line.byteslice(0, left_word_start) left_word = current_line.byteslice(left_word_start, middle_start - left_word_start) middle = current_line.byteslice(middle_start, right_word_start - middle_start) right_word = current_line.byteslice(right_word_start, after_start - right_word_start) after = current_line.byteslice(after_start, current_line.bytesize - after_start) return if left_word.empty? or right_word.empty? from_head_to_left_word = before + right_word + middle + left_word set_current_line(from_head_to_left_word + after, from_head_to_left_word.bytesize) end
#ed_unassigned(key) (private)
do nothing
# File 'lib/reline/line_editor.rb', line 1443
private def ed_unassigned(key) end
#editing_mode
[ GitHub ]# File 'lib/reline/line_editor.rb', line 807
def editing_mode @config.editing_mode end
#em_capitol_case(key) (private) Also known as: #capitalize_word
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2005
private def em_capitol_case(key) if current_line.bytesize > @byte_pointer byte_size, _, new_str = Reline::Unicode.em_forward_word_with_capitalization(current_line, @byte_pointer) before = current_line.byteslice(0, @byte_pointer) after = current_line.byteslice((@byte_pointer + byte_size)..-1) set_current_line(before + new_str + after, @byte_pointer + new_str.bytesize) end end
#em_delete(key) (private) Also known as: #delete_char
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1887
private def em_delete(key) if current_line.empty? and @buffer_of_lines.size == 1 and key == "\C-d".ord @eof = true finish elsif @byte_pointer < current_line.bytesize splitted_last = current_line.byteslice(@byte_pointer, current_line.bytesize) mbchar = splitted_last.grapheme_clusters.first line, = byteslice!(current_line, @byte_pointer, mbchar.bytesize) set_current_line(line) elsif @byte_pointer == current_line.bytesize and @buffer_of_lines.size > @line_index + 1 set_current_line(current_line + @buffer_of_lines.delete_at(@line_index + 1), current_line.bytesize) end end
#em_delete_next_word(key) (private) Also known as: #kill_word
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1955
private def em_delete_next_word(key) if current_line.bytesize > @byte_pointer byte_size, _ = Reline::Unicode.em_forward_word(current_line, @byte_pointer) line, word = byteslice!(current_line, @byte_pointer, byte_size) set_current_line(line) @kill_ring.append(word) end end
#em_delete_or_list(key) (private) Also known as: #delete_char_or_list
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1902
private def em_delete_or_list(key) if current_line.empty? or @byte_pointer < current_line.bytesize em_delete(key) elsif !@config.autocompletion # show completed list result = call_completion_proc if result.is_a?(Array) complete(result, true) end end end
#em_delete_prev_char(key, arg: 1) (private) Also known as: #backward_delete_char
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1822
private def em_delete_prev_char(key, arg: 1) arg.times do if @byte_pointer == 0 and @line_index > 0 @byte_pointer = @buffer_of_lines[@line_index - 1].bytesize @buffer_of_lines[@line_index - 1] += @buffer_of_lines.delete_at(@line_index) @line_index -= 1 elsif @byte_pointer > 0 byte_size = Reline::Unicode.get_prev_mbchar_size(current_line, @byte_pointer) line, = byteslice!(current_line, @byte_pointer - byte_size, byte_size) set_current_line(line, @byte_pointer - byte_size) end end process_auto_indent end
#em_exchange_mark(key) (private) Also known as: #exchange_point_and_mark
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2463
private def em_exchange_mark(key) return unless @mark_pointer new_pointer = [@byte_pointer, @line_index] @byte_pointer, @line_index = @mark_pointer @mark_pointer = new_pointer end
#em_kill_line(key) (private) Also known as: #kill_whole_line
- Editline
-
em-kill-line
(not bound) Delete the entire contents of the edit buffer and save it to the cut buffer.vi-kill-line-prev
- GNU Readline
-
kill-whole-line
(not bound) Kill all characters on the current line, no matter where point is.
# File 'lib/reline/line_editor.rb', line 1879
private def em_kill_line(key) if current_line.size > 0 @kill_ring.append(current_line.dup, true) set_current_line('', 0) end end
#em_kill_region(key) (private) Also known as: #unix_word_rubout
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2041
private def em_kill_region(key) if @byte_pointer > 0 byte_size, _ = Reline::Unicode.em_big_backward_word(current_line, @byte_pointer) line, deleted = byteslice!(current_line, @byte_pointer - byte_size, byte_size) set_current_line(line, @byte_pointer - byte_size) @kill_ring.append(deleted, true) end end
#em_lower_case(key) (private) Also known as: #downcase_word
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2015
private def em_lower_case(key) if current_line.bytesize > @byte_pointer byte_size, = Reline::Unicode.em_forward_word(current_line, @byte_pointer) part = current_line.byteslice(@byte_pointer, byte_size).grapheme_clusters.map { |mbchar| mbchar =~ /[A-Z]/ ? mbchar.downcase : mbchar }.join rest = current_line.byteslice((@byte_pointer + byte_size)..-1) line = current_line.byteslice(0, @byte_pointer) + part set_current_line(line + rest, line.bytesize) end end
#em_next_word(key) (private) Also known as: #forward_word
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1939
private def em_next_word(key) if current_line.bytesize > @byte_pointer byte_size, _ = Reline::Unicode.em_forward_word(current_line, @byte_pointer) @byte_pointer += byte_size end end
#em_set_mark(key) (private) Also known as: #set_mark
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2458
private def em_set_mark(key) @mark_pointer = [@byte_pointer, @line_index] end
#em_upper_case(key) (private) Also known as: #upcase_word
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2028
private def em_upper_case(key) if current_line.bytesize > @byte_pointer byte_size, = Reline::Unicode.em_forward_word(current_line, @byte_pointer) part = current_line.byteslice(@byte_pointer, byte_size).grapheme_clusters.map { |mbchar| mbchar =~ /[a-z]/ ? mbchar.upcase : mbchar }.join rest = current_line.byteslice((@byte_pointer + byte_size)..-1) line = current_line.byteslice(0, @byte_pointer) + part set_current_line(line + rest, line.bytesize) end end
#em_yank(key) (private) Also known as: #yank
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1914
private def em_yank(key) yanked = @kill_ring.yank insert_text(yanked) if yanked end
#em_yank_pop(key) (private) Also known as: #yank_pop
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1920
private def em_yank_pop(key) yanked, prev_yank = @kill_ring.yank_pop if yanked line, = byteslice!(current_line, @byte_pointer - prev_yank.bytesize, prev_yank.bytesize) set_current_line(line, @byte_pointer - prev_yank.bytesize) insert_text(yanked) end end
#emacs_editing_mode(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2471
private def emacs_editing_mode(key) @config.editing_mode = :emacs end
#end_of_line(key)
Alias for #ed_move_to_end.
# File 'lib/reline/line_editor.rb', line 1547
alias_method :end_of_line, :ed_move_to_end
#exchange_point_and_mark(key)
Alias for #em_exchange_mark.
# File 'lib/reline/line_editor.rb', line 2469
alias_method :exchange_point_and_mark, :em_exchange_mark
#finalize
[ GitHub ]# File 'lib/reline/line_editor.rb', line 215
def finalize Signal.trap('INT', @old_trap) end
#finish
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1395
def finish @finished = true @config.reset end
#forward_char(key, arg: 1)
Alias for #ed_next_char.
# File 'lib/reline/line_editor.rb', line 1519
alias_method :forward_char, :ed_next_char
#forward_search_history(key)
Alias for #vi_search_next.
# File 'lib/reline/line_editor.rb', line 1697
alias_method :forward_search_history, :vi_search_next
#forward_word(key)
Alias for #em_next_word.
# File 'lib/reline/line_editor.rb', line 1945
alias_method :forward_word, :em_next_word
#generate_searcher(search_key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1549
private def generate_searcher(search_key) search_word = String.new(encoding: @encoding) multibyte_buf = String.new(encoding: 'ASCII-8BIT') hit_pointer = nil lambda do |key| search_again = false case key when "\C-h".ord, "\C-?".ord grapheme_clusters = search_word.grapheme_clusters if grapheme_clusters.size > 0 grapheme_clusters.pop search_word = grapheme_clusters.join end when "\C-r".ord, "\C-s".ord search_again = true if search_key == key search_key = key else multibyte_buf << key if multibyte_buf.dup.force_encoding(@encoding).valid_encoding? search_word << multibyte_buf.dup.force_encoding(@encoding) multibyte_buf.clear end end hit = nil if not search_word.empty? and @line_backup_in_history&.include?(search_word) hit_pointer = Reline::HISTORY.size hit = @line_backup_in_history else if search_again if search_word.empty? and Reline.last_incremental_search search_word = Reline.last_incremental_search end if @history_pointer case search_key when "\C-r".ord history_pointer_base = 0 history = Reline::HISTORY[0..(@history_pointer - 1)] when "\C-s".ord history_pointer_base = @history_pointer + 1 history = Reline::HISTORY[(@history_pointer + 1)..-1] end else history_pointer_base = 0 history = Reline::HISTORY end elsif @history_pointer case search_key when "\C-r".ord history_pointer_base = 0 history = Reline::HISTORY[0..@history_pointer] when "\C-s".ord history_pointer_base = @history_pointer history = Reline::HISTORY[@history_pointer..-1] end else history_pointer_base = 0 history = Reline::HISTORY end case search_key when "\C-r".ord hit_index = history.rindex { |item| item.include?(search_word) } when "\C-s".ord hit_index = history.index { |item| item.include?(search_word) } end if hit_index hit_pointer = history_pointer_base + hit_index hit = Reline::HISTORY[hit_pointer] end end case search_key when "\C-r".ord prompt_name = 'reverse-i-search' when "\C-s".ord prompt_name = 'i-search' end prompt_name = "failed #{prompt_name}" unless hit [search_word, prompt_name, hit_pointer] end end
#handle_interrupted (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 184
private def handle_interrupted return unless @interrupted @interrupted = false clear_dialogs scrolldown = render_differential Reline::IOGate.scroll_down scrolldown Reline::IOGate.move_cursor_column 0 @rendered_screen.lines = [] @rendered_screen.cursor_y = 0 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
#handle_resized (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 171
private def handle_resized return unless @resized @screen_size = Reline::IOGate.get_screen_size @resized = false scroll_into_view Reline::IOGate.move_cursor_up @rendered_screen.cursor_y @rendered_screen.base_y = Reline::IOGate.cursor_pos.y @rendered_screen.lines = [] @rendered_screen.cursor_y = 0 render_differential end
#handle_signal
[ GitHub ]# File 'lib/reline/line_editor.rb', line 166
def handle_signal handle_interrupted handle_resized end
#history_search_backward(key, arg: 1)
Alias for #ed_search_prev_history.
# File 'lib/reline/line_editor.rb', line 1721
alias_method :history_search_backward, :ed_search_prev_history
#history_search_forward(key, arg: 1)
Alias for #ed_search_next_history.
# File 'lib/reline/line_editor.rb', line 1735
alias_method :history_search_forward, :ed_search_next_history
#inclusive?(method_obj) ⇒ Boolean
(private)
# File 'lib/reline/line_editor.rb', line 972
private def inclusive?(method_obj) # If a motion method with the keyword argument "inclusive" follows the # operator, it must contain the character at the cursor position. method_obj and method_obj.parameters.any? { |param| param[0] == :key and param[1] == :inclusive } end
#incremental_search_history(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1633
private def incremental_search_history(key) unless @history_pointer @line_backup_in_history = whole_buffer end searcher = generate_searcher(key) @searching_prompt = "(reverse-i-search)`': " termination_keys = ["\C-j".ord] termination_keys.concat(@config.isearch_terminators&.chars&.map(&:ord)) if @config.isearch_terminators @waiting_proc = ->(k) { case k when *termination_keys if @history_pointer buffer = Reline::HISTORY[@history_pointer] else buffer = @line_backup_in_history end @buffer_of_lines = buffer.split("\n") @buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty? @line_index = @buffer_of_lines.size - 1 @searching_prompt = nil @waiting_proc = nil @byte_pointer = 0 when "\C-g".ord @buffer_of_lines = @line_backup_in_history.split("\n") @buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty? @line_index = @buffer_of_lines.size - 1 move_history(nil, line: :end, cursor: :end, save_buffer: false) @searching_prompt = nil @waiting_proc = nil @byte_pointer = 0 else chr = k.is_a?(String) ? k : k.chr(Encoding::ASCII_8BIT) if chr.match?(/[[:print:]]/) or k == "\C-h".ord or k == "\C-?".ord or k == "\C-r".ord or k == "\C-s".ord search_word, prompt_name, hit_pointer = searcher.call(k) Reline.last_incremental_search = search_word @searching_prompt = "(%s)`%s'" % [prompt_name, search_word] @searching_prompt += ': ' unless @is_multiline move_history(hit_pointer, line: :end, cursor: :end, save_buffer: false) if hit_pointer else if @history_pointer line = Reline::HISTORY[@history_pointer] else line = @line_backup_in_history end @line_backup_in_history = whole_buffer @buffer_of_lines = line.split("\n") @buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty? @line_index = @buffer_of_lines.size - 1 @searching_prompt = nil @waiting_proc = nil @byte_pointer = 0 end end } end
#input_key(key)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1115
def input_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 if key.char.nil? if @first_char @eof = true end finish return end old_lines = @buffer_of_lines.dup @first_char = false @completion_occurs = false if @config.editing_mode_is?(:emacs, :vi_insert) and key.char == "\C-i".ord if !@config.disable_completion process_insert(force: true) if @config.autocompletion @completion_state = CompletionState::NORMAL @completion_occurs = move_completed_list(:down) else @completion_journey_state = nil result = call_completion_proc if result.is_a?(Array) @completion_occurs = true complete(result, false) end end end elsif @config.editing_mode_is?(:vi_insert) and ["\C-p".ord, "\C-n".ord].include?(key.char) # In vi mode, move completed list even if autocompletion is off if not @config.disable_completion process_insert(force: true) @completion_state = CompletionState::NORMAL @completion_occurs = move_completed_list("\C-p".ord == key.char ? :up : :down) 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_state = nil end if @in_pasting clear_dialogs return end modified = old_lines != @buffer_of_lines if !@completion_occurs && modified && !@config.disable_completion && @config.autocompletion # Auto complete starts only when edited process_insert(force: true) @completion_journey_state = retrieve_completion_journey_state end modified end
#insert_new_line(cursor_line, next_line) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 275
private def insert_new_line(cursor_line, next_line) @buffer_of_lines.insert(@line_index + 1, String.new(next_line, encoding: @encoding)) @buffer_of_lines[@line_index] = cursor_line @line_index += 1 @byte_pointer = 0 if @auto_indent_proc && !@in_pasting if next_line.empty? ( # For compatibility, use this calculation instead of just `process_auto_indent @line_index - 1, cursor_dependent: false` indent1 = @auto_indent_proc.(@buffer_of_lines.take(@line_index - 1).push(''), @line_index - 1, 0, true) indent2 = @auto_indent_proc.(@buffer_of_lines.take(@line_index), @line_index - 1, @buffer_of_lines[@line_index - 1].bytesize, false) indent = indent2 || indent1 @buffer_of_lines[@line_index - 1] = ' ' * indent + @buffer_of_lines[@line_index - 1].gsub(/\A */, '') ) process_auto_indent @line_index, add_newline: true else process_auto_indent @line_index - 1, cursor_dependent: false process_auto_indent @line_index, add_newline: true # Need for compatibility process_auto_indent @line_index, cursor_dependent: false end end end
#insert_text(text)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1335
def insert_text(text) if @buffer_of_lines[@line_index].bytesize == @byte_pointer @buffer_of_lines[@line_index] += text else @buffer_of_lines[@line_index] = byteinsert(@buffer_of_lines[@line_index], @byte_pointer, text) end @byte_pointer += text.bytesize process_auto_indent end
#io_gate
[ GitHub ]#key_delete(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1417
private def key_delete(key) if @config.editing_mode_is?(:vi_insert) ed_delete_next_char(key) elsif @config.editing_mode_is?(:emacs) em_delete(key) end end
#key_newline(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1425
private def key_newline(key) if @is_multiline next_line = current_line.byteslice(@byte_pointer, current_line.bytesize - @byte_pointer) cursor_line = current_line.byteslice(0, @byte_pointer) insert_new_line(cursor_line, next_line) end end
#kill_line(key)
Alias for #ed_kill_line.
# File 'lib/reline/line_editor.rb', line 1852
alias_method :kill_line, :ed_kill_line
#kill_whole_line(key)
Alias for #em_kill_line.
# File 'lib/reline/line_editor.rb', line 1885
alias_method :kill_whole_line, :em_kill_line
#kill_word(key)
Alias for #em_delete_next_word.
# File 'lib/reline/line_editor.rb', line 1963
alias_method :kill_word, :em_delete_next_word
#line
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1235
def line() @buffer_of_lines.join("\n") unless eof? end
#modified_lines
[ GitHub ]# File 'lib/reline/line_editor.rb', line 349
def modified_lines with_cache(__method__, whole_lines, finished?) do |whole, complete| modify_lines(whole, complete) end end
#modify_lines(before, complete) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 799
private def modify_lines(before, complete) if after = @output_modifier_proc&.call("#{before.join("\n")}\n", complete: complete) after.lines("\n").map { |l| l.chomp('') } else before.map { |l| Reline::Unicode.escape_for_print(l) } end end
#move_completed_list(direction) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 918
private def move_completed_list(direction) @completion_journey_state ||= retrieve_completion_journey_state return false unless @completion_journey_state if (delta = { up: -1, down: +1 }[direction]) @completion_journey_state.pointer = (@completion_journey_state.pointer + delta) % @completion_journey_state.list.size end completed = @completion_journey_state.list[@completion_journey_state.pointer] set_current_line(@completion_journey_state.pre + completed + @completion_journey_state.post, @completion_journey_state.pre.bytesize + completed.bytesize) true end
#move_history(history_pointer, line:, cursor:, save_buffer: true) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1737
private def move_history(history_pointer, line:, cursor:, save_buffer: true) history_pointer ||= Reline::HISTORY.size return if history_pointer < 0 || history_pointer > Reline::HISTORY.size old_history_pointer = @history_pointer || Reline::HISTORY.size if old_history_pointer == Reline::HISTORY.size @line_backup_in_history = save_buffer ? whole_buffer : '' else Reline::HISTORY[old_history_pointer] = whole_buffer if save_buffer end if history_pointer == Reline::HISTORY.size buf = @line_backup_in_history @history_pointer = @line_backup_in_history = nil else buf = Reline::HISTORY[history_pointer] @history_pointer = history_pointer end @buffer_of_lines = buf.split("\n") @buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty? @line_index = line == :start ? 0 : line == :end ? @buffer_of_lines.size - 1 : line @byte_pointer = cursor == :start ? 0 : cursor == :end ? current_line.bytesize : cursor end
#multiline_off
[ GitHub ]# File 'lib/reline/line_editor.rb', line 271
def multiline_off @is_multiline = false end
#multiline_on
[ GitHub ]# File 'lib/reline/line_editor.rb', line 267
def multiline_on @is_multiline = true end
#next_history(key, arg: 1)
Alias for #ed_next_history.
# File 'lib/reline/line_editor.rb', line 1791
alias_method :next_history, :ed_next_history
#normal_char(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1069
private def normal_char(key) if key.combined_char.is_a?(Symbol) process_key(key.combined_char, key.combined_char) return end @multibyte_buffer << key.combined_char if @multibyte_buffer.size > 1 if @multibyte_buffer.dup.force_encoding(@encoding).valid_encoding? process_key(@multibyte_buffer.dup.force_encoding(@encoding), nil) @multibyte_buffer.clear else # invalid return end else # single byte return if key.char >= 128 # maybe, first byte of multi byte method_symbol = @config.editing_mode.get_method(key.combined_char) if key. and method_symbol == :ed_unassigned if @config.editing_mode_is?(:vi_command, :vi_insert) # split ESC + key in vi mode method_symbol = @config.editing_mode.get_method("\e".ord) process_key("\e".ord, method_symbol) method_symbol = @config.editing_mode.get_method(key.char) process_key(key.char, method_symbol) end else process_key(key.combined_char, method_symbol) end @multibyte_buffer.clear end if @config.editing_mode_is?(:vi_command) and @byte_pointer > 0 and @byte_pointer == current_line.bytesize byte_size = Reline::Unicode.get_prev_mbchar_size(@buffer_of_lines[@line_index], @byte_pointer) @byte_pointer -= byte_size end end
#padding_space_with_escape_sequences(str, width) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 702
private def padding_space_with_escape_sequences(str, width) padding_width = width - calculate_width(str, true) # padding_width should be only positive value. But macOS and Alacritty returns negative value. padding_width = 0 if padding_width < 0 str + (' ' * padding_width) end
#previous_history(key, arg: 1)
Alias for #ed_prev_history.
# File 'lib/reline/line_editor.rb', line 1774
alias_method :previous_history, :ed_prev_history
#print_nomultiline_prompt(prompt)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 485
def print_nomultiline_prompt(prompt) return unless prompt && !@is_multiline # Readline's test `TestRelineAsReadline#test_readline` requires first output to be prompt, not cursor reset escape sequence. @rendered_screen.lines = [[[0, Reline::Unicode.calculate_width(prompt, true), prompt]]] @rendered_screen.cursor_y = 0 @output.write prompt end
#process_auto_indent(line_index = @line_index, cursor_dependent: true, add_newline: false) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1218
private def process_auto_indent(line_index = @line_index, cursor_dependent: true, add_newline: false) return if @in_pasting return unless @auto_indent_proc line = @buffer_of_lines[line_index] byte_pointer = cursor_dependent && @line_index == line_index ? @byte_pointer : line.bytesize new_indent = @auto_indent_proc.(@buffer_of_lines.take(line_index + 1).push(''), line_index, byte_pointer, add_newline) return unless new_indent new_line = ' ' * new_indent + line.lstrip @buffer_of_lines[line_index] = new_line if @line_index == line_index indent_diff = new_line.bytesize - line.bytesize @byte_pointer = [@byte_pointer + indent_diff, 0].max end end
#process_insert(force: false) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1445
private def process_insert(force: false) return if @continuous_insertion_buffer.empty? or (@in_pasting and not force) insert_text(@continuous_insertion_buffer) @continuous_insertion_buffer.clear end
#process_key(key, method_symbol) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1006
private def process_key(key, method_symbol) if key.is_a?(Symbol) cleanup_waiting elsif @waiting_proc old_byte_pointer = @byte_pointer @waiting_proc.call(key) if @vi_waiting_operator byte_pointer_diff = @byte_pointer - old_byte_pointer @byte_pointer = old_byte_pointer send(@vi_waiting_operator, byte_pointer_diff) cleanup_waiting end @kill_ring.process return end if method_symbol and respond_to?(method_symbol, true) method_obj = method(method_symbol) end if method_symbol and key.is_a?(Symbol) if @vi_arg and argumentable?(method_obj) run_for_operators(key, method_symbol) do |with_operator| wrap_method_call(method_symbol, method_obj, key, with_operator) end else wrap_method_call(method_symbol, method_obj, key) if method_obj end @kill_ring.process if @vi_arg @vi_arg = nil end elsif @vi_arg if key.chr =~ /[0-9]/ ed_argument_digit(key) else if argumentable?(method_obj) run_for_operators(key, method_symbol) do |with_operator| wrap_method_call(method_symbol, method_obj, key, with_operator) end elsif method_obj wrap_method_call(method_symbol, method_obj, key) else ed_insert(key) unless @config.editing_mode_is?(:vi_command) end @kill_ring.process if @vi_arg @vi_arg = nil end end elsif method_obj if method_symbol == :ed_argument_digit wrap_method_call(method_symbol, method_obj, key) else run_for_operators(key, method_symbol) do |with_operator| wrap_method_call(method_symbol, method_obj, key, with_operator) end end @kill_ring.process else ed_insert(key) unless @config.editing_mode_is?(:vi_command) end end
#prompt_list
[ GitHub ]# File 'lib/reline/line_editor.rb', line 355
def prompt_list with_cache(__method__, whole_lines, check_mode_string, @vi_arg, @searching_prompt) do |lines, mode_string| check_multiline_prompt(lines, mode_string) end end
#quoted_insert(str, arg: 1)
Alias for #ed_quoted_insert.
# File 'lib/reline/line_editor.rb', line 1506
alias_method :quoted_insert, :ed_quoted_insert
#render_differential
[ GitHub ]# File 'lib/reline/line_editor.rb', line 494
def render_differential wrapped_cursor_x, wrapped_cursor_y = wrapped_cursor_position rendered_lines = @rendered_screen.lines new_lines = wrapped_prompt_and_input_lines.flatten(1)[screen_scroll_top, screen_height].map do |prompt, line| prompt_width = Reline::Unicode.calculate_width(prompt, true) [[0, prompt_width, prompt], [prompt_width, Reline::Unicode.calculate_width(line, true), line]] end if @menu_info @menu_info.lines(screen_width).each do |item| new_lines << [[0, Reline::Unicode.calculate_width(item), item]] end @menu_info = nil # TODO: do not change state here end @dialogs.each_with_index do |dialog, index| next unless dialog.contents x_range, y_range = dialog_range dialog, wrapped_cursor_y - screen_scroll_top y_range.each do |row| next if row < 0 || row >= screen_height dialog_rows = new_lines[row] ||= [] # index 0 is for prompt, index 1 is for line, index 2.. is for dialog dialog_rows[index + 2] = [x_range.begin, dialog.width, dialog.contents[row - y_range.begin]] end end cursor_y = @rendered_screen.cursor_y if new_lines != rendered_lines # Hide cursor while rendering to avoid cursor flickering. Reline::IOGate.hide_cursor num_lines = [[new_lines.size, rendered_lines.size].max, screen_height].min if @rendered_screen.base_y + num_lines > screen_height Reline::IOGate.scroll_down(num_lines - cursor_y - 1) @rendered_screen.base_y = screen_height - num_lines cursor_y = num_lines - 1 end num_lines.times do |i| rendered_line = rendered_lines[i] || [] line_to_render = new_lines[i] || [] next if rendered_line == line_to_render Reline::IOGate.move_cursor_down i - cursor_y cursor_y = i unless rendered_lines[i] Reline::IOGate.move_cursor_column 0 Reline::IOGate.erase_after_cursor end render_line_differential(rendered_line, line_to_render) end @rendered_screen.lines = new_lines Reline::IOGate.show_cursor end y = wrapped_cursor_y - screen_scroll_top Reline::IOGate.move_cursor_column wrapped_cursor_x Reline::IOGate.move_cursor_down y - cursor_y @rendered_screen.cursor_y = y new_lines.size - y end
#render_finished
[ GitHub ]# File 'lib/reline/line_editor.rb', line 454
def render_finished clear_rendered_lines render_full_content end
#render_full_content
[ GitHub ]# File 'lib/reline/line_editor.rb', line 476
def render_full_content lines = @buffer_of_lines.size.times.map do |i| line = prompt_list[i] + modified_lines[i] wrapped_lines, = split_by_width(line, screen_width) wrapped_lines.last.empty? ? "#{line} " : line end @output.puts lines.map { |l| "#{l}\r\n" }.join end
#render_line_differential(old_items, new_items)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 404
def render_line_differential(old_items, new_items) old_levels = (old_items.zip(new_items).each_with_index.map {|((x, w, c), (nx, _nw, nc)), i| [x, w, c == nc && x == nx ? i : -1] if x }.compact) new_levels = (new_items.each_with_index.map { |(x, w), i| [x, w, i] if x }.compact).take(screen_width) base_x = 0 new_levels.zip(old_levels).chunk { |n, o| n == o ? :skip : n || :blank }.each do |level, chunk| width = chunk.size if level == :skip # do nothing elsif level == :blank Reline::IOGate.move_cursor_column base_x @output.write "#{Reline::IOGate::RESET_COLOR}#{' ' * width}" else x, w, content = new_items[level] content = Reline::Unicode.take_range(content, base_x - x, width) unless x == base_x && w == width Reline::IOGate.move_cursor_column base_x @output.write "#{Reline::IOGate::RESET_COLOR}#{content}#{Reline::IOGate::RESET_COLOR}" end base_x += width end if old_levels.size > new_levels.size Reline::IOGate.move_cursor_column new_levels.size Reline::IOGate.erase_after_cursor end end
#rerender
[ GitHub ]# File 'lib/reline/line_editor.rb', line 562
def rerender render_differential unless @in_pasting end
#reset(prompt = '', encoding:)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 139
def reset(prompt = '', encoding:) @screen_size = Reline::IOGate.get_screen_size reset_variables(prompt, encoding: encoding) @rendered_screen.base_y = Reline::IOGate.cursor_pos.y 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_line
[ GitHub ]#reset_variables(prompt = '', encoding:)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 223
def reset_variables(prompt = '', encoding:) @prompt = prompt.gsub("\n", "\\n") @mark_pointer = nil @encoding = encoding @is_multiline = false @finished = false @history_pointer = nil @kill_ring ||= Reline::KillRing.new @vi_clipboard = '' @vi_arg = nil @waiting_proc = nil @vi_waiting_operator = nil @vi_waiting_operator_arg = nil @completion_journey_state = nil @completion_state = CompletionState::NORMAL @completion_occurs = false @perfect_matched = nil @menu_info = nil @searching_prompt = nil @first_char = true @just_cursor_moving = false @eof = false @continuous_insertion_buffer = String.new(encoding: @encoding) @scroll_partial_screen = 0 @drop_terminate_spaces = false @in_pasting = false @auto_indent_proc = nil @dialogs = [] @interrupted = false @resized = false @cache = {} @rendered_screen = RenderedScreen.new(base_y: 0, lines: [], cursor_y: 0) reset_line end
#rest_height(wrapped_cursor_y)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 558
def rest_height(wrapped_cursor_y) screen_height - wrapped_cursor_y + screen_scroll_top - @rendered_screen.base_y - 1 end
#retrieve_completion_block(set_completion_quote_character = false)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1254
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 = current_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 = current_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 = current_line.byteslice(i, @byte_pointer - i) break_pointer = i else i += 1 end end postposing = current_line.byteslice(@byte_pointer, current_line.bytesize - @byte_pointer) if rest preposing = current_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 = current_line.byteslice(0, break_pointer) else preposing = '' end target = before end 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 [preposing.encode(@encoding), target.encode(@encoding), postposing.encode(@encoding)] end
#retrieve_completion_journey_state (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 930
private def retrieve_completion_journey_state preposing, target, postposing = retrieve_completion_block list = call_completion_proc return unless list.is_a?(Array) candidates = list.select{ |item| item.start_with?(target) } return if candidates.empty? pre = preposing.split("\n", -1).last || '' post = postposing.split("\n", -1).first || '' CompletionJourneyState.new( @line_index, pre, target, post, [target] + candidates, 0 ) end
#reverse_search_history(key)
Alias for #vi_search_prev.
# File 'lib/reline/line_editor.rb', line 1692
alias_method :reverse_search_history, :vi_search_prev
#run_for_operators(key, method_symbol, &block) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 945
private def run_for_operators(key, method_symbol, &block) if @vi_waiting_operator if VI_MOTIONS.include?(method_symbol) old_byte_pointer = @byte_pointer @vi_arg = (@vi_arg || 1) * @vi_waiting_operator_arg block.(true) unless @waiting_proc byte_pointer_diff = @byte_pointer - old_byte_pointer @byte_pointer = old_byte_pointer send(@vi_waiting_operator, byte_pointer_diff) cleanup_waiting end else # Ignores operator when not motion is given. block.(false) cleanup_waiting end @vi_arg = nil else block.(false) end end
#screen_height
[ GitHub ]# File 'lib/reline/line_editor.rb', line 361
def screen_height @screen_size.first end
#screen_scroll_top
[ GitHub ]# File 'lib/reline/line_editor.rb', line 369
def screen_scroll_top @scroll_partial_screen end
#screen_width
[ GitHub ]# File 'lib/reline/line_editor.rb', line 365
def screen_width @screen_size.last end
#scroll_into_view
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1178
def scroll_into_view _wrapped_cursor_x, wrapped_cursor_y = wrapped_cursor_position if wrapped_cursor_y < screen_scroll_top @scroll_partial_screen = wrapped_cursor_y end if wrapped_cursor_y >= screen_scroll_top + screen_height @scroll_partial_screen = wrapped_cursor_y - screen_height + 1 end end
#search_history(prefix, pointer_range) (private)
[ GitHub ]#search_next_char(key, arg, need_prev_char: false, inclusive: false) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2359
private def search_next_char(key, arg, need_prev_char: false, inclusive: false) if key.instance_of?(String) inputed_char = key else inputed_char = key.chr end prev_total = nil total = nil found = false current_line.byteslice(@byte_pointer..-1).grapheme_clusters.each do |mbchar| # total has [byte_size, cursor] unless total # skip cursor point width = Reline::Unicode.get_mbchar_width(mbchar) total = [mbchar.bytesize, width] else if inputed_char == mbchar arg -= 1 if arg.zero? found = true break end end width = Reline::Unicode.get_mbchar_width(mbchar) prev_total = total total = [total.first + mbchar.bytesize, total.last + width] end end if not need_prev_char and found and total byte_size, _ = total @byte_pointer += byte_size elsif need_prev_char and found and prev_total byte_size, _ = prev_total @byte_pointer += byte_size end if inclusive byte_size = Reline::Unicode.get_next_mbchar_size(current_line, @byte_pointer) if byte_size > 0 @byte_pointer += byte_size end end @waiting_proc = nil end
#search_prev_char(key, arg, need_next_char = false) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2411
private def search_prev_char(key, arg, need_next_char = false) if key.instance_of?(String) inputed_char = key else inputed_char = key.chr end prev_total = nil total = nil found = false current_line.byteslice(0..@byte_pointer).grapheme_clusters.reverse_each do |mbchar| # total has [byte_size, cursor] unless total # skip cursor point width = Reline::Unicode.get_mbchar_width(mbchar) total = [mbchar.bytesize, width] else if inputed_char == mbchar arg -= 1 if arg.zero? found = true break end end width = Reline::Unicode.get_mbchar_width(mbchar) prev_total = total total = [total.first + mbchar.bytesize, total.last + width] end end if not need_next_char and found and total byte_size, _ = total @byte_pointer -= byte_size elsif need_next_char and found and prev_total byte_size, _ = prev_total @byte_pointer -= byte_size end @waiting_proc = nil end
#self_insert(key)
Alias for #ed_insert.
# File 'lib/reline/line_editor.rb', line 1490
alias_method :self_insert, :ed_insert
#set_current_line(line, byte_pointer = nil)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1243
def set_current_line(line, byte_pointer = nil) cursor = current_byte_pointer_cursor @buffer_of_lines[@line_index] = line if byte_pointer @byte_pointer = byte_pointer else calculate_nearest_cursor(cursor) end process_auto_indent end
#set_mark(key)
Alias for #em_set_mark.
# File 'lib/reline/line_editor.rb', line 2461
alias_method :set_mark, :em_set_mark
#set_pasting_state(in_pasting)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 86
def set_pasting_state(in_pasting) # While pasting, text to be inserted is stored to @continuous_insertion_buffer. # After pasting, this buffer should be force inserted. process_insert(force: true) if @in_pasting && !in_pasting @in_pasting = in_pasting end
#set_signal_handlers
[ GitHub ]#split_by_width(str, max_width, offset: 0) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 298
private def split_by_width(str, max_width, offset: 0) Reline::Unicode.split_by_width(str, max_width, @encoding, offset: offset) end
#transpose_chars(key)
Alias for #ed_transpose_chars.
# File 'lib/reline/line_editor.rb', line 1990
alias_method :transpose_chars, :ed_transpose_chars
#transpose_words(key)
Alias for #ed_transpose_words.
# File 'lib/reline/line_editor.rb', line 2003
alias_method :transpose_words, :ed_transpose_words
#unix_line_discard(key)
Alias for #vi_kill_line_prev.
# File 'lib/reline/line_editor.rb', line 1873
alias_method :unix_line_discard, :vi_kill_line_prev
#unix_word_rubout(key)
Alias for #em_kill_region.
# File 'lib/reline/line_editor.rb', line 2049
alias_method :unix_word_rubout, :em_kill_region
#upcase_word(key)
Alias for #em_upper_case.
# File 'lib/reline/line_editor.rb', line 2039
alias_method :upcase_word, :em_upper_case
#update(key)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1105
def update(key) modified = input_key(key) unless @in_pasting scroll_into_view @just_cursor_moving = !modified update_dialogs(key) @just_cursor_moving = false end end
#update_dialogs(key = nil)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 446
def update_dialogs(key = nil) wrapped_cursor_x, wrapped_cursor_y = wrapped_cursor_position @dialogs.each do |dialog| dialog.trap_key = nil update_each_dialog(dialog, wrapped_cursor_x, wrapped_cursor_y - screen_scroll_top, key) end end
#update_each_dialog(dialog, cursor_column, cursor_row, key = nil) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 715
private def update_each_dialog(dialog, cursor_column, cursor_row, key = nil) dialog.set_cursor_pos(cursor_column, cursor_row) dialog_render_info = dialog.call(key) if dialog_render_info.nil? or dialog_render_info.contents.nil? or dialog_render_info.contents.empty? dialog.contents = nil dialog.trap_key = nil return end contents = dialog_render_info.contents pointer = dialog.pointer if dialog_render_info.width dialog.width = dialog_render_info.width else dialog.width = contents.map { |l| calculate_width(l, true) }.max end height = dialog_render_info.height || DIALOG_DEFAULT_HEIGHT height = contents.size if contents.size < height if contents.size > height if dialog.pointer if dialog.pointer < 0 dialog.scroll_top = 0 elsif (dialog.pointer - dialog.scroll_top) >= (height - 1) dialog.scroll_top = dialog.pointer - (height - 1) elsif (dialog.pointer - dialog.scroll_top) < 0 dialog.scroll_top = dialog.pointer end pointer = dialog.pointer - dialog.scroll_top else dialog.scroll_top = 0 end contents = contents[dialog.scroll_top, height] end if dialog_render_info. and dialog_render_info.contents.size > height = height * 2 moving_distance = (dialog_render_info.contents.size - height) * 2 position_ratio = dialog.scroll_top.zero? ? 0.0 : ((dialog.scroll_top * 2).to_f / moving_distance) = ( * ((contents.size * 2).to_f / (dialog_render_info.contents.size * 2))).floor.to_i = MINIMUM_SCROLLBAR_HEIGHT if < MINIMUM_SCROLLBAR_HEIGHT = (( - ) * position_ratio).floor.to_i else = nil end dialog.column = dialog_render_info.pos.x dialog.width += @block_elem_width if diff = (dialog.column + dialog.width) - screen_width if diff > 0 dialog.column -= diff end if rest_height(screen_scroll_top + cursor_row) - dialog_render_info.pos.y >= height dialog.vertical_offset = dialog_render_info.pos.y + 1 elsif cursor_row >= height dialog.vertical_offset = dialog_render_info.pos.y - height else dialog.vertical_offset = dialog_render_info.pos.y + 1 end if dialog.column < 0 dialog.column = 0 dialog.width = screen_width end face = Reline::Face[dialog_render_info.face || :default] = face[: ] default_sgr = face[:default] enhanced_sgr = face[:enhanced] dialog.contents = contents.map.with_index do |item, i| line_sgr = i == pointer ? enhanced_sgr : default_sgr str_width = dialog.width - ( .nil? ? 0 : @block_elem_width) str = padding_space_with_escape_sequences(Reline::Unicode.take_range(item, 0, str_width), str_width) colored_content = "#{line_sgr}#{str}" if if <= (i * 2) and (i * 2 + 1) < ( + ) colored_content + + @full_block elsif <= (i * 2) and (i * 2) < ( + ) colored_content + + @upper_half_block elsif <= (i * 2 + 1) and (i * 2) < ( + ) colored_content + + @lower_half_block else colored_content + + ' ' * @block_elem_width end else colored_content end end end
#upper_space_height(wrapped_cursor_y)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 554
def upper_space_height(wrapped_cursor_y) wrapped_cursor_y - screen_scroll_top end
#vi_add(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2061
private def vi_add(key) @config.editing_mode = :vi_insert ed_next_char(key) end
#vi_add_at_eol(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2157
private def vi_add_at_eol(key) ed_move_to_end(key) @config.editing_mode = :vi_insert end
#vi_change_meta(key, arg: nil) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2176
private def (key, arg: nil) if @vi_waiting_operator set_current_line('', 0) if @vi_waiting_operator == : && arg.nil? @vi_waiting_operator = nil @vi_waiting_operator_arg = nil else @drop_terminate_spaces = true @vi_waiting_operator = : @vi_waiting_operator_arg = arg || 1 end end
#vi_change_meta_confirm(byte_pointer_diff) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2188
private def (byte_pointer_diff) (byte_pointer_diff) @config.editing_mode = :vi_insert @drop_terminate_spaces = false end
#vi_change_to_eol(key) (private)
- Editline
-
vi_change_to_eol
(vi command:C
) + Kill and change from the cursor to the end of the line.
# File 'lib/reline/line_editor.rb', line 1855
private def vi_change_to_eol(key) ed_kill_line(key) @config.editing_mode = :vi_insert end
#vi_command_mode(key) (private) Also known as: #vi_movement_mode
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2066
private def vi_command_mode(key) ed_prev_char(key) @config.editing_mode = :vi_command end
#vi_delete_meta(key, arg: nil) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2194
private def (key, arg: nil) if @vi_waiting_operator set_current_line('', 0) if @vi_waiting_operator == : && arg.nil? @vi_waiting_operator = nil @vi_waiting_operator_arg = nil else @vi_waiting_operator = : @vi_waiting_operator_arg = arg || 1 end end
#vi_delete_meta_confirm(byte_pointer_diff) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2205
private def (byte_pointer_diff) if byte_pointer_diff > 0 line, cut = byteslice!(current_line, @byte_pointer, byte_pointer_diff) elsif byte_pointer_diff < 0 line, cut = byteslice!(current_line, @byte_pointer + byte_pointer_diff, -byte_pointer_diff) end copy_for_vi(cut) set_current_line(line || '', @byte_pointer + (byte_pointer_diff < 0 ? byte_pointer_diff : 0)) end
#vi_delete_prev_char(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2138
private def vi_delete_prev_char(key) if @byte_pointer == 0 and @line_index > 0 @byte_pointer = @buffer_of_lines[@line_index - 1].bytesize @buffer_of_lines[@line_index - 1] += @buffer_of_lines.delete_at(@line_index) @line_index -= 1 process_auto_indent cursor_dependent: false elsif @byte_pointer > 0 byte_size = Reline::Unicode.get_prev_mbchar_size(current_line, @byte_pointer) @byte_pointer -= byte_size line, _ = byteslice!(current_line, @byte_pointer, byte_size) set_current_line(line) end end
#vi_editing_mode(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2475
private def vi_editing_mode(key) @config.editing_mode = :vi_insert end
#vi_end_big_word(key, arg: 1, inclusive: false) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2123
private def vi_end_big_word(key, arg: 1, inclusive: false) if current_line.bytesize > @byte_pointer byte_size, _ = Reline::Unicode.vi_big_forward_end_word(current_line, @byte_pointer) @byte_pointer += byte_size end arg -= 1 if inclusive and arg.zero? byte_size = Reline::Unicode.get_next_mbchar_size(current_line, @byte_pointer) if byte_size > 0 @byte_pointer += byte_size end end vi_end_big_word(key, arg: arg) if arg > 0 end
#vi_end_of_transmission(key)
Alias for #vi_list_or_eof.
# File 'lib/reline/line_editor.rb', line 2244
alias_method :vi_end_of_transmission, :vi_list_or_eof
#vi_end_word(key, arg: 1, inclusive: false) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2090
private def vi_end_word(key, arg: 1, inclusive: false) if current_line.bytesize > @byte_pointer byte_size, _ = Reline::Unicode.vi_forward_end_word(current_line, @byte_pointer) @byte_pointer += byte_size end arg -= 1 if inclusive and arg.zero? byte_size = Reline::Unicode.get_next_mbchar_size(current_line, @byte_pointer) if byte_size > 0 @byte_pointer += byte_size end end vi_end_word(key, arg: arg) if arg > 0 end
#vi_eof_maybe(key)
Alias for #vi_list_or_eof.
# File 'lib/reline/line_editor.rb', line 2245
alias_method :vi_eof_maybe, :vi_list_or_eof
#vi_first_print(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1534
private def vi_first_print(key) @byte_pointer, = Reline::Unicode.vi_first_print(current_line) end
#vi_histedit(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2270
private def vi_histedit(key) path = Tempfile.open { |fp| fp.write whole_lines.join("\n") fp.path } system("#{ENV['EDITOR']} #{path}") @buffer_of_lines = File.read(path).split("\n") @buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty? @line_index = 0 finish end
#vi_insert(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2057
private def vi_insert(key) @config.editing_mode = :vi_insert end
#vi_insert_at_bol(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2152
private def vi_insert_at_bol(key) ed_move_to_beg(key) @config.editing_mode = :vi_insert end
#vi_join_lines(key, arg: 1) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2449
private def vi_join_lines(key, arg: 1) if @buffer_of_lines.size > @line_index + 1 next_line = @buffer_of_lines.delete_at(@line_index + 1).lstrip set_current_line(current_line + ' ' + next_line, current_line.bytesize) end arg -= 1 vi_join_lines(key, arg: arg) if arg > 0 end
#vi_kill_line_prev(key) (private) Also known as: #unix_line_discard
- Editline
-
vi-kill-line-prev
(vi:Ctrl-U
) Delete the string from the beginning of the edit buffer to the cursor and save it to the cut buffer. - GNU Readline
-
unix-line-discard
(C-u
) Kill backward from the cursor to the beginning of the current line.
# File 'lib/reline/line_editor.rb', line 1866
private def vi_kill_line_prev(key) if @byte_pointer > 0 line, deleted = byteslice!(current_line, 0, @byte_pointer) set_current_line(line, 0) @kill_ring.append(deleted, true) end end
#vi_list_or_eof(key) (private) Also known as: #vi_end_of_transmission, #vi_eof_maybe
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2235
private def vi_list_or_eof(key) if current_line.empty? and @buffer_of_lines.size == 1 set_current_line('', 0) @eof = true finish else ed_newline(key) end end
#vi_movement_mode(key)
Alias for #vi_command_mode.
# File 'lib/reline/line_editor.rb', line 2070
alias_method :vi_movement_mode, :vi_command_mode
#vi_next_big_word(key, arg: 1) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2105
private def vi_next_big_word(key, arg: 1) if current_line.bytesize > @byte_pointer byte_size, _ = Reline::Unicode.vi_big_forward_word(current_line, @byte_pointer) @byte_pointer += byte_size end arg -= 1 vi_next_big_word(key, arg: arg) if arg > 0 end
#vi_next_char(key, arg: 1, inclusive: false) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2351
private def vi_next_char(key, arg: 1, inclusive: false) @waiting_proc = ->(key_for_proc) { search_next_char(key_for_proc, arg, inclusive: inclusive) } end
#vi_next_word(key, arg: 1) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2072
private def vi_next_word(key, arg: 1) if current_line.bytesize > @byte_pointer byte_size, _ = Reline::Unicode.vi_forward_word(current_line, @byte_pointer, @drop_terminate_spaces) @byte_pointer += byte_size end arg -= 1 vi_next_word(key, arg: arg) if arg > 0 end
#vi_paste_next(key, arg: 1) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2291
private def vi_paste_next(key, arg: 1) if @vi_clipboard.size > 0 byte_size = Reline::Unicode.get_next_mbchar_size(current_line, @byte_pointer) line = byteinsert(current_line, @byte_pointer + byte_size, @vi_clipboard) set_current_line(line, @byte_pointer + @vi_clipboard.bytesize) end arg -= 1 vi_paste_next(key, arg: arg) if arg > 0 end
#vi_paste_prev(key, arg: 1) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2282
private def vi_paste_prev(key, arg: 1) if @vi_clipboard.size > 0 cursor_point = @vi_clipboard.grapheme_clusters[0..-2].join set_current_line(byteinsert(current_line, @byte_pointer, @vi_clipboard), @byte_pointer + cursor_point.bytesize) end arg -= 1 vi_paste_prev(key, arg: arg) if arg > 0 end
#vi_prev_big_word(key, arg: 1) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2114
private def vi_prev_big_word(key, arg: 1) if @byte_pointer > 0 byte_size, _ = Reline::Unicode.vi_big_backward_word(current_line, @byte_pointer) @byte_pointer -= byte_size end arg -= 1 vi_prev_big_word(key, arg: arg) if arg > 0 end
#vi_prev_char(key, arg: 1) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2403
private def vi_prev_char(key, arg: 1) @waiting_proc = ->(key_for_proc) { search_prev_char(key_for_proc, arg) } end
#vi_prev_word(key, arg: 1) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2081
private def vi_prev_word(key, arg: 1) if @byte_pointer > 0 byte_size, _ = Reline::Unicode.vi_backward_word(current_line, @byte_pointer) @byte_pointer -= byte_size end arg -= 1 vi_prev_word(key, arg: arg) if arg > 0 end
#vi_replace_char(key, arg: 1) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2327
private def vi_replace_char(key, arg: 1) @waiting_proc = ->(k) { if arg == 1 byte_size = Reline::Unicode.get_next_mbchar_size(current_line, @byte_pointer) before = current_line.byteslice(0, @byte_pointer) remaining_point = @byte_pointer + byte_size after = current_line.byteslice(remaining_point, current_line.bytesize - remaining_point) set_current_line(before + k.chr + after) @waiting_proc = nil elsif arg > 1 byte_size = 0 arg.times do byte_size += Reline::Unicode.get_next_mbchar_size(current_line, @byte_pointer + byte_size) end before = current_line.byteslice(0, @byte_pointer) remaining_point = @byte_pointer + byte_size after = current_line.byteslice(remaining_point, current_line.bytesize - remaining_point) replaced = k.chr * arg set_current_line(before + replaced + after, @byte_pointer + replaced.bytesize) @waiting_proc = nil end } end
#vi_search_next(key) (private) Also known as: #forward_search_history
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1694
private def vi_search_next(key) incremental_search_history(key) end
#vi_search_prev(key) (private) Also known as: #reverse_search_history
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1689
private def vi_search_prev(key) incremental_search_history(key) end
#vi_to_column(key, arg: 0) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2318
private def vi_to_column(key, arg: 0) # Implementing behavior of vi, not Readline's vi-mode. @byte_pointer, = current_line.grapheme_clusters.inject([0, 0]) { |(total_byte_size, total_width), gc| mbchar_width = Reline::Unicode.get_mbchar_width(gc) break [total_byte_size, total_width] if (total_width + mbchar_width) >= arg [total_byte_size + gc.bytesize, total_width + mbchar_width] } end
#vi_to_history_line(key) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2263
private def vi_to_history_line(key) if Reline::HISTORY.empty? return end move_history(0, line: :start, cursor: :start) end
#vi_to_next_char(key, arg: 1, inclusive: false) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2355
private def vi_to_next_char(key, arg: 1, inclusive: false) @waiting_proc = ->(key_for_proc) { search_next_char(key_for_proc, arg, need_prev_char: true, inclusive: inclusive) } end
#vi_to_prev_char(key, arg: 1) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2407
private def vi_to_prev_char(key, arg: 1) @waiting_proc = ->(key_for_proc) { search_prev_char(key_for_proc, arg, true) } end
#vi_yank(key, arg: nil) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2215
private def vi_yank(key, arg: nil) if @vi_waiting_operator copy_for_vi(current_line) if @vi_waiting_operator == :vi_yank_confirm && arg.nil? @vi_waiting_operator = nil @vi_waiting_operator_arg = nil else @vi_waiting_operator = :vi_yank_confirm @vi_waiting_operator_arg = arg || 1 end end
#vi_yank_confirm(byte_pointer_diff) (private)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 2226
private def vi_yank_confirm(byte_pointer_diff) if byte_pointer_diff > 0 cut = current_line.byteslice(@byte_pointer, byte_pointer_diff) elsif byte_pointer_diff < 0 cut = current_line.byteslice(@byte_pointer + byte_pointer_diff, -byte_pointer_diff) end copy_for_vi(cut) end
#vi_zero(key)
Alias for #ed_move_to_beg.
# File 'lib/reline/line_editor.rb', line 1542
alias_method :vi_zero, :ed_move_to_beg
#whole_buffer
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1387
def whole_buffer whole_lines.join("\n") end
#whole_lines
[ GitHub ]# File 'lib/reline/line_editor.rb', line 1383
def whole_lines @buffer_of_lines.dup end
#with_cache(key, *deps)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 341
def with_cache(key, *deps) cached_deps, value = @cache[key] if cached_deps != deps @cache[key] = [deps, value = yield(*deps, cached_deps, value)] end value end
#wrap_method_call(method_symbol, method_obj, key, with_operator = false)
[ GitHub ]# File 'lib/reline/line_editor.rb', line 978
def wrap_method_call(method_symbol, method_obj, key, with_operator = false) if @config.editing_mode_is?(:emacs, :vi_insert) and @vi_waiting_operator.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
#wrapped_cursor_position
Calculate cursor position in word wrapped content.
# File 'lib/reline/line_editor.rb', line 430
def wrapped_cursor_position prompt_width = calculate_width(prompt_list[@line_index], true) line_before_cursor = whole_lines[@line_index].byteslice(0, @byte_pointer) wrapped_line_before_cursor = split_by_width(' ' * prompt_width + line_before_cursor, screen_width).first.compact wrapped_cursor_y = wrapped_prompt_and_input_lines[0...@line_index].sum(&:size) + wrapped_line_before_cursor.size - 1 wrapped_cursor_x = calculate_width(wrapped_line_before_cursor.last) [wrapped_cursor_x, wrapped_cursor_y] end
#wrapped_prompt_and_input_lines
[ GitHub ]# File 'lib/reline/line_editor.rb', line 373
def wrapped_prompt_and_input_lines with_cache(__method__, @buffer_of_lines.size, modified_lines, prompt_list, screen_width) do |n, lines, prompts, width, prev_cache_key, cached_value| prev_n, prev_lines, prev_prompts, prev_width = prev_cache_key cached_wraps = {} if prev_width == width prev_n.times do |i| cached_wraps[[prev_prompts[i], prev_lines[i]]] = cached_value[i] end end n.times.map do |i| prompt = prompts[i] || '' line = lines[i] || '' if (cached = cached_wraps[[prompt, line]]) next cached end *wrapped_prompts, code_line_prompt = split_by_width(prompt, width).first.compact wrapped_lines = split_by_width(line, width, offset: calculate_width(code_line_prompt)).first.compact wrapped_prompts.map { |p| [p, ''] } + [[code_line_prompt, wrapped_lines.first]] + wrapped_lines.drop(1).map { |c| ['', c] } end end end
#yank(key)
Alias for #em_yank.
# File 'lib/reline/line_editor.rb', line 1918
alias_method :yank, :em_yank
#yank_pop(key)
Alias for #em_yank_pop.
# File 'lib/reline/line_editor.rb', line 1928
alias_method :yank_pop, :em_yank_pop