From a5d72a146ff79627828ed17b9d8162dbe3e450ba Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 28 Dec 2012 11:18:29 -0800 Subject: [PATCH] Make interactive? explicit --- lib/pry/commands/hist.rb | 2 +- lib/pry/pry_instance.rb | 19 +++++++++---------- lib/pry/repl.rb | 8 -------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/lib/pry/commands/hist.rb b/lib/pry/commands/hist.rb index 12ce9c9c..9e4a2dd2 100644 --- a/lib/pry/commands/hist.rb +++ b/lib/pry/commands/hist.rb @@ -113,7 +113,7 @@ class Pry check_for_juxtaposed_replay(replay_sequence) replay_sequence.lines.each do |line| - _pry_.eval line + _pry_.eval line, :generated => true end end diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 7ce78691..5b038265 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -248,16 +248,18 @@ class Pry # value if applicable. # # @param [String?] line The line of input; `nil` if the user types `` + # @option options [Boolean] :generated Whether this line was generated automatically. + # Generated lines are not stored in history. # @return [Boolean] Is Pry ready to accept more input? # @raise [Exception] If the user uses the `raise-up` command, this method # will raise that exception. - def eval(line) + def eval(line, options={}) return false if @stopped exit_value = nil exception = catch(:raise_up) do exit_value = catch(:breakout) do - handle_line(line) + handle_line(line, options) # We use 'return !@stopped' here instead of 'return true' so that if # handle_line has stopped this pry instance (e.g. by opening _pry_.repl and # then popping all the bindings) we still exit immediately. @@ -274,15 +276,17 @@ class Pry return false end - def handle_line(line) + def handle_line(line, options) if line.nil? Pry.config.control_d_handler.call(@eval_string, self) return end + ensure_correct_encoding!(line) + Pry.history << line unless options[:generated] + @suppress_output = false inject_sticky_locals! - ensure_correct_encoding!(line) begin if !process_command_safely(line.lstrip) @eval_string << "#{line.chomp}\n" unless line.empty? @@ -332,6 +336,7 @@ class Pry throw(:breakout) if current_binding.nil? end + private :handle_line # @deprecated Use `Pry::REPL.new(pry, :target => target).start` instead. def repl(target = nil) @@ -395,12 +400,6 @@ class Pry end private :ensure_correct_encoding! - # Is the user typing into this {Pry} instance directly? - # @return [Boolean] - def interactive? - !input.is_a?(StringIO) - end - # If the given line is a valid command, process it in the context of the # current `eval_string` and binding. # @param [String] val The line to process. diff --git a/lib/pry/repl.rb b/lib/pry/repl.rb index f4c9177d..5117d307 100644 --- a/lib/pry/repl.rb +++ b/lib/pry/repl.rb @@ -102,17 +102,9 @@ class Pry indented_val = val end - Pry.history << indented_val if interactive? - indented_val end - # Is the user typing into this pry instance directly? - # @return [Boolean] - def interactive? - !input.is_a?(StringIO) - end - # Manage switching of input objects on encountering EOFErrors def handle_read_errors should_retry = true