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/command_base"
|
||||||
require "pry/commands"
|
require "pry/commands"
|
||||||
require "pry/prompts"
|
require "pry/prompts"
|
||||||
|
require "pry/custom_completions"
|
||||||
require "pry/completion"
|
require "pry/completion"
|
||||||
require "pry/core_extensions"
|
require "pry/core_extensions"
|
||||||
require "pry/pry_class"
|
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
|
# A simple prompt - doesn't display target or nesting level
|
||||||
SIMPLE_PROMPT = [proc { ">> " }, proc { ">* " }]
|
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
|
end
|
||||||
|
|
|
@ -57,6 +57,8 @@ class Pry
|
||||||
# :after_session => proc { puts "goodbye" }
|
# :after_session => proc { puts "goodbye" }
|
||||||
attr_accessor :hooks
|
attr_accessor :hooks
|
||||||
|
|
||||||
|
attr_accessor :custom_completions
|
||||||
|
|
||||||
# Get the array of Procs to be used for the prompts by default by
|
# Get the array of Procs to be used for the prompts by default by
|
||||||
# all Pry instances.
|
# all Pry instances.
|
||||||
# @return [Array<Proc>] The array of Procs to be used for the
|
# @return [Array<Proc>] The array of Procs to be used for the
|
||||||
|
@ -192,6 +194,7 @@ class Pry
|
||||||
@prompt = DEFAULT_PROMPT
|
@prompt = DEFAULT_PROMPT
|
||||||
@print = DEFAULT_PRINT
|
@print = DEFAULT_PRINT
|
||||||
@hooks = DEFAULT_HOOKS
|
@hooks = DEFAULT_HOOKS
|
||||||
|
@custom_completions = DEFAULT_CUSTOM_COMPLETIONS
|
||||||
@color = true
|
@color = true
|
||||||
@should_load_rc = true
|
@should_load_rc = true
|
||||||
@rc_loaded = false
|
@rc_loaded = false
|
||||||
|
|
|
@ -2,7 +2,7 @@ class Pry
|
||||||
|
|
||||||
# The list of configuration options.
|
# The list of configuration options.
|
||||||
CONFIG_OPTIONS = [:input, :output, :commands, :print,
|
CONFIG_OPTIONS = [:input, :output, :commands, :print,
|
||||||
:prompt, :hooks]
|
:prompt, :hooks, :custom_completions]
|
||||||
|
|
||||||
attr_accessor *CONFIG_OPTIONS
|
attr_accessor *CONFIG_OPTIONS
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class Pry
|
||||||
|
|
||||||
return_value
|
return_value
|
||||||
end
|
end
|
||||||
|
|
||||||
# Start a read-eval-print-loop.
|
# Start a read-eval-print-loop.
|
||||||
# If no parameter is given, default to top-level (main).
|
# If no parameter is given, default to top-level (main).
|
||||||
# @param [Object, Binding] target The receiver of the Pry session
|
# @param [Object, Binding] target The receiver of the Pry session
|
||||||
|
@ -149,7 +149,7 @@ class Pry
|
||||||
|
|
||||||
if input == Readline
|
if input == Readline
|
||||||
# Readline tab completion
|
# 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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue