Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/irb
File: input-method.rb
# frozen_string_literal: false
[0] Fix | Delete
#
[1] Fix | Delete
# irb/input-method.rb - input methods used irb
[2] Fix | Delete
# $Release Version: 0.9.6$
[3] Fix | Delete
# $Revision$
[4] Fix | Delete
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
[5] Fix | Delete
#
[6] Fix | Delete
# --
[7] Fix | Delete
#
[8] Fix | Delete
#
[9] Fix | Delete
#
[10] Fix | Delete
require_relative 'src_encoding'
[11] Fix | Delete
require_relative 'magic-file'
[12] Fix | Delete
require_relative 'completion'
[13] Fix | Delete
require 'io/console'
[14] Fix | Delete
require 'reline'
[15] Fix | Delete
[16] Fix | Delete
module IRB
[17] Fix | Delete
STDIN_FILE_NAME = "(line)" # :nodoc:
[18] Fix | Delete
class InputMethod
[19] Fix | Delete
[20] Fix | Delete
# Creates a new input method object
[21] Fix | Delete
def initialize(file = STDIN_FILE_NAME)
[22] Fix | Delete
@file_name = file
[23] Fix | Delete
end
[24] Fix | Delete
# The file name of this input method, usually given during initialization.
[25] Fix | Delete
attr_reader :file_name
[26] Fix | Delete
[27] Fix | Delete
# The irb prompt associated with this input method
[28] Fix | Delete
attr_accessor :prompt
[29] Fix | Delete
[30] Fix | Delete
# Reads the next line from this input method.
[31] Fix | Delete
#
[32] Fix | Delete
# See IO#gets for more information.
[33] Fix | Delete
def gets
[34] Fix | Delete
fail NotImplementedError, "gets"
[35] Fix | Delete
end
[36] Fix | Delete
public :gets
[37] Fix | Delete
[38] Fix | Delete
def winsize
[39] Fix | Delete
if instance_variable_defined?(:@stdout)
[40] Fix | Delete
@stdout.winsize
[41] Fix | Delete
else
[42] Fix | Delete
[24, 80]
[43] Fix | Delete
end
[44] Fix | Delete
end
[45] Fix | Delete
[46] Fix | Delete
# Whether this input method is still readable when there is no more data to
[47] Fix | Delete
# read.
[48] Fix | Delete
#
[49] Fix | Delete
# See IO#eof for more information.
[50] Fix | Delete
def readable_after_eof?
[51] Fix | Delete
false
[52] Fix | Delete
end
[53] Fix | Delete
[54] Fix | Delete
# For debug message
[55] Fix | Delete
def inspect
[56] Fix | Delete
'Abstract InputMethod'
[57] Fix | Delete
end
[58] Fix | Delete
end
[59] Fix | Delete
[60] Fix | Delete
class StdioInputMethod < InputMethod
[61] Fix | Delete
# Creates a new input method object
[62] Fix | Delete
def initialize
[63] Fix | Delete
super
[64] Fix | Delete
@line_no = 0
[65] Fix | Delete
@line = []
[66] Fix | Delete
@stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
[67] Fix | Delete
@stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
[68] Fix | Delete
end
[69] Fix | Delete
[70] Fix | Delete
# Reads the next line from this input method.
[71] Fix | Delete
#
[72] Fix | Delete
# See IO#gets for more information.
[73] Fix | Delete
def gets
[74] Fix | Delete
print @prompt
[75] Fix | Delete
line = @stdin.gets
[76] Fix | Delete
@line[@line_no += 1] = line
[77] Fix | Delete
end
[78] Fix | Delete
[79] Fix | Delete
# Whether the end of this input method has been reached, returns +true+ if
[80] Fix | Delete
# there is no more data to read.
[81] Fix | Delete
#
[82] Fix | Delete
# See IO#eof? for more information.
[83] Fix | Delete
def eof?
[84] Fix | Delete
@stdin.eof?
[85] Fix | Delete
end
[86] Fix | Delete
[87] Fix | Delete
# Whether this input method is still readable when there is no more data to
[88] Fix | Delete
# read.
[89] Fix | Delete
#
[90] Fix | Delete
# See IO#eof for more information.
[91] Fix | Delete
def readable_after_eof?
[92] Fix | Delete
true
[93] Fix | Delete
end
[94] Fix | Delete
[95] Fix | Delete
# Returns the current line number for #io.
[96] Fix | Delete
#
[97] Fix | Delete
# #line counts the number of times #gets is called.
[98] Fix | Delete
#
[99] Fix | Delete
# See IO#lineno for more information.
[100] Fix | Delete
def line(line_no)
[101] Fix | Delete
@line[line_no]
[102] Fix | Delete
end
[103] Fix | Delete
[104] Fix | Delete
# The external encoding for standard input.
[105] Fix | Delete
def encoding
[106] Fix | Delete
@stdin.external_encoding
[107] Fix | Delete
end
[108] Fix | Delete
[109] Fix | Delete
# For debug message
[110] Fix | Delete
def inspect
[111] Fix | Delete
'StdioInputMethod'
[112] Fix | Delete
end
[113] Fix | Delete
end
[114] Fix | Delete
[115] Fix | Delete
# Use a File for IO with irb, see InputMethod
[116] Fix | Delete
class FileInputMethod < InputMethod
[117] Fix | Delete
# Creates a new input method object
[118] Fix | Delete
def initialize(file)
[119] Fix | Delete
super
[120] Fix | Delete
@io = IRB::MagicFile.open(file)
[121] Fix | Delete
end
[122] Fix | Delete
# The file name of this input method, usually given during initialization.
[123] Fix | Delete
attr_reader :file_name
[124] Fix | Delete
[125] Fix | Delete
# Whether the end of this input method has been reached, returns +true+ if
[126] Fix | Delete
# there is no more data to read.
[127] Fix | Delete
#
[128] Fix | Delete
# See IO#eof? for more information.
[129] Fix | Delete
def eof?
[130] Fix | Delete
@io.eof?
[131] Fix | Delete
end
[132] Fix | Delete
[133] Fix | Delete
# Reads the next line from this input method.
[134] Fix | Delete
#
[135] Fix | Delete
# See IO#gets for more information.
[136] Fix | Delete
def gets
[137] Fix | Delete
print @prompt
[138] Fix | Delete
@io.gets
[139] Fix | Delete
end
[140] Fix | Delete
[141] Fix | Delete
# The external encoding for standard input.
[142] Fix | Delete
def encoding
[143] Fix | Delete
@io.external_encoding
[144] Fix | Delete
end
[145] Fix | Delete
[146] Fix | Delete
# For debug message
[147] Fix | Delete
def inspect
[148] Fix | Delete
'FileInputMethod'
[149] Fix | Delete
end
[150] Fix | Delete
end
[151] Fix | Delete
[152] Fix | Delete
begin
[153] Fix | Delete
class ReadlineInputMethod < InputMethod
[154] Fix | Delete
def self.initialize_readline
[155] Fix | Delete
require "readline"
[156] Fix | Delete
rescue LoadError
[157] Fix | Delete
else
[158] Fix | Delete
include ::Readline
[159] Fix | Delete
end
[160] Fix | Delete
[161] Fix | Delete
# Creates a new input method object using Readline
[162] Fix | Delete
def initialize
[163] Fix | Delete
self.class.initialize_readline
[164] Fix | Delete
if Readline.respond_to?(:encoding_system_needs)
[165] Fix | Delete
IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
[166] Fix | Delete
end
[167] Fix | Delete
super
[168] Fix | Delete
[169] Fix | Delete
@line_no = 0
[170] Fix | Delete
@line = []
[171] Fix | Delete
@eof = false
[172] Fix | Delete
[173] Fix | Delete
@stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
[174] Fix | Delete
@stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
[175] Fix | Delete
[176] Fix | Delete
if Readline.respond_to?("basic_word_break_characters=")
[177] Fix | Delete
Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
[178] Fix | Delete
end
[179] Fix | Delete
Readline.completion_append_character = nil
[180] Fix | Delete
Readline.completion_proc = IRB::InputCompletor::CompletionProc
[181] Fix | Delete
end
[182] Fix | Delete
[183] Fix | Delete
# Reads the next line from this input method.
[184] Fix | Delete
#
[185] Fix | Delete
# See IO#gets for more information.
[186] Fix | Delete
def gets
[187] Fix | Delete
Readline.input = @stdin
[188] Fix | Delete
Readline.output = @stdout
[189] Fix | Delete
if l = readline(@prompt, false)
[190] Fix | Delete
HISTORY.push(l) if !l.empty?
[191] Fix | Delete
@line[@line_no += 1] = l + "\n"
[192] Fix | Delete
else
[193] Fix | Delete
@eof = true
[194] Fix | Delete
l
[195] Fix | Delete
end
[196] Fix | Delete
end
[197] Fix | Delete
[198] Fix | Delete
# Whether the end of this input method has been reached, returns +true+
[199] Fix | Delete
# if there is no more data to read.
[200] Fix | Delete
#
[201] Fix | Delete
# See IO#eof? for more information.
[202] Fix | Delete
def eof?
[203] Fix | Delete
@eof
[204] Fix | Delete
end
[205] Fix | Delete
[206] Fix | Delete
# Whether this input method is still readable when there is no more data to
[207] Fix | Delete
# read.
[208] Fix | Delete
#
[209] Fix | Delete
# See IO#eof for more information.
[210] Fix | Delete
def readable_after_eof?
[211] Fix | Delete
true
[212] Fix | Delete
end
[213] Fix | Delete
[214] Fix | Delete
# Returns the current line number for #io.
[215] Fix | Delete
#
[216] Fix | Delete
# #line counts the number of times #gets is called.
[217] Fix | Delete
#
[218] Fix | Delete
# See IO#lineno for more information.
[219] Fix | Delete
def line(line_no)
[220] Fix | Delete
@line[line_no]
[221] Fix | Delete
end
[222] Fix | Delete
[223] Fix | Delete
# The external encoding for standard input.
[224] Fix | Delete
def encoding
[225] Fix | Delete
@stdin.external_encoding
[226] Fix | Delete
end
[227] Fix | Delete
[228] Fix | Delete
# For debug message
[229] Fix | Delete
def inspect
[230] Fix | Delete
readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
[231] Fix | Delete
str = "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION}"
[232] Fix | Delete
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
[233] Fix | Delete
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
[234] Fix | Delete
str
[235] Fix | Delete
end
[236] Fix | Delete
end
[237] Fix | Delete
end
[238] Fix | Delete
[239] Fix | Delete
class ReidlineInputMethod < InputMethod
[240] Fix | Delete
include Reline
[241] Fix | Delete
# Creates a new input method object using Readline
[242] Fix | Delete
def initialize
[243] Fix | Delete
IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false)
[244] Fix | Delete
super
[245] Fix | Delete
[246] Fix | Delete
@line_no = 0
[247] Fix | Delete
@line = []
[248] Fix | Delete
@eof = false
[249] Fix | Delete
[250] Fix | Delete
@stdin = ::IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
[251] Fix | Delete
@stdout = ::IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
[252] Fix | Delete
[253] Fix | Delete
if Reline.respond_to?("basic_word_break_characters=")
[254] Fix | Delete
Reline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
[255] Fix | Delete
end
[256] Fix | Delete
Reline.completion_append_character = nil
[257] Fix | Delete
Reline.completion_proc = IRB::InputCompletor::CompletionProc
[258] Fix | Delete
Reline.output_modifier_proc =
[259] Fix | Delete
if IRB.conf[:USE_COLORIZE]
[260] Fix | Delete
proc do |output, complete: |
[261] Fix | Delete
next unless IRB::Color.colorable?
[262] Fix | Delete
IRB::Color.colorize_code(output, complete: complete)
[263] Fix | Delete
end
[264] Fix | Delete
else
[265] Fix | Delete
proc do |output|
[266] Fix | Delete
Reline::Unicode.escape_for_print(output)
[267] Fix | Delete
end
[268] Fix | Delete
end
[269] Fix | Delete
Reline.dig_perfect_match_proc = IRB::InputCompletor::PerfectMatchedProc
[270] Fix | Delete
end
[271] Fix | Delete
[272] Fix | Delete
def check_termination(&block)
[273] Fix | Delete
@check_termination_proc = block
[274] Fix | Delete
end
[275] Fix | Delete
[276] Fix | Delete
def dynamic_prompt(&block)
[277] Fix | Delete
@prompt_proc = block
[278] Fix | Delete
end
[279] Fix | Delete
[280] Fix | Delete
def auto_indent(&block)
[281] Fix | Delete
@auto_indent_proc = block
[282] Fix | Delete
end
[283] Fix | Delete
[284] Fix | Delete
# Reads the next line from this input method.
[285] Fix | Delete
#
[286] Fix | Delete
# See IO#gets for more information.
[287] Fix | Delete
def gets
[288] Fix | Delete
Reline.input = @stdin
[289] Fix | Delete
Reline.output = @stdout
[290] Fix | Delete
Reline.prompt_proc = @prompt_proc
[291] Fix | Delete
Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc
[292] Fix | Delete
if l = readmultiline(@prompt, false, &@check_termination_proc)
[293] Fix | Delete
HISTORY.push(l) if !l.empty?
[294] Fix | Delete
@line[@line_no += 1] = l + "\n"
[295] Fix | Delete
else
[296] Fix | Delete
@eof = true
[297] Fix | Delete
l
[298] Fix | Delete
end
[299] Fix | Delete
end
[300] Fix | Delete
[301] Fix | Delete
# Whether the end of this input method has been reached, returns +true+
[302] Fix | Delete
# if there is no more data to read.
[303] Fix | Delete
#
[304] Fix | Delete
# See IO#eof? for more information.
[305] Fix | Delete
def eof?
[306] Fix | Delete
@eof
[307] Fix | Delete
end
[308] Fix | Delete
[309] Fix | Delete
# Whether this input method is still readable when there is no more data to
[310] Fix | Delete
# read.
[311] Fix | Delete
#
[312] Fix | Delete
# See IO#eof for more information.
[313] Fix | Delete
def readable_after_eof?
[314] Fix | Delete
true
[315] Fix | Delete
end
[316] Fix | Delete
[317] Fix | Delete
# Returns the current line number for #io.
[318] Fix | Delete
#
[319] Fix | Delete
# #line counts the number of times #gets is called.
[320] Fix | Delete
#
[321] Fix | Delete
# See IO#lineno for more information.
[322] Fix | Delete
def line(line_no)
[323] Fix | Delete
@line[line_no]
[324] Fix | Delete
end
[325] Fix | Delete
[326] Fix | Delete
# The external encoding for standard input.
[327] Fix | Delete
def encoding
[328] Fix | Delete
@stdin.external_encoding
[329] Fix | Delete
end
[330] Fix | Delete
[331] Fix | Delete
# For debug message
[332] Fix | Delete
def inspect
[333] Fix | Delete
config = Reline::Config.new
[334] Fix | Delete
str = "ReidlineInputMethod with Reline #{Reline::VERSION}"
[335] Fix | Delete
if config.respond_to?(:inputrc_path)
[336] Fix | Delete
inputrc_path = File.expand_path(config.inputrc_path)
[337] Fix | Delete
else
[338] Fix | Delete
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
[339] Fix | Delete
end
[340] Fix | Delete
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
[341] Fix | Delete
str
[342] Fix | Delete
end
[343] Fix | Delete
end
[344] Fix | Delete
end
[345] Fix | Delete
[346] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function