{"id":13484201,"url":"https://github.com/cldwalker/hirb","last_synced_at":"2025-05-14T15:05:37.507Z","repository":{"id":516888,"uuid":"144937","full_name":"cldwalker/hirb","owner":"cldwalker","description":"A mini view framework for console/irb that's easy to use, even while under its influence. Console goodies include a no-wrap table, auto-pager, tree and menu.","archived":false,"fork":false,"pushed_at":"2024-02-28T04:13:19.000Z","size":1238,"stargazers_count":1661,"open_issues_count":18,"forks_count":71,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-05-05T12:57:36.909Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://tagaholic.me/hirb/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cldwalker.png","metadata":{"files":{"readme":"README.rdoc","changelog":"CHANGELOG.rdoc","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2009-03-07T01:13:19.000Z","updated_at":"2025-03-23T17:30:54.000Z","dependencies_parsed_at":"2024-06-21T20:15:25.600Z","dependency_job_id":null,"html_url":"https://github.com/cldwalker/hirb","commit_stats":{"total_commits":434,"total_committers":17,"mean_commits":"25.529411764705884","dds":"0.048387096774193505","last_synced_commit":"264f72c7c0f0966001e802414a5b0641036c7860"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldwalker%2Fhirb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldwalker%2Fhirb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldwalker%2Fhirb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cldwalker%2Fhirb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cldwalker","download_url":"https://codeload.github.com/cldwalker/hirb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253678844,"owners_count":21946314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:01:20.528Z","updated_at":"2025-05-14T15:05:37.000Z","avatar_url":"https://github.com/cldwalker.png","language":"Ruby","readme":"To read a linked version of this README, {click here}[http://tagaholic.me/hirb/doc/].\n\n== Description\n\nHirb provides a mini view framework for console applications and uses it to improve ripl(irb)'s default inspect output.\nGiven an object or array of objects, hirb renders a view based on the object's class and/or ancestry. Hirb offers reusable\nviews in the form of helper classes. The two main helpers, Hirb::Helpers::Table and Hirb::Helpers::Tree, provide several options\nfor generating ascii tables and trees. Using Hirb::Helpers::AutoTable, hirb has useful default views for at least ten popular database gems\ni.e. Rails' ActiveRecord::Base. Other than views, hirb offers a smart pager and a console menu. The smart pager\nonly pages when the output exceeds the current screen size. The menu is used in conjunction with tables to offer\n{two dimensional menus}[http://tagaholic.me/2010/02/16/two-dimensional-console-menus-with-hirb.html].\n\n== Install\n\nInstall the gem with:\n\n    gem install hirb\n\nFor people using full-width unicode characters, install {hirb-unicode}[https://github.com/miaout17/hirb-unicode]:\n\n    gem install hirb-unicode\n\n== View Tutorials\n\n* To create and configure views, see Hirb::View or {here if on the web}[http://tagaholic.me/hirb/doc/classes/Hirb/View.html].\n* To create dynamic views, see Hirb::DynamicView or {here if on the web}[http://tagaholic.me/hirb/doc/classes/Hirb/DynamicView.html].\n\n== Printing Ascii Tables\n\nTo print ascii tables from an array of arrays, hashes or any objects:\n\n  puts Hirb::Helpers::AutoTable.render(ARRAY_OF_OBJECTS)\n\nHirb will intelligently pick up on field names from an array of hashes and create properly-aligned\nfields from an array of arrays. See\n{here}[http://tagaholic.me/2009/10/15/boson-and-hirb-interactions.html#hirbs_handy_tables] for examples.\n\n== Rails Example\n\nLet's load and enable the view framework:\n  $ rails console\n  Loading local environment (Rails 3.0.3)\n  \u003e\u003e require 'hirb'\n  =\u003e true\n  \u003e\u003e Hirb.enable\n  =\u003e nil\n\nThe default configuration provides table views for ActiveRecord::Base descendants.\nIf a class isn't configured, Hirb reverts to irb's default echo mode.\n  \u003e\u003e Hirb::Formatter.dynamic_config['ActiveRecord::Base']\n  =\u003e {:class=\u003eHirb::Helpers::AutoTable, :ancestor=\u003etrue}\n\n  # Tag is a model class and descendant of ActiveRecord::Base\n  \u003e\u003e Tag.last\n  +-----+-------------------------+-------------+---------------+-----------+-----------+-------+\n  | id  | created_at              | description | name          | namespace | predicate | value |\n  +-----+-------------------------+-------------+---------------+-----------+-----------+-------+\n  | 907 | 2009-03-06 21:10:41 UTC |             | gem:tags=yaml | gem       | tags      | yaml  |\n  +-----+-------------------------+-------------+---------------+-----------+-----------+-------+\n  1 row in set\n\n  \u003e\u003e Hirb::Formatter.dynamic_config['String']\n  =\u003e nil\n  \u003e\u003e 'plain ol irb'\n  =\u003e 'plain ol irb'\n  \u003e\u003e Hirb::Formatter.dynamic_config['Symbol']\n  =\u003e nil\n  \u003e\u003e :blah\n  =\u003e :blah\n\nFrom above you can see there are no views configured for a String or a Symbol so Hirb defaults to\nirb's echo mode. On the other hand, Tag has a view thanks to being a descendant of ActiveRecord::Base\nand there being an :ancestor option.\n\nHaving seen hirb display views based on an output object's class, let's see it handle an array of objects:\n\n  \u003e\u003e Tag.all :limit=\u003e3, :order=\u003e\"id DESC\"\n  +-----+-------------------------+-------------+-------------------+-----------+-----------+----------+\n  | id  | created_at              | description | name              | namespace | predicate | value    |\n  +-----+-------------------------+-------------+-------------------+-----------+-----------+----------+\n  | 907 | 2009-03-06 21:10:41 UTC |             | gem:tags=yaml     | gem       | tags      | yaml     |\n  | 906 | 2009-03-06 08:47:04 UTC |             | gem:tags=nomonkey | gem       | tags      | nomonkey |\n  | 905 | 2009-03-04 00:30:10 UTC |             | article:tags=ruby | article   | tags      | ruby     |\n  +-----+-------------------------+-------------+-------------------+-----------+-----------+----------+\n  3 rows in set\n\nAt any time you can disable Hirb if you really like irb's lovely echo mode:\n  \u003e\u003e Hirb.disable\n  =\u003e nil\n  \u003e\u003e Tag.all :limit=\u003e3, :order=\u003e\"id DESC\"\n  =\u003e [#\u003cTag id: 907, name: \"gem:tags=yaml\", description: nil, created_at: \"2009-03-06 21:10:41\",\n  namespace: \"gem\", predicate: \"tags\", value: \"yaml\"\u003e, #\u003cTag id: 906, name: \"gem:tags=nomonkey\",\n  description: nil, created_at: \"2009-03-06 08:47:04\", namespace: \"gem\", predicate: \"tags\", value:\n  \"nomonkey\"\u003e, #\u003cTag id: 905, name: \"article:tags=ruby\", description: nil, created_at: \"2009-03-04\n  00:30:10\", namespace: \"article\", predicate: \"tags\", value: \"ruby\"\u003e]\n\n== Views: Anytime, Anywhere\nWhile preconfigured tables are great for database records, sometimes you just want to create\ntables/views for any output object:\n  \n  #These examples don't need to have Hirb::View enabled.\n  \u003e\u003e Hirb.disable\n  =\u003e nil\n\n  # Imports table() and view()\n  \u003e\u003e extend Hirb::Console\n  =\u003e main\n\n  # Create a unicode table\n  \u003e\u003e table [[:a, :b, :c]], :unicode =\u003e true\n  ┌───┬───┬───┐\n  │ 0 │ 1 │ 2 │\n  ├───┼───┼───┤\n  │ a ╎ b ╎ c │\n  └───┴───┴───┘\n  1 row in set\n\n  # Creates github-markdown\n  \u003e\u003e table [[:a, :b, :c]], :markdown =\u003e true\n  | 0 | 1 | 2 |\n  |---|---|---|\n  | a | b | c |\n\n  # Create a table of Dates comparing them with different formats.\n  \u003e\u003e table [Date.today, Date.today.next_month], :fields=\u003e[:to_s, :ld, :ajd, :amjd, :asctime]\n  +------------+--------+-----------+-------+--------------------------+\n  | to_s       | ld     | ajd       | amjd  | asctime                  |\n  +------------+--------+-----------+-------+--------------------------+\n  | 2009-03-11 | 155742 | 4909803/2 | 54901 | Wed Mar 11 00:00:00 2009 |\n  | 2009-04-11 | 155773 | 4909865/2 | 54932 | Sat Apr 11 00:00:00 2009 |\n  +------------+--------+-----------+-------+--------------------------+\n  2 rows in set\n\n  # Same table as the previous method. However view() will be able to call any helper.\n  \u003e\u003e view [Date.today, Date.today.next_month], :class=\u003e:object_table,\n    :fields=\u003e[:to_s, :ld, :ajd, :amjd, :asctime]\n\nIf these console methods weren't convenient enough, try:\n\n  # Imports view() to all objects.\n  \u003e\u003e require 'hirb/import_object'\n  =\u003e true\n  # Yields same table as above examples.\n  \u003e\u003e [Date.today, Date.today.next_month].view :class=\u003e:object_table,\n    :fields=\u003e[:to_s, :ld, :ajd, :amjd, :asctime]\n\nAlthough views by default are printed to STDOUT, they can be easily modified to write anywhere:\n  # Setup views to write to file 'console.log'.\n  \u003e\u003e Hirb::View.render_method = lambda {|output| File.open(\"console.log\", 'w') {|f| f.write(output) } }\n\n  # Writes to file with same table output as above example.\n  \u003e\u003e view [Date.today, Date.today.next_month], :class=\u003e:object_table,\n    :fields=\u003e[:to_s, :ld, :ajd, :amjd, :asctime]\n\n  # Doesn't write to file because Symbol doesn't have a view and thus defaults to irb's echo mode.\n  \u003e\u003e :blah\n  =\u003e :blah\n\n  # Go back to printing Hirb views to STDOUT.\n  \u003e\u003e Hirb::View.reset_render_method\n\n== Pager\n\nHirb has both pager and formatter functionality enabled by default. Note - if you copy and paste\ninto your ruby console and think that one of your lines will kick off the pager, be aware that subsequent\ncharacters will go to your pager and could cause side effects like saving a file.\n\nIf you want to turn off the functionality of either pager or formatter, pass that in at startup:\n\n  Hirb.enable :pager=\u003efalse\n  Hirb.enable :formatter=\u003efalse\n\nor toggle their state at runtime:\n\n  Hirb::View.toggle_pager\n  Hirb::View.toggle_formatter\n\n== Sharing Helpers and Views\nIf you have tested helpers you'd like to share, fork Hirb and put them under lib/hirb/helpers. To share\nviews for certain classes, put them under lib/hirb/views. Please submit views for gems that have a nontrivial\nnumber of users.\n\n== Limitations\nIf using Wirble and irb, you should call Hirb after it since they both override irb's default output.\n\n== Motivation\nTable code from http://gist.github.com/72234 and {my console app's needs}[http://github.com/cldwalker/tag-tree].\n\n== Credits\n* Chrononaut for vertical table helper.\n* janlelis for unicode table helper.\n* technogeeky and FND for markdown table helper.\n* hsume2, crafterm, spastorino, xaviershay, bogdan, asanghi, vwall, maxmeyer, jimjh, ddoherty03,\n  rochefort and joshua for patches.\n\n== Bugs/Issues\nPlease report them {on github}[http://github.com/cldwalker/hirb/issues].\n\n== Contributing\n{See here}[http://tagaholic.me/contributing.html]\n\n== Links\n* http://tagaholic.me/2009/03/13/hirb-irb-on-the-good-stuff.html\n* http://tagaholic.me/2009/03/18/ruby-class-trees-rails-plugin-trees-with-hirb.html\n* http://tagaholic.me/2009/06/19/page-irb-output-and-improve-ri-with-hirb.html\n","funding_links":[],"categories":["Ruby","IRB"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcldwalker%2Fhirb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcldwalker%2Fhirb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcldwalker%2Fhirb/lists"}