# File lib/pry/pry_instance.rb, line 358
  def retrieve_line(eval_string, target)
    @indent.reset if eval_string.empty?

    current_prompt = select_prompt(eval_string, target)
    completion_proc = Pry::InputCompleter.build_completion_proc(target,
                                                        instance_eval(&custom_completions))


    indentation = Pry.config.auto_indent ? @indent.current_prefix : ''

    begin
      val = readline("#{current_prompt}#{indentation}", completion_proc)

    # Handle <Ctrl+C> like Bash, empty the current input buffer but do not quit.
    # This is only for ruby-1.9; other versions of ruby do not let you send Interrupt
    # from within Readline.
    rescue Interrupt
      output.puts ""
      eval_string.replace("")
      return
    end

    # invoke handler if we receive EOF character (^D)
    if !val
      output.puts ""
      Pry.config.control_d_handler.call(eval_string, self)
      return
    end

    # Change the eval_string into the input encoding (Issue 284)
    # TODO: This wouldn't be necessary if the eval_string was constructed from
    # input strings only.
    if should_force_encoding?(eval_string, val)
      eval_string.force_encoding(val.encoding)
    end

    if Pry.config.auto_indent && !input.is_a?(StringIO)
      original_val = "#{indentation}#{val}"
      indented_val = @indent.indent(val)

      if output.tty? && Pry::Helpers::BaseHelpers.use_ansi_codes? && Pry.config.correct_indent
        output.print @indent.correct_indentation(current_prompt, indented_val, original_val.length - indented_val.length)
        output.flush
      end
    else
      indented_val = val
    end

    begin
      if !process_command(val, eval_string, target)
        eval_string << "#{indented_val.rstrip}\n" unless val.empty?
      end
    ensure
      Pry.history << indented_val unless input.is_a?(StringIO)
    end
  end