lib/bond/readline.rb in bond-0.3.3 vs lib/bond/readline.rb in bond-0.3.4

- old
+ new

@@ -5,11 +5,13 @@ DefaultBreakCharacters = " \t\n\"\\'`><=;|&{(" # Loads the readline-like library and sets the completion_proc to the given agent. def setup(agent) require 'readline' - load_extension unless ::Readline.respond_to?(:line_buffer) + 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 @@ -19,17 +21,28 @@ 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 + 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 + def load_extension require 'readline_line_buffer' rescue LoadError - $stderr.puts "Bond Error: Failed to load readline_line_buffer.bundle. Ensure that it exists and was built correctly." + $stderr.puts "Bond Error: Failed to load readline_line_buffer. Ensure that it exists and was built correctly." end # Returns full line of what the user has typed. def line_buffer ::Readline.line_buffer end end -end \ No newline at end of file +end