From d057388d172ac7e0e6feebb9f5ef0a5dcb2a1422 Mon Sep 17 00:00:00 2001 From: John Mair Date: Thu, 7 Apr 2011 04:59:09 +1200 Subject: [PATCH] added custom_completions.rb for customizable tab completions --- lib/pry.rb | 1 + lib/pry/custom_completions.rb | 5 +++++ lib/pry/prompts.rb | 5 +++++ lib/pry/pry_class.rb | 3 +++ lib/pry/pry_instance.rb | 6 +++--- 5 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 lib/pry/custom_completions.rb diff --git a/lib/pry.rb b/lib/pry.rb index efc2c032..f3657b9c 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -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" diff --git a/lib/pry/custom_completions.rb b/lib/pry/custom_completions.rb new file mode 100644 index 00000000..dde8b7f2 --- /dev/null +++ b/lib/pry/custom_completions.rb @@ -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 diff --git a/lib/pry/prompts.rb b/lib/pry/prompts.rb index a12da4fe..65fdd0d1 100644 --- a/lib/pry/prompts.rb +++ b/lib/pry/prompts.rb @@ -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 diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index b0a072ef..a6ba06eb 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -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] 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 diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index bc0f4927..ec44eb12 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -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