1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Add Bond completion (when available) cirwin++

This commit is contained in:
☈king 2012-08-18 22:49:20 +00:00 committed by rking@sharpsaw.org
parent 8c9c38ef4c
commit 6617856b06
7 changed files with 35 additions and 5 deletions

View file

@ -25,6 +25,8 @@ def apply_spec_defaults(s)
s.add_development_dependency('bacon', '~> 1.1') s.add_development_dependency('bacon', '~> 1.1')
s.add_development_dependency('open4', '~> 1.3') s.add_development_dependency('open4', '~> 1.3')
s.add_development_dependency('rake', '~> 0.9') s.add_development_dependency('rake', '~> 0.9')
# TODO: make this a plain dependency:
s.add_development_dependency('bond', '~> 0.4.2')
end end
def check_dependencies def check_dependencies

View file

@ -222,3 +222,11 @@ require 'pry/pry_class'
require 'pry/pry_instance' require 'pry/pry_instance'
require 'pry/cli' require 'pry/cli'
require 'pry/pager' require 'pry/pager'
begin
require 'bond'
rescue LoadError
Pry.config.completer = Pry::InputCompleter
else
Pry.config.completer = Pry::BondCompleter
end

View file

@ -1,9 +1,14 @@
# taken from irb # taken from irb
require "readline"
class Pry class Pry
module BondCompleter
def self.build_completion_proc(target, pry=nil, commands=[""])
Bond.start
proc{ |*a| Bond.agent.call(*a) }
end
end
# Implements tab completion for Readline in Pry # Implements tab completion for Readline in Pry
module InputCompleter module InputCompleter
@ -42,6 +47,7 @@ class Pry
# @param [Binding] target The current binding context. # @param [Binding] target The current binding context.
# @param [Array<String>] commands The array of Pry commands. # @param [Array<String>] commands The array of Pry commands.
def self.build_completion_proc(target, pry=nil, commands=[""]) def self.build_completion_proc(target, pry=nil, commands=[""])
proc do |input| proc do |input|
# if there are multiple contexts e.g. cd 1/2/3 # if there are multiple contexts e.g. cd 1/2/3

View file

@ -228,6 +228,9 @@ class Pry
# Pry.config.extra_sticky_locals = { :random_number => proc { # Pry.config.extra_sticky_locals = { :random_number => proc {
# rand(10) } } # rand(10) } }
attr_accessor :extra_sticky_locals attr_accessor :extra_sticky_locals
# @return [#build_completion_proc] A completer to use.
attr_accessor :completer
end end
end end

View file

@ -360,7 +360,7 @@ class Pry
@indent.reset if eval_string.empty? @indent.reset if eval_string.empty?
current_prompt = select_prompt(eval_string, target) current_prompt = select_prompt(eval_string, target)
completion_proc = Pry::InputCompleter.build_completion_proc(target, self, completion_proc = Pry.config.completer.build_completion_proc(target, self,
instance_eval(&custom_completions)) instance_eval(&custom_completions))

View file

@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["John Mair (banisterfiend)", "Conrad Irwin"] s.authors = ["John Mair (banisterfiend)", "Conrad Irwin"]
s.date = "2012-08-13" s.date = "2012-08-18"
s.description = "An IRB alternative and runtime developer console" s.description = "An IRB alternative and runtime developer console"
s.email = ["jrmair@gmail.com", "conrad.irwin@gmail.com"] s.email = ["jrmair@gmail.com", "conrad.irwin@gmail.com"]
s.executables = ["pry"] s.executables = ["pry"]
@ -27,6 +27,7 @@ Gem::Specification.new do |s|
s.add_development_dependency(%q<bacon>, ["~> 1.1"]) s.add_development_dependency(%q<bacon>, ["~> 1.1"])
s.add_development_dependency(%q<open4>, ["~> 1.3"]) s.add_development_dependency(%q<open4>, ["~> 1.3"])
s.add_development_dependency(%q<rake>, ["~> 0.9"]) s.add_development_dependency(%q<rake>, ["~> 0.9"])
s.add_development_dependency(%q<bond>, ["~> 0.4.2"])
else else
s.add_dependency(%q<coderay>, ["~> 1.0.5"]) s.add_dependency(%q<coderay>, ["~> 1.0.5"])
s.add_dependency(%q<slop>, ["~> 3.3.1"]) s.add_dependency(%q<slop>, ["~> 3.3.1"])
@ -34,6 +35,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<bacon>, ["~> 1.1"]) s.add_dependency(%q<bacon>, ["~> 1.1"])
s.add_dependency(%q<open4>, ["~> 1.3"]) s.add_dependency(%q<open4>, ["~> 1.3"])
s.add_dependency(%q<rake>, ["~> 0.9"]) s.add_dependency(%q<rake>, ["~> 0.9"])
s.add_dependency(%q<bond>, ["~> 0.4.2"])
end end
else else
s.add_dependency(%q<coderay>, ["~> 1.0.5"]) s.add_dependency(%q<coderay>, ["~> 1.0.5"])
@ -42,5 +44,6 @@ Gem::Specification.new do |s|
s.add_dependency(%q<bacon>, ["~> 1.1"]) s.add_dependency(%q<bacon>, ["~> 1.1"])
s.add_dependency(%q<open4>, ["~> 1.3"]) s.add_dependency(%q<open4>, ["~> 1.3"])
s.add_dependency(%q<rake>, ["~> 0.9"]) s.add_dependency(%q<rake>, ["~> 0.9"])
s.add_dependency(%q<bond>, ["~> 0.4.2"])
end end
end end

View file

@ -10,6 +10,11 @@ def completer_test(bind, pry=nil, assert_flag=true)
return proc {|*symbols| symbols.each(&test) } return proc {|*symbols| symbols.each(&test) }
end end
describe 'bond-based completion' do
it 'should pull in Bond by default' do
Pry.config.completer.should == Pry::BondCompleter
end
end
describe Pry::InputCompleter do describe Pry::InputCompleter do
@ -20,9 +25,13 @@ describe Pry::InputCompleter do
module SymbolyName module SymbolyName
def self.name; :symboly_name; end def self.name; :symboly_name; end
end end
$default_completer = Pry.config.completer
Pry.config.completer = Pry::InputCompleter
end end
after do after do
Pry.config.completer = $default_completer
Object.remove_const :SymbolyName Object.remove_const :SymbolyName
end end
@ -216,4 +225,3 @@ describe Pry::InputCompleter do
end end
end end