-
-
Save codenamev/d8b8ee0cb73e88bec969fe67aec6cbb8 to your computer and use it in GitHub Desktop.
My pryrc file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pry.hooks.add_hook(:before_eval, "runtime_start") do |output, pry| | |
pry.instance_variable_set(:"@x_runtime_start", Process.clock_gettime(Process::CLOCK_MONOTONIC)) | |
end | |
Pry.hooks.add_hook(:after_eval, "runtime_end") do |output, pry| | |
pry.instance_variable_set(:"@x_runtime_end", Process.clock_gettime(Process::CLOCK_MONOTONIC)) | |
end | |
Pry.config.print = proc do |output, value, _pry_| | |
rts = _pry_.instance_variable_get(:"@x_runtime_start") | |
rte = _pry_.instance_variable_get(:"@x_runtime_end") | |
_pry_.instance_variable_set(:"@x_runtime_start", false) | |
_pry_.instance_variable_set(:"@x_runtime_end", false) | |
if rts && rte | |
rt = (rte - rts) | |
rtms = (rt * 1000.0).round | |
rtus = (rt * 1000.0 * 1000.0).round | |
rtf = rtms.zero? ? "#{rtus}µs" : "#{rtms}ms" | |
end | |
_pry_.pager.open do |pager| | |
pager.print "\e[30m#{rtf}\e[0m #{_pry_.config.output_prefix}" | |
Pry::ColorPrinter.pp(value, pager, output.width) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment