2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2000-05-12 05:07:57 -04:00
|
|
|
#
|
2005-04-13 11:27:09 -04:00
|
|
|
# irb/input-method.rb - input methods used irb
|
2009-07-07 07:36:20 -04:00
|
|
|
# $Release Version: 0.9.6$
|
2000-05-12 05:07:57 -04:00
|
|
|
# $Revision$
|
2005-04-13 11:27:09 -04:00
|
|
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
2000-05-12 05:07:57 -04:00
|
|
|
#
|
|
|
|
# --
|
|
|
|
#
|
2009-03-05 22:56:38 -05:00
|
|
|
#
|
2000-05-12 05:07:57 -04:00
|
|
|
#
|
2018-11-02 13:52:33 -04:00
|
|
|
require_relative 'src_encoding'
|
2018-11-02 13:52:43 -04:00
|
|
|
require_relative 'magic-file'
|
2019-04-27 17:37:39 -04:00
|
|
|
require_relative 'completion'
|
2020-08-29 07:48:25 -04:00
|
|
|
require 'io/console'
|
2019-04-27 17:37:39 -04:00
|
|
|
require 'reline'
|
2021-08-29 07:04:23 -04:00
|
|
|
require 'rdoc'
|
2008-12-18 08:09:26 -05:00
|
|
|
|
2000-05-12 05:07:57 -04:00
|
|
|
module IRB
|
2012-12-21 00:45:50 -05:00
|
|
|
STDIN_FILE_NAME = "(line)" # :nodoc:
|
2000-05-12 05:07:57 -04:00
|
|
|
class InputMethod
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Creates a new input method object
|
2000-05-12 05:07:57 -04:00
|
|
|
def initialize(file = STDIN_FILE_NAME)
|
|
|
|
@file_name = file
|
|
|
|
end
|
2012-12-21 00:45:50 -05:00
|
|
|
# The file name of this input method, usually given during initialization.
|
2001-04-30 13:54:55 -04:00
|
|
|
attr_reader :file_name
|
2000-05-12 05:07:57 -04:00
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# The irb prompt associated with this input method
|
2001-04-30 13:54:55 -04:00
|
|
|
attr_accessor :prompt
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Reads the next line from this input method.
|
|
|
|
#
|
|
|
|
# See IO#gets for more information.
|
2000-05-12 05:07:57 -04:00
|
|
|
def gets
|
2019-11-24 15:38:09 -05:00
|
|
|
fail NotImplementedError, "gets"
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
|
|
|
public :gets
|
|
|
|
|
2020-08-29 07:48:25 -04:00
|
|
|
def winsize
|
|
|
|
if instance_variable_defined?(:@stdout)
|
|
|
|
@stdout.winsize
|
|
|
|
else
|
|
|
|
[24, 80]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Whether this input method is still readable when there is no more data to
|
|
|
|
# read.
|
|
|
|
#
|
|
|
|
# See IO#eof for more information.
|
2012-12-21 12:29:18 -05:00
|
|
|
def readable_after_eof?
|
2000-05-12 05:07:57 -04:00
|
|
|
false
|
|
|
|
end
|
2020-04-27 05:27:19 -04:00
|
|
|
|
|
|
|
# For debug message
|
|
|
|
def inspect
|
|
|
|
'Abstract InputMethod'
|
|
|
|
end
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2000-05-12 05:07:57 -04:00
|
|
|
class StdioInputMethod < InputMethod
|
2012-12-21 00:45:50 -05:00
|
|
|
# Creates a new input method object
|
2000-05-12 05:07:57 -04:00
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@line_no = 0
|
|
|
|
@line = []
|
2008-12-18 08:09:26 -05:00
|
|
|
@stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
2009-01-12 22:37:15 -05:00
|
|
|
@stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Reads the next line from this input method.
|
|
|
|
#
|
|
|
|
# See IO#gets for more information.
|
2000-05-12 05:07:57 -04:00
|
|
|
def gets
|
|
|
|
print @prompt
|
2008-12-18 08:09:26 -05:00
|
|
|
line = @stdin.gets
|
|
|
|
@line[@line_no += 1] = line
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Whether the end of this input method has been reached, returns +true+ if
|
|
|
|
# there is no more data to read.
|
|
|
|
#
|
|
|
|
# See IO#eof? for more information.
|
2000-05-12 05:07:57 -04:00
|
|
|
def eof?
|
2020-12-23 06:29:57 -05:00
|
|
|
rs, = IO.select([@stdin], [], [], 0.00001)
|
|
|
|
if rs and rs[0]
|
|
|
|
c = @stdin.getc
|
|
|
|
result = c.nil? ? true : false
|
|
|
|
@stdin.ungetc(c) unless c.nil?
|
|
|
|
result
|
|
|
|
else # buffer is empty
|
|
|
|
false
|
|
|
|
end
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Whether this input method is still readable when there is no more data to
|
|
|
|
# read.
|
|
|
|
#
|
|
|
|
# See IO#eof for more information.
|
2012-12-21 12:29:18 -05:00
|
|
|
def readable_after_eof?
|
2000-05-12 05:07:57 -04:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Returns the current line number for #io.
|
|
|
|
#
|
|
|
|
# #line counts the number of times #gets is called.
|
|
|
|
#
|
|
|
|
# See IO#lineno for more information.
|
2000-05-12 05:07:57 -04:00
|
|
|
def line(line_no)
|
|
|
|
@line[line_no]
|
|
|
|
end
|
2008-12-18 08:09:26 -05:00
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# The external encoding for standard input.
|
2008-12-18 08:09:26 -05:00
|
|
|
def encoding
|
|
|
|
@stdin.external_encoding
|
|
|
|
end
|
2020-04-27 05:27:19 -04:00
|
|
|
|
|
|
|
# For debug message
|
|
|
|
def inspect
|
|
|
|
'StdioInputMethod'
|
|
|
|
end
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Use a File for IO with irb, see InputMethod
|
2000-05-12 05:07:57 -04:00
|
|
|
class FileInputMethod < InputMethod
|
2021-01-22 12:12:39 -05:00
|
|
|
class << self
|
|
|
|
def open(file, &block)
|
|
|
|
begin
|
|
|
|
io = new(file)
|
|
|
|
block.call(io)
|
|
|
|
ensure
|
|
|
|
io&.close
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Creates a new input method object
|
2000-05-12 05:07:57 -04:00
|
|
|
def initialize(file)
|
|
|
|
super
|
2008-12-18 08:09:26 -05:00
|
|
|
@io = IRB::MagicFile.open(file)
|
2021-01-22 12:12:39 -05:00
|
|
|
@external_encoding = @io.external_encoding
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
2012-12-21 00:45:50 -05:00
|
|
|
# The file name of this input method, usually given during initialization.
|
2001-04-30 13:54:55 -04:00
|
|
|
attr_reader :file_name
|
2000-05-12 05:07:57 -04:00
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Whether the end of this input method has been reached, returns +true+ if
|
|
|
|
# there is no more data to read.
|
|
|
|
#
|
|
|
|
# See IO#eof? for more information.
|
2000-05-12 05:07:57 -04:00
|
|
|
def eof?
|
2021-01-22 12:12:39 -05:00
|
|
|
@io.closed? || @io.eof?
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Reads the next line from this input method.
|
|
|
|
#
|
|
|
|
# See IO#gets for more information.
|
2000-05-12 05:07:57 -04:00
|
|
|
def gets
|
2002-07-09 07:17:17 -04:00
|
|
|
print @prompt
|
2019-11-26 05:07:29 -05:00
|
|
|
@io.gets
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
2008-12-18 08:09:26 -05:00
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# The external encoding for standard input.
|
2008-12-18 08:09:26 -05:00
|
|
|
def encoding
|
2021-01-22 12:12:39 -05:00
|
|
|
@external_encoding
|
2008-12-18 08:09:26 -05:00
|
|
|
end
|
2020-04-27 05:27:19 -04:00
|
|
|
|
|
|
|
# For debug message
|
|
|
|
def inspect
|
|
|
|
'FileInputMethod'
|
|
|
|
end
|
2021-01-22 12:12:39 -05:00
|
|
|
|
|
|
|
def close
|
|
|
|
@io.close
|
|
|
|
end
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
class ReadlineInputMethod < InputMethod
|
2020-08-11 22:21:36 -04:00
|
|
|
def self.initialize_readline
|
|
|
|
require "readline"
|
|
|
|
rescue LoadError
|
|
|
|
else
|
|
|
|
include ::Readline
|
|
|
|
end
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Creates a new input method object using Readline
|
2000-05-12 05:07:57 -04:00
|
|
|
def initialize
|
2020-08-11 22:21:36 -04:00
|
|
|
self.class.initialize_readline
|
2020-01-14 01:40:03 -05:00
|
|
|
if Readline.respond_to?(:encoding_system_needs)
|
|
|
|
IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
|
|
|
|
end
|
2014-08-08 21:36:49 -04:00
|
|
|
super
|
2000-05-12 05:07:57 -04:00
|
|
|
|
2014-08-08 21:36:49 -04:00
|
|
|
@line_no = 0
|
|
|
|
@line = []
|
|
|
|
@eof = false
|
2008-12-18 08:09:26 -05:00
|
|
|
|
2014-08-08 21:36:49 -04:00
|
|
|
@stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
|
|
|
@stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
2019-04-27 17:37:39 -04:00
|
|
|
|
|
|
|
if Readline.respond_to?("basic_word_break_characters=")
|
|
|
|
Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
|
|
|
|
end
|
|
|
|
Readline.completion_append_character = nil
|
|
|
|
Readline.completion_proc = IRB::InputCompletor::CompletionProc
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Reads the next line from this input method.
|
|
|
|
#
|
|
|
|
# See IO#gets for more information.
|
2000-05-12 05:07:57 -04:00
|
|
|
def gets
|
2008-12-18 08:09:26 -05:00
|
|
|
Readline.input = @stdin
|
|
|
|
Readline.output = @stdout
|
2019-04-21 05:13:49 -04:00
|
|
|
if l = readline(@prompt, false)
|
2014-08-08 21:36:49 -04:00
|
|
|
HISTORY.push(l) if !l.empty?
|
|
|
|
@line[@line_no += 1] = l + "\n"
|
|
|
|
else
|
|
|
|
@eof = true
|
|
|
|
l
|
|
|
|
end
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Whether the end of this input method has been reached, returns +true+
|
|
|
|
# if there is no more data to read.
|
|
|
|
#
|
|
|
|
# See IO#eof? for more information.
|
2000-05-12 05:07:57 -04:00
|
|
|
def eof?
|
2014-08-08 21:36:49 -04:00
|
|
|
@eof
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Whether this input method is still readable when there is no more data to
|
|
|
|
# read.
|
|
|
|
#
|
|
|
|
# See IO#eof for more information.
|
2012-12-21 12:29:18 -05:00
|
|
|
def readable_after_eof?
|
2014-08-08 21:36:49 -04:00
|
|
|
true
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Returns the current line number for #io.
|
|
|
|
#
|
|
|
|
# #line counts the number of times #gets is called.
|
|
|
|
#
|
|
|
|
# See IO#lineno for more information.
|
2000-05-12 05:07:57 -04:00
|
|
|
def line(line_no)
|
2014-08-08 21:36:49 -04:00
|
|
|
@line[line_no]
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
2008-12-18 08:09:26 -05:00
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# The external encoding for standard input.
|
2008-12-18 08:09:26 -05:00
|
|
|
def encoding
|
2014-08-08 21:36:49 -04:00
|
|
|
@stdin.external_encoding
|
2008-12-18 08:09:26 -05:00
|
|
|
end
|
2019-04-27 17:37:39 -04:00
|
|
|
|
2020-04-27 05:27:19 -04:00
|
|
|
# For debug message
|
|
|
|
def inspect
|
|
|
|
readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
|
2020-04-28 04:06:43 -04:00
|
|
|
str = "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION}"
|
|
|
|
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
|
|
|
|
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
|
|
|
|
str
|
2020-04-27 05:27:19 -04:00
|
|
|
end
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|
|
|
|
end
|
2019-04-27 17:37:39 -04:00
|
|
|
|
|
|
|
class ReidlineInputMethod < InputMethod
|
|
|
|
include Reline
|
|
|
|
# Creates a new input method object using Readline
|
|
|
|
def initialize
|
2020-01-14 01:40:03 -05:00
|
|
|
IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false)
|
2019-04-27 17:37:39 -04:00
|
|
|
super
|
|
|
|
|
|
|
|
@line_no = 0
|
|
|
|
@line = []
|
|
|
|
@eof = false
|
|
|
|
|
|
|
|
@stdin = ::IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
|
|
|
@stdout = ::IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
|
|
|
|
|
|
|
|
if Reline.respond_to?("basic_word_break_characters=")
|
|
|
|
Reline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
|
|
|
|
end
|
|
|
|
Reline.completion_append_character = nil
|
2021-03-24 01:55:05 -04:00
|
|
|
Reline.completer_quote_characters = ''
|
2019-04-27 17:37:39 -04:00
|
|
|
Reline.completion_proc = IRB::InputCompletor::CompletionProc
|
2019-05-25 09:52:10 -04:00
|
|
|
Reline.output_modifier_proc =
|
|
|
|
if IRB.conf[:USE_COLORIZE]
|
2020-08-11 22:21:36 -04:00
|
|
|
proc do |output, complete: |
|
2019-05-25 09:52:10 -04:00
|
|
|
next unless IRB::Color.colorable?
|
2019-05-30 17:03:18 -04:00
|
|
|
IRB::Color.colorize_code(output, complete: complete)
|
2019-05-25 09:52:10 -04:00
|
|
|
end
|
|
|
|
else
|
|
|
|
proc do |output|
|
|
|
|
Reline::Unicode.escape_for_print(output)
|
|
|
|
end
|
2019-05-25 09:31:13 -04:00
|
|
|
end
|
2019-04-27 18:47:33 -04:00
|
|
|
Reline.dig_perfect_match_proc = IRB::InputCompletor::PerfectMatchedProc
|
2021-08-29 13:08:16 -04:00
|
|
|
Reline.autocompletion = IRB.conf[:USE_AUTOCOMPLETE]
|
|
|
|
if IRB.conf[:USE_AUTOCOMPLETE]
|
|
|
|
Reline.add_dialog_proc(:show_doc, SHOW_DOC_DIALOG, Reline::DEFAULT_DIALOG_CONTEXT)
|
|
|
|
end
|
2019-04-27 17:37:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_termination(&block)
|
|
|
|
@check_termination_proc = block
|
|
|
|
end
|
|
|
|
|
2019-06-13 19:26:06 -04:00
|
|
|
def dynamic_prompt(&block)
|
|
|
|
@prompt_proc = block
|
|
|
|
end
|
|
|
|
|
2019-06-18 07:57:58 -04:00
|
|
|
def auto_indent(&block)
|
|
|
|
@auto_indent_proc = block
|
|
|
|
end
|
|
|
|
|
2021-08-29 07:04:23 -04:00
|
|
|
SHOW_DOC_DIALOG = ->() {
|
2021-09-02 12:17:10 -04:00
|
|
|
dialog.trap_key = nil
|
|
|
|
alt_d = 0xE4
|
2021-08-29 07:04:23 -04:00
|
|
|
begin
|
|
|
|
require 'rdoc'
|
|
|
|
rescue LoadError
|
|
|
|
return nil
|
|
|
|
end
|
2021-09-02 12:17:10 -04:00
|
|
|
|
2021-08-29 07:04:23 -04:00
|
|
|
if just_cursor_moving and completion_journey_data.nil?
|
|
|
|
return nil
|
|
|
|
end
|
2021-08-30 16:50:15 -04:00
|
|
|
cursor_pos_to_render, result, pointer, autocomplete_dialog = context.pop(4)
|
2021-08-30 15:26:41 -04:00
|
|
|
return nil if result.nil? or pointer.nil? or pointer < 0
|
2021-08-29 07:04:23 -04:00
|
|
|
name = result[pointer]
|
2021-08-29 22:52:38 -04:00
|
|
|
name = IRB::InputCompletor.retrieve_completion_data(name, doc_namespace: true)
|
2021-08-29 07:04:23 -04:00
|
|
|
|
|
|
|
driver = RDoc::RI::Driver.new
|
2021-09-02 12:17:10 -04:00
|
|
|
|
|
|
|
if key.combined_char == alt_d
|
|
|
|
begin
|
|
|
|
driver.display_names([name])
|
|
|
|
rescue RDoc::RI::Driver::NotFoundError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-08-29 07:05:57 -04:00
|
|
|
begin
|
|
|
|
name = driver.expand_name(name)
|
|
|
|
rescue RDoc::RI::Driver::NotFoundError
|
|
|
|
return nil
|
2021-08-29 22:51:17 -04:00
|
|
|
rescue
|
|
|
|
return nil # unknown error
|
2021-08-29 07:05:57 -04:00
|
|
|
end
|
2021-08-29 07:04:23 -04:00
|
|
|
doc = nil
|
|
|
|
used_for_class = false
|
|
|
|
if not name =~ /#|\./
|
|
|
|
found, klasses, includes, extends = driver.classes_and_includes_and_extends_for(name)
|
|
|
|
if not found.empty?
|
|
|
|
doc = driver.class_document(name, found, klasses, includes, extends)
|
|
|
|
used_for_class = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
unless used_for_class
|
|
|
|
doc = RDoc::Markup::Document.new
|
|
|
|
begin
|
|
|
|
driver.add_method(doc, name)
|
|
|
|
rescue RDoc::RI::Driver::NotFoundError
|
|
|
|
doc = nil
|
2021-08-29 22:51:17 -04:00
|
|
|
rescue
|
|
|
|
return nil # unknown error
|
2021-08-29 07:04:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil if doc.nil?
|
2021-08-31 01:06:36 -04:00
|
|
|
width = 40
|
2021-08-29 07:04:23 -04:00
|
|
|
formatter = RDoc::Markup::ToAnsi.new
|
2021-08-31 01:06:36 -04:00
|
|
|
formatter.width = width
|
2021-09-02 12:17:10 -04:00
|
|
|
dialog.trap_key = alt_d
|
2021-08-31 01:06:36 -04:00
|
|
|
contents = doc.accept(formatter).split("\n")
|
2021-08-29 07:04:23 -04:00
|
|
|
|
2021-08-31 02:14:16 -04:00
|
|
|
x = cursor_pos_to_render.x + autocomplete_dialog.width
|
2021-08-31 01:06:36 -04:00
|
|
|
x = cursor_pos_to_render.x - width if x + width >= screen_width
|
2021-08-30 16:50:15 -04:00
|
|
|
y = cursor_pos_to_render.y + pointer - autocomplete_dialog.scroll_top
|
2021-08-31 02:15:29 -04:00
|
|
|
DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49')
|
2021-08-29 07:04:23 -04:00
|
|
|
}
|
|
|
|
|
2019-04-27 17:37:39 -04:00
|
|
|
# Reads the next line from this input method.
|
|
|
|
#
|
|
|
|
# See IO#gets for more information.
|
|
|
|
def gets
|
|
|
|
Reline.input = @stdin
|
|
|
|
Reline.output = @stdout
|
2019-06-13 19:26:06 -04:00
|
|
|
Reline.prompt_proc = @prompt_proc
|
2019-06-18 20:19:41 -04:00
|
|
|
Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc
|
2021-03-26 09:46:40 -04:00
|
|
|
if l = readmultiline(@prompt, false, &@check_termination_proc)
|
2019-04-27 17:37:39 -04:00
|
|
|
HISTORY.push(l) if !l.empty?
|
|
|
|
@line[@line_no += 1] = l + "\n"
|
|
|
|
else
|
|
|
|
@eof = true
|
|
|
|
l
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Whether the end of this input method has been reached, returns +true+
|
|
|
|
# if there is no more data to read.
|
|
|
|
#
|
|
|
|
# See IO#eof? for more information.
|
|
|
|
def eof?
|
2019-11-29 21:14:35 -05:00
|
|
|
@eof
|
2019-04-27 17:37:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Whether this input method is still readable when there is no more data to
|
|
|
|
# read.
|
|
|
|
#
|
|
|
|
# See IO#eof for more information.
|
|
|
|
def readable_after_eof?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Returns the current line number for #io.
|
|
|
|
#
|
|
|
|
# #line counts the number of times #gets is called.
|
|
|
|
#
|
|
|
|
# See IO#lineno for more information.
|
|
|
|
def line(line_no)
|
|
|
|
@line[line_no]
|
|
|
|
end
|
|
|
|
|
|
|
|
# The external encoding for standard input.
|
|
|
|
def encoding
|
|
|
|
@stdin.external_encoding
|
|
|
|
end
|
2020-04-27 05:27:19 -04:00
|
|
|
|
|
|
|
# For debug message
|
|
|
|
def inspect
|
|
|
|
config = Reline::Config.new
|
2020-04-28 04:06:43 -04:00
|
|
|
str = "ReidlineInputMethod with Reline #{Reline::VERSION}"
|
2020-04-27 05:27:19 -04:00
|
|
|
if config.respond_to?(:inputrc_path)
|
2020-08-13 06:19:00 -04:00
|
|
|
inputrc_path = File.expand_path(config.inputrc_path)
|
2020-04-27 05:27:19 -04:00
|
|
|
else
|
|
|
|
inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
|
|
|
|
end
|
2020-04-28 04:06:43 -04:00
|
|
|
str += " and #{inputrc_path}" if File.exist?(inputrc_path)
|
|
|
|
str
|
2020-04-27 05:27:19 -04:00
|
|
|
end
|
2019-12-07 06:21:08 -05:00
|
|
|
end
|
2000-05-12 05:07:57 -04:00
|
|
|
end
|