From 3c7a1c2ecaa88cc7ecfe5d95881aeb3157e7c9b7 Mon Sep 17 00:00:00 2001 From: John Mair Date: Sat, 11 Jun 2011 22:44:30 +1200 Subject: [PATCH] save before computer crash --- lib/pry.rb | 10 +++------- lib/pry/commands.rb | 3 --- lib/pry/config.rb | 6 +++++- lib/pry/default_commands/context.rb | 1 + lib/pry/helpers/base_helpers.rb | 10 +++++++++- lib/pry/pry_class.rb | 1 + 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/pry.rb b/lib/pry.rb index 9970b281..372659d6 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -2,7 +2,7 @@ # MIT License require 'pp' - +require 'pry/helpers/base_helpers' class Pry # The default hooks - display messages when beginning and ending Pry sessions. DEFAULT_HOOKS = { @@ -20,11 +20,7 @@ class Pry # The default prints DEFAULT_PRINT = proc do |output, value| - if Pry.color - output.puts "=> #{CodeRay.scan(value.pretty_inspect, :ruby).term}" - else - output.puts "=> #{Pry.view(value)}" - end + Helpers::BaseHelpers.stagger_output("=> #{Helpers::BaseHelpers.colorize_code(value.pretty_inspect)}", output) end # Will only show the first line of the backtrace @@ -53,7 +49,7 @@ class Pry ] # A simple prompt - doesn't display target or nesting level - SIMPLE_PROMPT = [proc { ">> " }, proc { ">* " }] + SIMPLE_PROMPT = [proc { ">> " }, proc { " | " }] SHELL_PROMPT = [ proc { |target_self, _| "pry #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " }, diff --git a/lib/pry/commands.rb b/lib/pry/commands.rb index 47c785d9..450e81aa 100644 --- a/lib/pry/commands.rb +++ b/lib/pry/commands.rb @@ -22,8 +22,5 @@ class Pry import DefaultCommands::Shell import DefaultCommands::Introspection import DefaultCommands::EasterEggs - -# Helpers::CommandHelpers.try_to_load_pry_doc - end end diff --git a/lib/pry/config.rb b/lib/pry/config.rb index eab4a287..c2e10e21 100644 --- a/lib/pry/config.rb +++ b/lib/pry/config.rb @@ -89,8 +89,12 @@ class Pry # @return [OpenStruct] attr_accessor :plugins - # @return [Integer] Amount of results that will be stored into _out_ + # @return [Integer] Amount of results that will be stored into out attr_accessor :memory_size + + # @return [Boolean] Whether or not evalation results (`=>`) are sent + # through a pager. + attr_accessor :result_pager end end diff --git a/lib/pry/default_commands/context.rb b/lib/pry/default_commands/context.rb index 618c60cb..72a5b1db 100644 --- a/lib/pry/default_commands/context.rb +++ b/lib/pry/default_commands/context.rb @@ -67,6 +67,7 @@ class Pry alias_command "!!@", "exit-all", "" command "exit-program", "End the current program. Aliases: quit-program, !!!" do + Pry.active_instance.save_history if Pry.config.history.should_save exit end diff --git a/lib/pry/helpers/base_helpers.rb b/lib/pry/helpers/base_helpers.rb index fb412b1b..52e08916 100644 --- a/lib/pry/helpers/base_helpers.rb +++ b/lib/pry/helpers/base_helpers.rb @@ -63,6 +63,14 @@ class Pry end end + def colorize_code(code) + if Pry.color + CodeRay.scan(code, :ruby).term + else + code + end + end + def highlight(string, regexp, highlight_color=:bright_yellow) highlighted = string.gsub(regexp) { |match| "<#{highlight_color}>#{match}" } end @@ -93,7 +101,7 @@ class Pry # Try to use `less` for paging, if it fails then use # simple_pager. Also do not page if Pry.pager is falsey # FIXME! Another JRuby hack - def stagger_output(text) + def stagger_output(text, output=output()) if text.lines.count < page_size || !Pry.pager output.puts text return diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index 15b7a992..8728907c 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -201,6 +201,7 @@ class Pry config.history.file = File.expand_path("~/.pry_history") config.memory_size = 100 + config.results_pager = true end # Set all the configurable options back to their default values