類別 IRB::ReadlineInputMethod

公開類別方法

initialize_readline() 按一下以切換來源
# File lib/irb/input-method.rb, line 165
def self.initialize_readline
  require "readline"
rescue LoadError
else
  include ::Readline
end
new() 按一下以切換來源

使用 Readline 建立新的輸入方法物件

呼叫超類別方法 IRB::StdioInputMethod::new
# File lib/irb/input-method.rb, line 175
def initialize
  self.class.initialize_readline
  if Readline.respond_to?(:encoding_system_needs)
    IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
  end

  super

  @eof = false
  @completor = RegexpCompletor.new

  if Readline.respond_to?("basic_word_break_characters=")
    Readline.basic_word_break_characters = BASIC_WORD_BREAK_CHARACTERS
  end
  Readline.completion_append_character = nil
  Readline.completion_proc = ->(target) {
    bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
    @completor.completion_candidates('', target, '', bind: bind)
  }
end

公開執行個體方法

completion_info() 按一下以切換來源
# File lib/irb/input-method.rb, line 196
def completion_info
  'RegexpCompletor'
end
eof?() 按一下以切換來源

此輸入方法的結尾是否已達,如果沒有更多資料可讀取,則傳回 true

請參閱 IO#eof? 以取得更多資訊。

# File lib/irb/input-method.rb, line 219
def eof?
  @eof
end
gets() 按一下以切換來源

從此輸入方法讀取下一行。

請參閱 IO#gets 以取得更多資訊。

# File lib/irb/input-method.rb, line 203
def gets
  Readline.input = @stdin
  Readline.output = @stdout
  if l = readline(@prompt, false)
    HISTORY.push(l) if !l.empty?
    @line[@line_no += 1] = l + "\n"
  else
    @eof = true
    l
  end
end
inspect() 按一下以切換來源

用於偵錯訊息

# File lib/irb/input-method.rb, line 224
def inspect
  readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
  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
end