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

added custom_completions.rb for customizable tab completions

This commit is contained in:
John Mair 2011-04-07 04:59:09 +12:00
parent 7095ba8db1
commit d057388d17
5 changed files with 17 additions and 3 deletions

View file

@ -26,6 +26,7 @@ require "pry/print"
require "pry/command_base"
require "pry/commands"
require "pry/prompts"
require "pry/custom_completions"
require "pry/completion"
require "pry/core_extensions"
require "pry/pry_class"

View file

@ -0,0 +1,5 @@
class Pry
# This proc will be instance_eval's against the active Pry instance
DEFAULT_CUSTOM_COMPLETIONS = proc { commands.commands.keys }
end

View file

@ -23,4 +23,9 @@ class Pry
# A simple prompt - doesn't display target or nesting level
SIMPLE_PROMPT = [proc { ">> " }, proc { ">* " }]
FILE_PROMPT = [
proc { |target_self, _| "pry(#{Pry.view_clip(target_self)}:#{Dir.pwd}> " },
proc { |target_self, _| "pry(#{Pry.view_clip(target_self)}:#{Dir.pwd}* " }
]
end

View file

@ -57,6 +57,8 @@ class Pry
# :after_session => proc { puts "goodbye" }
attr_accessor :hooks
attr_accessor :custom_completions
# Get the array of Procs to be used for the prompts by default by
# all Pry instances.
# @return [Array<Proc>] The array of Procs to be used for the
@ -192,6 +194,7 @@ class Pry
@prompt = DEFAULT_PROMPT
@print = DEFAULT_PRINT
@hooks = DEFAULT_HOOKS
@custom_completions = DEFAULT_CUSTOM_COMPLETIONS
@color = true
@should_load_rc = true
@rc_loaded = false

View file

@ -2,7 +2,7 @@ class Pry
# The list of configuration options.
CONFIG_OPTIONS = [:input, :output, :commands, :print,
:prompt, :hooks]
:prompt, :hooks, :custom_completions]
attr_accessor *CONFIG_OPTIONS
@ -93,7 +93,7 @@ class Pry
return_value
end
# Start a read-eval-print-loop.
# If no parameter is given, default to top-level (main).
# @param [Object, Binding] target The receiver of the Pry session
@ -149,7 +149,7 @@ class Pry
if input == Readline
# Readline tab completion
Readline.completion_proc = Pry::InputCompleter.build_completion_proc(target, commands.commands.keys)
Readline.completion_proc = Pry::InputCompleter.build_completion_proc target, instance_eval(&custom_completions)
end