Sha256: c603c5d8ff5fd54a9f974c8722d36c19d60a557482c4624edc1253ad36d13816

Contents?: true

Size: 1.36 KB

Versions: 9

Compression:

Stored size: 1.36 KB

Contents

Irbtools.add_library :hirb, thread: :paint do
  Hirb::View.enable output: { "Object" => { ancestor: true, options: { unicode: true }}},
                    pager_command: 'less -R'
  extend Hirb::Console

  def page(what, options = {})
    Hirb::Pager.command_pager(what, options = {})
  end

  # page wirb output hacks
  class Hirb::Pager
    alias original_activated_by? activated_by?
    def activated_by?(string_to_page, inspect_mode=false)
      original_activated_by?(Paint.unpaint(string_to_page || ''), inspect_mode)
    end
  end

  class << Hirb::View
    def view_or_page_output(val)
      if defined?(val.inspect)
        unless view_output(val)
          if defined?(Wirb) && Wirb.running?
            page_output Wirb.colorize_result_with_timeout(val.inspect), true
          else
            page_output val.inspect, true
          end
        end
      end
    end
  end

  # colorful border
  table_color = :yellow
  Hirb::Helpers::UnicodeTable::CHARS.each do |place, group|
    Hirb::Helpers::UnicodeTable::CHARS[place] =
    group.each do |name, part|
      if part.kind_of? String
        Hirb::Helpers::UnicodeTable::CHARS[place][name] = Paint[part, *table_color]
      elsif part.kind_of? Hash
        part.each do |special, char|
          Hirb::Helpers::UnicodeTable::CHARS[place][name][special] = Paint[char, *table_color]
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
irbtools-3.0.2 lib/irbtools/hirb.rb
irbtools-3.0.1 lib/irbtools/hirb.rb
irbtools-3.0.0 lib/irbtools/hirb.rb
irbtools-2.2.2 lib/irbtools/hirb.rb
irbtools-2.2.1 lib/irbtools/hirb.rb
irbtools-2.2.0 lib/irbtools/hirb.rb
irbtools-2.1.0 lib/irbtools/hirb.rb
irbtools-2.0.1 lib/irbtools/hirb.rb
irbtools-2.0.0 lib/irbtools/hirb.rb