ruby-on-railsrubyhirb

Hirb - "Too many fields.." only when loading from irbrc (not directly in console)


I'm trying to get Hirb setup in my console.

When i type:

require 'hirb'
Hirb.enable

My (rather large) table prints fine (with column names shortened). However, I want to automatically load this (and other gems) whenever i load up rails c, so i edited my .irbc

  if Rails.env
    require 'rubygems'
    require 'hirb'
    Hirb.enable

    require 'wirble'
    Wirble.init
    Wirble.colorize

    require 'awesome_print'
  end

When running the same command from the console (Account.all), i then get the error:

Too many fields for the current width. Configure your width and/or fields to avoid this error. Defaulting to a vertical table

Any ideas why? I really like Hirb, but am too lazy to manually include it everytime i load the console


Solution

  • I managed to fix this. Turns out when i ran:

    Hirb::View.width
    

    in the console (after Hirb being loaded from .irbrc), I saw it was smaller than expected - so it seemed as though Hirb wasn't correctly detecing my console size.

    I changed my .irbrc file to explicitly pass in these values:

    require 'hirb'
    Hirb.enable({:width => 155, :height => 500})
    

    And all works as expected