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:
parent
7095ba8db1
commit
d057388d17
5 changed files with 17 additions and 3 deletions
|
@ -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"
|
||||
|
|
5
lib/pry/custom_completions.rb
Normal file
5
lib/pry/custom_completions.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue