From 263e722c2a6ae77f3054d00593c333c86cb550fc Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 19 Apr 2011 22:37:10 +1200 Subject: [PATCH] resolved conflict, brought in injekt's awesome changes, added changes to README and fixed but in lesspipe broken pipes --- README.markdown | 34 ++++++++++++++++++++++++++++----- lib/pry/command_base_helpers.rb | 5 +++-- lib/pry/command_processor.rb | 2 +- lib/pry/print.rb | 4 +++- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/README.markdown b/README.markdown index 870b9caf..8126adf5 100644 --- a/README.markdown +++ b/README.markdown @@ -1,5 +1,4 @@ -![Alt text](http://dl.dropbox.com/u/26521875/pry_logo2.png) - +![Alt text](http://dl.dropbox.com/u/26521875/pry_logo_shade.png) (C) John Mair (banisterfiend) 2011 _Get to the code_ @@ -50,7 +49,7 @@ Example: Navigating around state --------------------------------------- Pry allows us to pop in and out of different scopes (objects) using -the `cd` command. To view what variables and methods are available +the `cd` command. To view which variables and methods are available within a particular scope we use the versatile `ls` command. Here we will begin Pry at top-level, then pry on a class and then on @@ -100,7 +99,7 @@ point available. When the session ends the program continues with any modifications you made to it. This functionality can be used for such things as: debugging, -implementing developer consoles, and applying hot patches. +implementing developer consoles and applying hot patches. code: @@ -134,7 +133,32 @@ Pry session: pry(main)> exit program resumes here. - + +Command Shell Integration +-------------------------- + +A line of input that begins with a '.' will be forwarded to the +command shell. This enables us to navigate the file system, spawn +an editor, and run git and rake directly from within Pry. + +Further, we can use the `shell-mode` command to incorporate the +present working directory into the Pry prompt and bring in (very +limited at this stage, sorry) file name completion. +We can also interpolate Ruby code directly into the shell by +using the normal `#{}` string interpolation syntax. + + + + + +In the code below we're going to switch to `shell-mode` and use the +`gem-cd` command to enter the home directory for a gem and examine +some of the files there, we will also show off some interpolation. + + + + + Features and limitations ------------------------ diff --git a/lib/pry/command_base_helpers.rb b/lib/pry/command_base_helpers.rb index 2431a993..e280f454 100644 --- a/lib/pry/command_base_helpers.rb +++ b/lib/pry/command_base_helpers.rb @@ -4,7 +4,7 @@ class Pry private - def gem_installed?(gem_name) + def gem_installed?(gem_name) require 'rubygems' !!Gem.source_index.find_name(gem_name).first end @@ -94,8 +94,9 @@ class Pry return end lesspipe { |less| less.puts text } - rescue Exception + rescue Errno::ENOENT simple_pager(text) + rescue Errno::EPIPE end # diff --git a/lib/pry/command_processor.rb b/lib/pry/command_processor.rb index 671b44e2..6c99c800 100644 --- a/lib/pry/command_processor.rb +++ b/lib/pry/command_processor.rb @@ -71,7 +71,7 @@ class Pry @@cd_history << Dir.pwd Dir.chdir(dest) - output.puts "=> #{dest.inspect}" + output.puts "=> #{dest}" rescue Errno::ENOENT output.puts "No such directory: #{dest}" end diff --git a/lib/pry/print.rb b/lib/pry/print.rb index 9f83a0c9..f41d02a2 100644 --- a/lib/pry/print.rb +++ b/lib/pry/print.rb @@ -1,7 +1,9 @@ +require "awesome_print" + class Pry DEFAULT_PRINT = proc do |output, value| if Pry.color - output.puts "=> #{CodeRay.scan(Pry.view(value), :ruby).term}" + output.puts "=> #{value.ai}"#"#{CodeRay.scan(Pry.view(value), :ruby).term}" else output.puts "=> #{Pry.view(value)}" end