Browse files

version 0.6.7pre3, getting syntax higlighting working and adding new …

…commands to pry commandline, see TODO
  • Loading branch information...
1 parent 7ed6c17 commit f1c5fa4a69014b8be2640f110b4306f9bd51734f @banister banister committed Mar 3, 2011
Showing with 108 additions and 36 deletions.
  1. +18 −1 Rakefile
  2. +4 −0 TODO
  3. +12 −0 bin/pry
  4. +24 −10 lib/pry.rb
  5. +38 −8 lib/pry/commands.rb
  6. +5 −1 lib/pry/print.rb
  7. +1 −1 lib/pry/prompts.rb
  8. +5 −11 lib/pry/pry_class.rb
  9. +0 −3 lib/pry/pry_instance.rb
  10. +1 −1 lib/pry/version.rb
View
19 Rakefile
@@ -20,6 +20,7 @@ def apply_spec_defaults(s)
s.description = s.summary
s.require_path = 'lib'
s.add_dependency("ruby_parser",">=2.0.5")
+ s.add_dependency("coderay",">=0.9.7")
s.add_development_dependency("bacon",">=1.1.0")
s.homepage = "http://banisterfiend.wordpress.com"
s.has_rdoc = 'yard'
@@ -56,6 +57,22 @@ namespace :ruby do
end
end
+[:mingw32, :mswin32].each do |v|
+ namespace v do
+ spec = Gem::Specification.new do |s|
+ apply_spec_defaults(s)
+ s.add_dependency("method_source",">=0.3.4")
+ s.add_dependency("win32console", ">=1.3.0")
+ s.platform = "i386-#{v}"
+ end
+
+ Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_zip = false
+ pkg.need_tar = false
+ end
+ end
+end
+
namespace :jruby do
spec = Gem::Specification.new do |s|
apply_spec_defaults(s)
@@ -71,7 +88,7 @@ end
desc "build all platform gems at once"
-task :gems => [:rmgems, "ruby:gem", "jruby:gem"]
+task :gems => [:rmgems, "ruby:gem", "jruby:gem", "mswin32:gem", "mingw32:gem"]
desc "remove all platform gems"
task :rmgems => ["ruby:clobber_package"]
View
4 TODO
@@ -1,3 +1,7 @@
+0.6.7
+* color support
+* --simple-prompt for pry commandline
+
0.6.1
* !@ command alias for exit_all
* `cd /` for breaking out to pry top level (jump-to 0)
View
12 bin/pry
@@ -35,6 +35,18 @@ See: `https://github.com/banister` for more information.
options[:loadrc] = false
end
+ opts.on("--color", "Start session with syntax highlighting on.") do
+ Pry.color = true
+ end
+
+ opts.on("--simple-prompt", "Simple prompt mode.") do
+ Pry.prompt = Pry::SIMPLE_PROMPT
+ end
+
+ opts.on("-I LOADPATH", "Specify $LOAD_PATH directory.") do |load_path|
+ $LOAD_PATH << load_path
+ end
+
opts.on("-v", "--version", "Display the Pry version.") do
puts "Pry version #{Pry::VERSION} on Ruby #{RUBY_VERSION}"
exit
View
34 lib/pry.rb
@@ -3,16 +3,30 @@
direc = File.dirname(__FILE__)
+$LOAD_PATH << File.expand_path(direc)
+
require "method_source"
+require 'shellwords'
require "readline"
require "stringio"
-require "#{direc}/pry/version"
-require "#{direc}/pry/hooks"
-require "#{direc}/pry/print"
-require "#{direc}/pry/command_base"
-require "#{direc}/pry/commands"
-require "#{direc}/pry/prompts"
-require "#{direc}/pry/completion"
-require "#{direc}/pry/core_extensions"
-require "#{direc}/pry/pry_class"
-require "#{direc}/pry/pry_instance"
+require "coderay"
+
+if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
+ begin
+ require 'win32console'
+ rescue LoadError
+ $stderr.puts "Need to `gem install win32console`"
+ exit 1
+ end
+end
+
+require "pry/version"
+require "pry/hooks"
+require "pry/print"
+require "pry/command_base"
+require "pry/commands"
+require "pry/prompts"
+require "pry/completion"
+require "pry/core_extensions"
+require "pry/pry_class"
+require "pry/pry_instance"
View
46 lib/pry/commands.rb
@@ -1,9 +1,7 @@
-direc = File.dirname(__FILE__)
-
require "optparse"
require "method_source"
-require "#{direc}/command_base"
-require "#{direc}/pry_instance"
+require "pry/command_base"
+require "pry/pry_instance"
class Pry
@@ -25,6 +23,10 @@ class Commands < CommandBase
raise "Cannot retrieve source for dynamically defined method."
end
end
+
+ remove_first_word = lambda do |text|
+ text.split.drop(1).join(' ')
+ end
command "!", "Clear the input buffer. Useful if the parsing process goes wrong and you get stuck in the read loop." do
output.puts "Input buffer cleared!"
@@ -41,6 +43,11 @@ class Commands < CommandBase
alias_command "quit-program", "exit-program", ""
+ command "toggle-color", "Toggle syntax highlighting." do
+ Pry.color = !Pry.color
+ output.puts "Syntax highlighting #{Pry.color ? "on" : "off"}"
+ end
+
command "nesting", "Show nesting information." do
nesting = opts[:nesting]
@@ -76,7 +83,7 @@ class Commands < CommandBase
end
command "exit-all", "End all nested Pry sessions. Accepts optional return value. Aliases: !@" do
- str = opts[:val].split.drop(1).join(' ')
+ str = remove_first_word.call(opts[:val])
throw(:breakout, [0, target.eval(str)])
end
@@ -219,15 +226,23 @@ class Commands < CommandBase
info.sort_by { |k, v| v.last }.each do |k, v|
if !v.first.empty?
output.puts "#{k}:\n--"
- output.puts Pry.view(v.first)
+ if Pry.color
+ output.puts CodeRay.scan(Pry.view(v.first), :ruby).term
+ else
+ output.puts Pry.view(v.first)
+ end
output.puts
end
end
# plain
else
list = info.values.sort_by { |v| v.last }.map { |v| v.first }.inject(&:+)
- output.puts Pry.view(list)
+ if Pry.color
+ output.puts CodeRay.scan(Pry.view(list), :ruby).term
+ else
+ output.puts Pry.view(list)
+ end
list
end
end
@@ -364,6 +379,11 @@ class Commands < CommandBase
check_for_dynamically_defined_method.call(file)
output.puts "--\nFrom #{file} @ line ~#{line}:\n--"
+
+ if Pry.color
+ doc = CodeRay.scan(doc, :ruby).term
+ end
+
output.puts doc
doc
end
@@ -426,6 +446,11 @@ class Commands < CommandBase
check_for_dynamically_defined_method.call(file)
output.puts "--\nFrom #{file} @ line #{line}:\n--"
+
+ if Pry.color
+ code = CodeRay.scan(code, :ruby).term
+ end
+
output.puts code
code
end
@@ -444,6 +469,11 @@ class Commands < CommandBase
check_for_dynamically_defined_method.call(file)
output.puts "--\nFrom #{file} @ line #{line}:\n--"
+
+ if Pry.color
+ code = CodeRay.scan(code, :ruby).term
+ end
+
output.puts code
code
else
@@ -467,7 +497,7 @@ class Commands < CommandBase
end
command "exit", "End the current Pry session. Accepts optional return value. Aliases: quit, back" do
- str = opts[:val].split.drop(1).join(' ')
+ str = remove_first_word.call(opts[:val])
throw(:breakout, [opts[:nesting].level, target.eval(str)])
end
View
6 lib/pry/print.rb
@@ -8,7 +8,11 @@ class Pry
output.puts "#{value.class}: #{value.message}"
output.puts "from #{value.backtrace.first}"
else
- output.puts "=> #{Pry.view(value)}"
+ if Pry.color
+ output.puts "=> #{CodeRay.scan(Pry.view(value), :ruby).term}"
+ else
+ output.puts "=> #{Pry.view(value)}"
+ end
end
end
end
View
2 lib/pry/prompts.rb
@@ -22,5 +22,5 @@ class Pry
]
# A simple prompt - doesn't display target or nesting level
- SIMPLE_PROMPT = [proc { "pry> " }, proc { "pry* " }]
+ SIMPLE_PROMPT = [proc { ">> " }, proc { ">* " }]
end
View
16 lib/pry/pry_class.rb
@@ -1,14 +1,3 @@
-direc = File.dirname(__FILE__)
-
-require 'readline'
-require 'shellwords'
-require "#{direc}/prompts"
-require "#{direc}/hooks"
-require "#{direc}/print"
-require "#{direc}/commands"
-require "#{direc}/core_extensions"
-require "#{direc}/pry_instance"
-
# @author John Mair (banisterfiend)
class Pry
@@ -69,6 +58,10 @@ class << self
# Value returned by last executed Pry command.
# @return [Object] The command value
attr_accessor :cmd_ret_value
+
+ # Determines whether colored output is enabled.
+ # @return [Boolean]
+ attr_accessor :color
end
# Start a Pry REPL.
@@ -157,6 +150,7 @@ def self.reset_defaults
@prompt = DEFAULT_PROMPT
@print = DEFAULT_PRINT
@hooks = DEFAULT_HOOKS
+ @color = false
end
self.reset_defaults
View
3 lib/pry/pry_instance.rb
@@ -1,6 +1,3 @@
-require 'readline'
-require 'shellwords'
-
class Pry
# The list of configuration options.
View
2 lib/pry/version.rb
@@ -1,3 +1,3 @@
class Pry
- VERSION = "0.6.6"
+ VERSION = "0.6.7pre3"
end

0 comments on commit f1c5fa4

Please sign in to comment.