Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Pry Support #46

Closed
ryanb opened this Issue August 21, 2011 · 8 comments

8 participants

Ryan Bates Gabriel Horner John Mair Robert Bialek harryhorn Ches Martin ebbflowgo shshank jain
Ryan Bates

Is Pry supported? I tried Hirb.enable but it doesn't look like it worked. If it is supported, maybe provide some docs.

Gabriel Horner
Owner

Hirb currently supports irb and ripl. I'm not looking to add and support more shells. This could probably be done as a pry plugin. To give you an idea of what's needed, here's the ripl plugin. Basically you need to Hirb.enable and then extend whatever Pry method that formats the resulting object of a shell operation: Hirb::View.view_or_page_output(object) || original_pry_method(object)

John Mair

@ryanb,

I haven't tested this but try putting something like this in your .pryrc:

require 'hirb'

Pry.config.print = proc do |output, value|
  Hirb::View.view_or_page_output(value) || Pry::DEFAULT_PRINT.call(output, value)
end
Robert Bialek

@banister
Thanks for sharing - your solution works perfectly!

Ryan Bates

@banister awesome, thanks for the code! That is simple enough that I don't think we really need a plugin. Closing this issue, but it might be nice to document this somewhere. Maybe the Pry wiki would be a better spot?

Ryan Bates ryanb closed this August 22, 2011
harryhorn

The suggestion works but is missing one line. Here is the complete code:

require 'hirb'

Hirb.enable

Pry.config.print = proc do |output, value|
  Hirb::View.view_or_page_output(value) || Pry::DEFAULT_PRINT.call(output, value)
end
Ches Martin
ches commented August 28, 2011

One more iteration -- I've expanded it to the following semi-dirty hack in my .pryrc, because there are often times that I want to toggle Hirb off for a moment with Hirb.disable:

begin
  require 'hirb'
rescue LoadError
  # Missing goodies, bummer
end

if defined? Hirb
  # Dirty hack to support in-session Hirb.disable/enable
  Hirb::View.instance_eval do
    def enable_output_method
      @output_method = true
      Pry.config.print = proc do |output, value|
        Hirb::View.view_or_page_output(value) || Pry::DEFAULT_PRINT.call(output, value)
      end
    end

    def disable_output_method
      Pry.config.print = proc { |output, value| Pry::DEFAULT_PRINT.call(output, value) }
      @output_method = nil
    end
  end

  Hirb.enable
end

I've updated the Pry wiki FAQ entry.

ebbflowgo

Awesome stuff.

shshank jain

Using Rails 3.2.12. Have added pry to Gemfile along with hirb. The above fix doesnt seem to be working.

puts Hirb::Helpers::AutoTable.render(User.first) 

works.

Update: I must be high on caffeine or something, I tried @harryhorn trick again and it worked :)

-Shanky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.