1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

version 0.8.0pre4, suppress output from command that dont have return

values. suppress output from all expressions that end in a ';'. Added
`gem-cd` command that chdir to the directory containing the gem files.
This commit is contained in:
John Mair 2011-04-08 02:13:16 +12:00
parent 1aa4a66ffc
commit f026516673
5 changed files with 53 additions and 19 deletions

4
TODO
View file

@ -1,10 +1,10 @@
FUTURE
* allows pipes (|) for commands
* `strip_leading_whitespace` freaks out when method has no
documentation; fix this
0.8.0
* add ; at end of line to suppress return value output
* Remove message spam (before/after hooks)
* stop commands returning a value and allow all statements to suppress
values being returned by ending line in ';'
* use `redo` in the r() method when encounter a command

View file

@ -2,6 +2,9 @@ require 'forwardable'
class Pry
class CommandProcessor
SYSTEM_COMMAND_DELIMITER = "."
SYSTEM_COMMAND_REGEX = /^#{Regexp.escape(SYSTEM_COMMAND_DELIMITER)}(.*)/
extend Forwardable
attr_reader :pry_instance
@ -12,20 +15,22 @@ class Pry
def_delegators :@pry_instance, :commands, :nesting, :output
# Run a system command (shell command).
# @param [String] val The shell command to execute.
# @return [Boolean] Whether
def system_command(val)
if val =~ /^\.(.*)/
execute_system_command($1)
val.clear
else
return false
end
true
def valid_command?(val)
system_command?(val) || pry_command?(val)
end
def execute_system_command(cmd)
def system_command?(val)
!!(SYSTEM_COMMAND_REGEX =~ val)
end
def pry_command?(val)
!!command_matched(val).first
end
def execute_system_command(val)
SYSTEM_COMMAND_REGEX =~ val
cmd = $1
if cmd =~ /^cd\s+(.+)/i
begin
Dir.chdir(File.expand_path($1))
@ -35,6 +40,8 @@ class Pry
else
system(cmd)
end
val.clear
end
# Determine whether a Pry command was matched and return command data
@ -63,7 +70,10 @@ class Pry
def val.clear() replace("") end
def eval_string.clear() replace("") end
return if system_command(val)
if system_command?(val)
execute_system_command(val)
return
end
cmd_data, args_string = command_matched(val)

View file

@ -120,6 +120,13 @@ class Pry
alias_command "quit-program", "exit-program", ""
alias_command "!!!", "exit-program", ""
command "gem-cd", "Change working directory to specified gem's directory." do |gem_name|
require 'rubygems'
gem_spec = Gem.source_index.find_name(gem_name).first
next output.put("Gem `#{gem_name}` not found.") if !gem_spec
Dir.chdir(File.expand_path(gem_spec.full_gem_path))
end
command "toggle-color", "Toggle syntax highlighting." do
Pry.color = !Pry.color
output.puts "Syntax highlighting #{Pry.color ? "on" : "off"}"

View file

@ -141,7 +141,8 @@ class Pry
# Pry.new.rep(Object.new)
def rep(target=TOPLEVEL_BINDING)
target = Pry.binding_for(target)
print.call output, re(target)
result = re(target)
print.call output, result if !@suppress_output
end
# Perform a read-eval
@ -185,13 +186,29 @@ class Pry
# Pry.new.r(Object.new)
def r(target=TOPLEVEL_BINDING)
target = Pry.binding_for(target)
@suppress_output = false
eval_string = ""
loop do
val = retrieve_line(eval_string, target)
process_line(val, eval_string, target)
break eval_string if valid_expression?(eval_string)
if valid_expression?(eval_string)
redo if null_input?(val)
break
end
end
@suppress_output = true if eval_string =~ /;\Z/
eval_string
end
# Returns true if input is "" and a command is not returning a
# value.
# @param [String] val The input string.
# @return [Boolean] Whether the input is null.
def null_input?(val)
val.empty? && !Pry.cmd_ret_value
end
# Read a line of input and check for ^d, also determine prompt to use.
@ -224,7 +241,7 @@ class Pry
if Pry.cmd_ret_value
eval_string << "Pry.cmd_ret_value\n"
else
eval_string << "#{val}\n"
eval_string << "#{val}\n" if !val.empty?
end
end

View file

@ -1,3 +1,3 @@
class Pry
VERSION = "0.8.0pre3"
VERSION = "0.8.0pre4"
end