Class: Bond::Readline

Inherits:
Object
  • Object
show all
Defined in:
lib/bond/readline.rb

Overview

This is the default readline plugin for Bond. A valid plugin must be an object that responds to methods setup and line_buffer as described below.

Direct Known Subclasses

Jruby, Rawline, Ruby

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.line_bufferObject

Returns full line of what the user has typed.



35
36
37
# File 'lib/bond/readline.rb', line 35

def self.line_buffer
  Readline.line_buffer
end

.load_extensionObject



28
29
30
31
32
# File 'lib/bond/readline.rb', line 28

def self.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

.readline_setupObject



19
20
21
22
23
24
25
26
# File 'lib/bond/readline.rb', line 19

def self.readline_setup
  require 'readline'
  load_extension unless Readline.respond_to?(:line_buffer)
  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

.setup(agent) ⇒ Object

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



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bond/readline.rb', line 7

def self.setup(agent)
  readline_setup

  # 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
end