Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../opt/alt/ruby27/share/ruby
File: reline.rb
require 'io/console'
[0] Fix | Delete
require 'timeout'
[1] Fix | Delete
require 'forwardable'
[2] Fix | Delete
require 'reline/version'
[3] Fix | Delete
require 'reline/config'
[4] Fix | Delete
require 'reline/key_actor'
[5] Fix | Delete
require 'reline/key_stroke'
[6] Fix | Delete
require 'reline/line_editor'
[7] Fix | Delete
require 'reline/history'
[8] Fix | Delete
require 'rbconfig'
[9] Fix | Delete
[10] Fix | Delete
module Reline
[11] Fix | Delete
FILENAME_COMPLETION_PROC = nil
[12] Fix | Delete
USERNAME_COMPLETION_PROC = nil
[13] Fix | Delete
[14] Fix | Delete
Key = Struct.new('Key', :char, :combined_char, :with_meta)
[15] Fix | Delete
CursorPos = Struct.new(:x, :y)
[16] Fix | Delete
[17] Fix | Delete
class Core
[18] Fix | Delete
ATTR_READER_NAMES = %i(
[19] Fix | Delete
completion_append_character
[20] Fix | Delete
basic_word_break_characters
[21] Fix | Delete
completer_word_break_characters
[22] Fix | Delete
basic_quote_characters
[23] Fix | Delete
completer_quote_characters
[24] Fix | Delete
filename_quote_characters
[25] Fix | Delete
special_prefixes
[26] Fix | Delete
completion_proc
[27] Fix | Delete
output_modifier_proc
[28] Fix | Delete
prompt_proc
[29] Fix | Delete
auto_indent_proc
[30] Fix | Delete
pre_input_hook
[31] Fix | Delete
dig_perfect_match_proc
[32] Fix | Delete
).each(&method(:attr_reader))
[33] Fix | Delete
[34] Fix | Delete
attr_accessor :config
[35] Fix | Delete
attr_accessor :key_stroke
[36] Fix | Delete
attr_accessor :line_editor
[37] Fix | Delete
attr_accessor :ambiguous_width
[38] Fix | Delete
attr_accessor :last_incremental_search
[39] Fix | Delete
attr_reader :output
[40] Fix | Delete
[41] Fix | Delete
def initialize
[42] Fix | Delete
self.output = STDOUT
[43] Fix | Delete
yield self
[44] Fix | Delete
@completion_quote_character = nil
[45] Fix | Delete
end
[46] Fix | Delete
[47] Fix | Delete
def encoding
[48] Fix | Delete
Reline::IOGate.encoding
[49] Fix | Delete
end
[50] Fix | Delete
[51] Fix | Delete
def completion_append_character=(val)
[52] Fix | Delete
if val.nil?
[53] Fix | Delete
@completion_append_character = nil
[54] Fix | Delete
elsif val.size == 1
[55] Fix | Delete
@completion_append_character = val.encode(Reline::IOGate.encoding)
[56] Fix | Delete
elsif val.size > 1
[57] Fix | Delete
@completion_append_character = val[0].encode(Reline::IOGate.encoding)
[58] Fix | Delete
else
[59] Fix | Delete
@completion_append_character = nil
[60] Fix | Delete
end
[61] Fix | Delete
end
[62] Fix | Delete
[63] Fix | Delete
def basic_word_break_characters=(v)
[64] Fix | Delete
@basic_word_break_characters = v.encode(Reline::IOGate.encoding)
[65] Fix | Delete
end
[66] Fix | Delete
[67] Fix | Delete
def completer_word_break_characters=(v)
[68] Fix | Delete
@completer_word_break_characters = v.encode(Reline::IOGate.encoding)
[69] Fix | Delete
end
[70] Fix | Delete
[71] Fix | Delete
def basic_quote_characters=(v)
[72] Fix | Delete
@basic_quote_characters = v.encode(Reline::IOGate.encoding)
[73] Fix | Delete
end
[74] Fix | Delete
[75] Fix | Delete
def completer_quote_characters=(v)
[76] Fix | Delete
@completer_quote_characters = v.encode(Reline::IOGate.encoding)
[77] Fix | Delete
end
[78] Fix | Delete
[79] Fix | Delete
def filename_quote_characters=(v)
[80] Fix | Delete
@filename_quote_characters = v.encode(Reline::IOGate.encoding)
[81] Fix | Delete
end
[82] Fix | Delete
[83] Fix | Delete
def special_prefixes=(v)
[84] Fix | Delete
@special_prefixes = v.encode(Reline::IOGate.encoding)
[85] Fix | Delete
end
[86] Fix | Delete
[87] Fix | Delete
def completion_case_fold=(v)
[88] Fix | Delete
@config.completion_ignore_case = v
[89] Fix | Delete
end
[90] Fix | Delete
[91] Fix | Delete
def completion_case_fold
[92] Fix | Delete
@config.completion_ignore_case
[93] Fix | Delete
end
[94] Fix | Delete
[95] Fix | Delete
def completion_quote_character
[96] Fix | Delete
@completion_quote_character
[97] Fix | Delete
end
[98] Fix | Delete
[99] Fix | Delete
def completion_proc=(p)
[100] Fix | Delete
raise ArgumentError unless p.respond_to?(:call) or p.nil?
[101] Fix | Delete
@completion_proc = p
[102] Fix | Delete
end
[103] Fix | Delete
[104] Fix | Delete
def output_modifier_proc=(p)
[105] Fix | Delete
raise ArgumentError unless p.respond_to?(:call) or p.nil?
[106] Fix | Delete
@output_modifier_proc = p
[107] Fix | Delete
end
[108] Fix | Delete
[109] Fix | Delete
def prompt_proc=(p)
[110] Fix | Delete
raise ArgumentError unless p.respond_to?(:call) or p.nil?
[111] Fix | Delete
@prompt_proc = p
[112] Fix | Delete
end
[113] Fix | Delete
[114] Fix | Delete
def auto_indent_proc=(p)
[115] Fix | Delete
raise ArgumentError unless p.respond_to?(:call) or p.nil?
[116] Fix | Delete
@auto_indent_proc = p
[117] Fix | Delete
end
[118] Fix | Delete
[119] Fix | Delete
def pre_input_hook=(p)
[120] Fix | Delete
@pre_input_hook = p
[121] Fix | Delete
end
[122] Fix | Delete
[123] Fix | Delete
def dig_perfect_match_proc=(p)
[124] Fix | Delete
raise ArgumentError unless p.respond_to?(:call) or p.nil?
[125] Fix | Delete
@dig_perfect_match_proc = p
[126] Fix | Delete
end
[127] Fix | Delete
[128] Fix | Delete
def input=(val)
[129] Fix | Delete
raise TypeError unless val.respond_to?(:getc) or val.nil?
[130] Fix | Delete
if val.respond_to?(:getc)
[131] Fix | Delete
if defined?(Reline::ANSI) and Reline::IOGate == Reline::ANSI
[132] Fix | Delete
Reline::ANSI.input = val
[133] Fix | Delete
elsif Reline::IOGate == Reline::GeneralIO
[134] Fix | Delete
Reline::GeneralIO.input = val
[135] Fix | Delete
end
[136] Fix | Delete
end
[137] Fix | Delete
end
[138] Fix | Delete
[139] Fix | Delete
def output=(val)
[140] Fix | Delete
raise TypeError unless val.respond_to?(:write) or val.nil?
[141] Fix | Delete
@output = val
[142] Fix | Delete
if defined?(Reline::ANSI) and Reline::IOGate == Reline::ANSI
[143] Fix | Delete
Reline::ANSI.output = val
[144] Fix | Delete
end
[145] Fix | Delete
end
[146] Fix | Delete
[147] Fix | Delete
def vi_editing_mode
[148] Fix | Delete
config.editing_mode = :vi_insert
[149] Fix | Delete
nil
[150] Fix | Delete
end
[151] Fix | Delete
[152] Fix | Delete
def emacs_editing_mode
[153] Fix | Delete
config.editing_mode = :emacs
[154] Fix | Delete
nil
[155] Fix | Delete
end
[156] Fix | Delete
[157] Fix | Delete
def vi_editing_mode?
[158] Fix | Delete
config.editing_mode_is?(:vi_insert, :vi_command)
[159] Fix | Delete
end
[160] Fix | Delete
[161] Fix | Delete
def emacs_editing_mode?
[162] Fix | Delete
config.editing_mode_is?(:emacs)
[163] Fix | Delete
end
[164] Fix | Delete
[165] Fix | Delete
def get_screen_size
[166] Fix | Delete
Reline::IOGate.get_screen_size
[167] Fix | Delete
end
[168] Fix | Delete
[169] Fix | Delete
def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
[170] Fix | Delete
unless confirm_multiline_termination
[171] Fix | Delete
raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
[172] Fix | Delete
end
[173] Fix | Delete
inner_readline(prompt, add_hist, true, &confirm_multiline_termination)
[174] Fix | Delete
[175] Fix | Delete
whole_buffer = line_editor.whole_buffer.dup
[176] Fix | Delete
whole_buffer.taint if RUBY_VERSION < '2.7'
[177] Fix | Delete
if add_hist and whole_buffer and whole_buffer.chomp("\n").size > 0
[178] Fix | Delete
Reline::HISTORY << whole_buffer
[179] Fix | Delete
end
[180] Fix | Delete
[181] Fix | Delete
line_editor.reset_line if line_editor.whole_buffer.nil?
[182] Fix | Delete
whole_buffer
[183] Fix | Delete
end
[184] Fix | Delete
[185] Fix | Delete
def readline(prompt = '', add_hist = false)
[186] Fix | Delete
inner_readline(prompt, add_hist, false)
[187] Fix | Delete
[188] Fix | Delete
line = line_editor.line.dup
[189] Fix | Delete
line.taint if RUBY_VERSION < '2.7'
[190] Fix | Delete
if add_hist and line and line.chomp("\n").size > 0
[191] Fix | Delete
Reline::HISTORY << line.chomp("\n")
[192] Fix | Delete
end
[193] Fix | Delete
[194] Fix | Delete
line_editor.reset_line if line_editor.line.nil?
[195] Fix | Delete
line
[196] Fix | Delete
end
[197] Fix | Delete
[198] Fix | Delete
private def inner_readline(prompt, add_hist, multiline, &confirm_multiline_termination)
[199] Fix | Delete
if ENV['RELINE_STDERR_TTY']
[200] Fix | Delete
$stderr.reopen(ENV['RELINE_STDERR_TTY'], 'w')
[201] Fix | Delete
$stderr.sync = true
[202] Fix | Delete
$stderr.puts "Reline is used by #{Process.pid}"
[203] Fix | Delete
end
[204] Fix | Delete
otio = Reline::IOGate.prep
[205] Fix | Delete
[206] Fix | Delete
may_req_ambiguous_char_width
[207] Fix | Delete
line_editor.reset(prompt, encoding: Reline::IOGate.encoding)
[208] Fix | Delete
if multiline
[209] Fix | Delete
line_editor.multiline_on
[210] Fix | Delete
if block_given?
[211] Fix | Delete
line_editor.confirm_multiline_termination_proc = confirm_multiline_termination
[212] Fix | Delete
end
[213] Fix | Delete
else
[214] Fix | Delete
line_editor.multiline_off
[215] Fix | Delete
end
[216] Fix | Delete
line_editor.output = output
[217] Fix | Delete
line_editor.completion_proc = completion_proc
[218] Fix | Delete
line_editor.completion_append_character = completion_append_character
[219] Fix | Delete
line_editor.output_modifier_proc = output_modifier_proc
[220] Fix | Delete
line_editor.prompt_proc = prompt_proc
[221] Fix | Delete
line_editor.auto_indent_proc = auto_indent_proc
[222] Fix | Delete
line_editor.dig_perfect_match_proc = dig_perfect_match_proc
[223] Fix | Delete
line_editor.pre_input_hook = pre_input_hook
[224] Fix | Delete
[225] Fix | Delete
unless config.test_mode
[226] Fix | Delete
config.read
[227] Fix | Delete
config.reset_default_key_bindings
[228] Fix | Delete
Reline::IOGate::RAW_KEYSTROKE_CONFIG.each_pair do |key, func|
[229] Fix | Delete
config.add_default_key_binding(key, func)
[230] Fix | Delete
end
[231] Fix | Delete
end
[232] Fix | Delete
[233] Fix | Delete
line_editor.rerender
[234] Fix | Delete
[235] Fix | Delete
begin
[236] Fix | Delete
loop do
[237] Fix | Delete
read_io(config.keyseq_timeout) { |inputs|
[238] Fix | Delete
inputs.each { |c|
[239] Fix | Delete
line_editor.input_key(c)
[240] Fix | Delete
line_editor.rerender
[241] Fix | Delete
}
[242] Fix | Delete
}
[243] Fix | Delete
break if line_editor.finished?
[244] Fix | Delete
end
[245] Fix | Delete
Reline::IOGate.move_cursor_column(0)
[246] Fix | Delete
rescue Errno::EIO
[247] Fix | Delete
# Maybe the I/O has been closed.
[248] Fix | Delete
rescue StandardError => e
[249] Fix | Delete
line_editor.finalize
[250] Fix | Delete
Reline::IOGate.deprep(otio)
[251] Fix | Delete
raise e
[252] Fix | Delete
end
[253] Fix | Delete
[254] Fix | Delete
line_editor.finalize
[255] Fix | Delete
Reline::IOGate.deprep(otio)
[256] Fix | Delete
end
[257] Fix | Delete
[258] Fix | Delete
# Keystrokes of GNU Readline will timeout it with the specification of
[259] Fix | Delete
# "keyseq-timeout" when waiting for the 2nd character after the 1st one.
[260] Fix | Delete
# If the 2nd character comes after 1st ESC without timeout it has a
[261] Fix | Delete
# meta-property of meta-key to discriminate modified key with meta-key
[262] Fix | Delete
# from multibyte characters that come with 8th bit on.
[263] Fix | Delete
#
[264] Fix | Delete
# GNU Readline will wait for the 2nd character with "keyseq-timeout"
[265] Fix | Delete
# milli-seconds but wait forever after 3rd characters.
[266] Fix | Delete
private def read_io(keyseq_timeout, &block)
[267] Fix | Delete
buffer = []
[268] Fix | Delete
loop do
[269] Fix | Delete
c = Reline::IOGate.getc
[270] Fix | Delete
buffer << c
[271] Fix | Delete
result = key_stroke.match_status(buffer)
[272] Fix | Delete
case result
[273] Fix | Delete
when :matched
[274] Fix | Delete
expanded = key_stroke.expand(buffer).map{ |expanded_c|
[275] Fix | Delete
Reline::Key.new(expanded_c, expanded_c, false)
[276] Fix | Delete
}
[277] Fix | Delete
block.(expanded)
[278] Fix | Delete
break
[279] Fix | Delete
when :matching
[280] Fix | Delete
if buffer.size == 1
[281] Fix | Delete
begin
[282] Fix | Delete
succ_c = nil
[283] Fix | Delete
Timeout.timeout(keyseq_timeout / 1000.0) {
[284] Fix | Delete
succ_c = Reline::IOGate.getc
[285] Fix | Delete
}
[286] Fix | Delete
rescue Timeout::Error # cancel matching only when first byte
[287] Fix | Delete
block.([Reline::Key.new(c, c, false)])
[288] Fix | Delete
break
[289] Fix | Delete
else
[290] Fix | Delete
if key_stroke.match_status(buffer.dup.push(succ_c)) == :unmatched
[291] Fix | Delete
if c == "\e".ord
[292] Fix | Delete
block.([Reline::Key.new(succ_c, succ_c | 0b10000000, true)])
[293] Fix | Delete
else
[294] Fix | Delete
block.([Reline::Key.new(c, c, false), Reline::Key.new(succ_c, succ_c, false)])
[295] Fix | Delete
end
[296] Fix | Delete
break
[297] Fix | Delete
else
[298] Fix | Delete
Reline::IOGate.ungetc(succ_c)
[299] Fix | Delete
end
[300] Fix | Delete
end
[301] Fix | Delete
end
[302] Fix | Delete
when :unmatched
[303] Fix | Delete
if buffer.size == 1 and c == "\e".ord
[304] Fix | Delete
read_escaped_key(keyseq_timeout, c, block)
[305] Fix | Delete
else
[306] Fix | Delete
expanded = buffer.map{ |expanded_c|
[307] Fix | Delete
Reline::Key.new(expanded_c, expanded_c, false)
[308] Fix | Delete
}
[309] Fix | Delete
block.(expanded)
[310] Fix | Delete
end
[311] Fix | Delete
break
[312] Fix | Delete
end
[313] Fix | Delete
end
[314] Fix | Delete
end
[315] Fix | Delete
[316] Fix | Delete
private def read_escaped_key(keyseq_timeout, c, block)
[317] Fix | Delete
begin
[318] Fix | Delete
escaped_c = nil
[319] Fix | Delete
Timeout.timeout(keyseq_timeout / 1000.0) {
[320] Fix | Delete
escaped_c = Reline::IOGate.getc
[321] Fix | Delete
}
[322] Fix | Delete
rescue Timeout::Error # independent ESC
[323] Fix | Delete
block.([Reline::Key.new(c, c, false)])
[324] Fix | Delete
else
[325] Fix | Delete
if escaped_c.nil?
[326] Fix | Delete
block.([Reline::Key.new(c, c, false)])
[327] Fix | Delete
elsif escaped_c >= 128 # maybe, first byte of multi byte
[328] Fix | Delete
block.([Reline::Key.new(c, c, false), Reline::Key.new(escaped_c, escaped_c, false)])
[329] Fix | Delete
elsif escaped_c == "\e".ord # escape twice
[330] Fix | Delete
block.([Reline::Key.new(c, c, false), Reline::Key.new(c, c, false)])
[331] Fix | Delete
else
[332] Fix | Delete
block.([Reline::Key.new(escaped_c, escaped_c | 0b10000000, true)])
[333] Fix | Delete
end
[334] Fix | Delete
end
[335] Fix | Delete
end
[336] Fix | Delete
[337] Fix | Delete
private def may_req_ambiguous_char_width
[338] Fix | Delete
@ambiguous_width = 2 if Reline::IOGate == Reline::GeneralIO or STDOUT.is_a?(File)
[339] Fix | Delete
return if ambiguous_width
[340] Fix | Delete
Reline::IOGate.move_cursor_column(0)
[341] Fix | Delete
begin
[342] Fix | Delete
output.write "\u{25bd}"
[343] Fix | Delete
rescue Encoding::UndefinedConversionError
[344] Fix | Delete
# LANG=C
[345] Fix | Delete
@ambiguous_width = 1
[346] Fix | Delete
else
[347] Fix | Delete
@ambiguous_width = Reline::IOGate.cursor_pos.x
[348] Fix | Delete
end
[349] Fix | Delete
Reline::IOGate.move_cursor_column(0)
[350] Fix | Delete
Reline::IOGate.erase_after_cursor
[351] Fix | Delete
end
[352] Fix | Delete
end
[353] Fix | Delete
[354] Fix | Delete
extend Forwardable
[355] Fix | Delete
extend SingleForwardable
[356] Fix | Delete
[357] Fix | Delete
#--------------------------------------------------------
[358] Fix | Delete
# Documented API
[359] Fix | Delete
#--------------------------------------------------------
[360] Fix | Delete
[361] Fix | Delete
(Core::ATTR_READER_NAMES).each { |name|
[362] Fix | Delete
def_single_delegators :core, "#{name}", "#{name}="
[363] Fix | Delete
}
[364] Fix | Delete
def_single_delegators :core, :input=, :output=
[365] Fix | Delete
def_single_delegators :core, :vi_editing_mode, :emacs_editing_mode
[366] Fix | Delete
def_single_delegators :core, :readline
[367] Fix | Delete
def_single_delegators :core, :completion_case_fold, :completion_case_fold=
[368] Fix | Delete
def_single_delegators :core, :completion_quote_character
[369] Fix | Delete
def_instance_delegators self, :readline
[370] Fix | Delete
private :readline
[371] Fix | Delete
[372] Fix | Delete
[373] Fix | Delete
#--------------------------------------------------------
[374] Fix | Delete
# Undocumented API
[375] Fix | Delete
#--------------------------------------------------------
[376] Fix | Delete
[377] Fix | Delete
# Testable in original
[378] Fix | Delete
def_single_delegators :core, :get_screen_size
[379] Fix | Delete
def_single_delegators :line_editor, :eof?
[380] Fix | Delete
def_instance_delegators self, :eof?
[381] Fix | Delete
def_single_delegators :line_editor, :delete_text
[382] Fix | Delete
def_single_delegator :line_editor, :line, :line_buffer
[383] Fix | Delete
def_single_delegator :line_editor, :byte_pointer, :point
[384] Fix | Delete
def_single_delegator :line_editor, :byte_pointer=, :point=
[385] Fix | Delete
[386] Fix | Delete
def self.insert_text(*args, &block)
[387] Fix | Delete
line_editor.insert_text(*args, &block)
[388] Fix | Delete
self
[389] Fix | Delete
end
[390] Fix | Delete
[391] Fix | Delete
# Untestable in original
[392] Fix | Delete
def_single_delegator :line_editor, :rerender, :redisplay
[393] Fix | Delete
def_single_delegators :core, :vi_editing_mode?, :emacs_editing_mode?
[394] Fix | Delete
def_single_delegators :core, :ambiguous_width
[395] Fix | Delete
def_single_delegators :core, :last_incremental_search
[396] Fix | Delete
def_single_delegators :core, :last_incremental_search=
[397] Fix | Delete
[398] Fix | Delete
def_single_delegators :core, :readmultiline
[399] Fix | Delete
def_instance_delegators self, :readmultiline
[400] Fix | Delete
private :readmultiline
[401] Fix | Delete
[402] Fix | Delete
def self.encoding_system_needs
[403] Fix | Delete
self.core.encoding
[404] Fix | Delete
end
[405] Fix | Delete
[406] Fix | Delete
def self.core
[407] Fix | Delete
@core ||= Core.new { |core|
[408] Fix | Delete
core.config = Reline::Config.new
[409] Fix | Delete
core.key_stroke = Reline::KeyStroke.new(core.config)
[410] Fix | Delete
core.line_editor = Reline::LineEditor.new(core.config, Reline::IOGate.encoding)
[411] Fix | Delete
[412] Fix | Delete
core.basic_word_break_characters = " \t\n`><=;|&{("
[413] Fix | Delete
core.completer_word_break_characters = " \t\n`><=;|&{("
[414] Fix | Delete
core.basic_quote_characters = '"\''
[415] Fix | Delete
core.completer_quote_characters = '"\''
[416] Fix | Delete
core.filename_quote_characters = ""
[417] Fix | Delete
core.special_prefixes = ""
[418] Fix | Delete
}
[419] Fix | Delete
end
[420] Fix | Delete
[421] Fix | Delete
def self.line_editor
[422] Fix | Delete
core.line_editor
[423] Fix | Delete
end
[424] Fix | Delete
end
[425] Fix | Delete
[426] Fix | Delete
if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
[427] Fix | Delete
require 'reline/windows'
[428] Fix | Delete
if Reline::Windows.msys_tty?
[429] Fix | Delete
require 'reline/ansi'
[430] Fix | Delete
Reline::IOGate = Reline::ANSI
[431] Fix | Delete
else
[432] Fix | Delete
Reline::IOGate = Reline::Windows
[433] Fix | Delete
end
[434] Fix | Delete
else
[435] Fix | Delete
require 'reline/ansi'
[436] Fix | Delete
Reline::IOGate = Reline::ANSI
[437] Fix | Delete
end
[438] Fix | Delete
Reline::HISTORY = Reline::History.new(Reline.core.config)
[439] Fix | Delete
require 'reline/general_io'
[440] Fix | Delete
[441] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function