Module: Bond::Readline

Defined in:
lib/bond/readline.rb

Overview

This is the default readline plugin for Bond. A valid plugin must be a module that defines methods setup and line_buffer as described below.

Constant Summary collapse

DefaultBreakCharacters =
" \t\n\"\\'`><=;|&{("

Instance Method Summary collapse

Instance Method Details

#line_bufferObject

Returns full line of what the user has typed.



44
45
46
# File 'lib/bond/readline.rb', line 44

def line_buffer
  ::Readline.line_buffer
end

#load_extensionObject



37
38
39
40
41
# File 'lib/bond/readline.rb', line 37

def load_extension
  require 'readline_line_buffer'
rescue LoadError
  $stderr.puts "Bond Error: Failed to load readline_line_buffer. Ensure that it exists and was built correctly."
end

#load_jruby_extensionObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/bond/readline.rb', line 26

def load_jruby_extension
  require 'jruby'

  class << Readline
    ReadlineExt = org.jruby.ext.Readline
    def line_buffer
      ReadlineExt.s_get_line_buffer(JRuby.runtime.current_context, JRuby.reference(self))
    end
  end
end

#setup(agent) ⇒ Object

Loads the readline-like library and sets the completion_proc to the given agent.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bond/readline.rb', line 8

def setup(agent)
  require 'readline'
  unless ::Readline.respond_to?(:line_buffer)
    RUBY_PLATFORM =~ /java/ ? load_jruby_extension : load_extension
  end

  # Reinforcing irb defaults
  ::Readline.completion_append_character = nil
  if ::Readline.respond_to?("basic_word_break_characters=")
    ::Readline.basic_word_break_characters = DefaultBreakCharacters
  end

  ::Readline.completion_proc = agent
  if (::Readline::VERSION rescue nil).to_s[/editline/i]
    puts "Bond has detected EditLine and may not work with it. See the README's Limitations section."
  end
end