mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
save before computer crash
This commit is contained in:
parent
ff4781a24e
commit
3c7a1c2eca
6 changed files with 19 additions and 12 deletions
10
lib/pry.rb
10
lib/pry.rb
|
@ -2,7 +2,7 @@
|
||||||
# MIT License
|
# MIT License
|
||||||
|
|
||||||
require 'pp'
|
require 'pp'
|
||||||
|
require 'pry/helpers/base_helpers'
|
||||||
class Pry
|
class Pry
|
||||||
# The default hooks - display messages when beginning and ending Pry sessions.
|
# The default hooks - display messages when beginning and ending Pry sessions.
|
||||||
DEFAULT_HOOKS = {
|
DEFAULT_HOOKS = {
|
||||||
|
@ -20,11 +20,7 @@ class Pry
|
||||||
|
|
||||||
# The default prints
|
# The default prints
|
||||||
DEFAULT_PRINT = proc do |output, value|
|
DEFAULT_PRINT = proc do |output, value|
|
||||||
if Pry.color
|
Helpers::BaseHelpers.stagger_output("=> #{Helpers::BaseHelpers.colorize_code(value.pretty_inspect)}", output)
|
||||||
output.puts "=> #{CodeRay.scan(value.pretty_inspect, :ruby).term}"
|
|
||||||
else
|
|
||||||
output.puts "=> #{Pry.view(value)}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Will only show the first line of the backtrace
|
# 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
|
# A simple prompt - doesn't display target or nesting level
|
||||||
SIMPLE_PROMPT = [proc { ">> " }, proc { ">* " }]
|
SIMPLE_PROMPT = [proc { ">> " }, proc { " | " }]
|
||||||
|
|
||||||
SHELL_PROMPT = [
|
SHELL_PROMPT = [
|
||||||
proc { |target_self, _| "pry #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
|
proc { |target_self, _| "pry #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
|
||||||
|
|
|
@ -22,8 +22,5 @@ class Pry
|
||||||
import DefaultCommands::Shell
|
import DefaultCommands::Shell
|
||||||
import DefaultCommands::Introspection
|
import DefaultCommands::Introspection
|
||||||
import DefaultCommands::EasterEggs
|
import DefaultCommands::EasterEggs
|
||||||
|
|
||||||
# Helpers::CommandHelpers.try_to_load_pry_doc
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -89,8 +89,12 @@ class Pry
|
||||||
# @return [OpenStruct]
|
# @return [OpenStruct]
|
||||||
attr_accessor :plugins
|
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
|
attr_accessor :memory_size
|
||||||
|
|
||||||
|
# @return [Boolean] Whether or not evalation results (`=>`) are sent
|
||||||
|
# through a pager.
|
||||||
|
attr_accessor :result_pager
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,7 @@ class Pry
|
||||||
alias_command "!!@", "exit-all", ""
|
alias_command "!!@", "exit-all", ""
|
||||||
|
|
||||||
command "exit-program", "End the current program. Aliases: quit-program, !!!" do
|
command "exit-program", "End the current program. Aliases: quit-program, !!!" do
|
||||||
|
Pry.active_instance.save_history if Pry.config.history.should_save
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,14 @@ class Pry
|
||||||
end
|
end
|
||||||
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)
|
def highlight(string, regexp, highlight_color=:bright_yellow)
|
||||||
highlighted = string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
|
highlighted = string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
|
||||||
end
|
end
|
||||||
|
@ -93,7 +101,7 @@ class Pry
|
||||||
# Try to use `less` for paging, if it fails then use
|
# Try to use `less` for paging, if it fails then use
|
||||||
# simple_pager. Also do not page if Pry.pager is falsey
|
# simple_pager. Also do not page if Pry.pager is falsey
|
||||||
# FIXME! Another JRuby hack
|
# FIXME! Another JRuby hack
|
||||||
def stagger_output(text)
|
def stagger_output(text, output=output())
|
||||||
if text.lines.count < page_size || !Pry.pager
|
if text.lines.count < page_size || !Pry.pager
|
||||||
output.puts text
|
output.puts text
|
||||||
return
|
return
|
||||||
|
|
|
@ -201,6 +201,7 @@ class Pry
|
||||||
config.history.file = File.expand_path("~/.pry_history")
|
config.history.file = File.expand_path("~/.pry_history")
|
||||||
|
|
||||||
config.memory_size = 100
|
config.memory_size = 100
|
||||||
|
config.results_pager = true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set all the configurable options back to their default values
|
# Set all the configurable options back to their default values
|
||||||
|
|
Loading…
Reference in a new issue