Pry Support #46

Closed
ryanb opened this Issue Aug 22, 2011 · 8 comments

Comments

Projects
None yet
8 participants
@ryanb

ryanb commented Aug 22, 2011

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

@cldwalker

This comment has been minimized.

Show comment
Hide comment
@cldwalker

cldwalker Aug 22, 2011

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)

Owner

cldwalker commented Aug 22, 2011

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)

@banister

This comment has been minimized.

Show comment
Hide comment
@banister

banister Aug 22, 2011

@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

@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
@rbialek

This comment has been minimized.

Show comment
Hide comment
@rbialek

rbialek Aug 22, 2011

@banister
Thanks for sharing - your solution works perfectly!

rbialek commented Aug 22, 2011

@banister
Thanks for sharing - your solution works perfectly!

@ryanb

This comment has been minimized.

Show comment
Hide comment
@ryanb

ryanb Aug 22, 2011

@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?

ryanb commented Aug 22, 2011

@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?

@ryanb ryanb closed this Aug 22, 2011

@harryhorn

This comment has been minimized.

Show comment
Hide comment
@harryhorn

harryhorn Aug 25, 2011

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

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

This comment has been minimized.

Show comment
Hide comment
@ches

ches Aug 29, 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.

ches commented Aug 29, 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.

@1dolinski

This comment has been minimized.

Show comment
Hide comment
@1dolinski

1dolinski Nov 7, 2012

Awesome stuff.

Awesome stuff.

@shshankjain

This comment has been minimized.

Show comment
Hide comment
@shshankjain

shshankjain Jul 25, 2013

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

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