123456789_123456789_123456789_123456789_123456789_

Class: IRB::ReadlineInputMethod

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: IRB::StdioInputMethod
Defined in: lib/irb/input-method.rb

Constant Summary

InputMethod - Inherited

BASIC_WORD_BREAK_CHARACTERS

Class Method Summary

StdioInputMethod - Inherited

.new

Creates a new input method object.

Instance Attribute Summary

HistorySavingAbility - Included

StdioInputMethod - Inherited

#eof?

Whether the end of this input method has been reached, returns true if there is no more data to read.

#prompting?,
#readable_after_eof?

Whether this input method is still readable when there is no more data to read.

InputMethod - Inherited

#prompt

The irb prompt associated with this input method.

#prompting?,
#readable_after_eof?

Whether this input method is still readable when there is no more data to read.

#support_history_saving?

Instance Method Summary

HistorySavingAbility - Included

StdioInputMethod - Inherited

#encoding

The external encoding for standard input.

#gets

Reads the next line from this input method.

#inspect

For debug message.

#line

Returns the current line number for #io.

InputMethod - Inherited

#gets

Reads the next line from this input method.

#inspect

For debug message.

#winsize

Constructor Details

.newReadlineInputMethod

Creates a new input method object using Readline

[ GitHub ]

  
# File 'lib/irb/input-method.rb', line 183

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

Class Method Details

.initialize_readline

[ GitHub ]

  
# File 'lib/irb/input-method.rb', line 173

def self.initialize_readline
  require "readline"
rescue LoadError
else
  include ::Readline
end

Instance Attribute Details

#eof?Boolean (readonly)

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.

[ GitHub ]

  
# File 'lib/irb/input-method.rb', line 227

def eof?
  @eof
end

#prompting?Boolean (readonly)

[ GitHub ]

  
# File 'lib/irb/input-method.rb', line 231

def prompting?
  true
end

Instance Method Details

#completion_info

[ GitHub ]

  
# File 'lib/irb/input-method.rb', line 204

def completion_info
  'RegexpCompletor'
end

#gets

Reads the next line from this input method.

See IO#gets for more information.

[ GitHub ]

  
# File 'lib/irb/input-method.rb', line 211

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

For debug message

[ GitHub ]

  
# File 'lib/irb/input-method.rb', line 236

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