The project is in a healthy, maintained state
Format data as terminal tables with Unicode, ASCII, Markdown, or compact styles. Supports column alignment, auto-sizing, and ANSI color-safe width calculation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

philiprehberger-table

Tests Gem Version License

Terminal table formatting with Unicode borders, alignment, and multiple styles

Requirements

  • Ruby >= 3.1

Installation

Add to your Gemfile:

gem "philiprehberger-table"

Or install directly:

gem install philiprehberger-table

Usage

require "philiprehberger/table"

table = Philiprehberger::Table.new(
  headers: %w[Name Age City],
  rows: [
    %w[Alice 30 NYC],
    %w[Bob 25 LA]
  ]
)

puts table.render
# ┌───────┬─────┬──────┐
# │ Name  │ Age │ City │
# ├───────┼─────┼──────┤
# │ Alice │ 30  │ NYC  │
# │ Bob   │ 25  │ LA   │
# └───────┴─────┴──────┘

Styles

table.render(style: :unicode)   # Unicode box-drawing (default)
table.render(style: :ascii)     # +---+---+ borders
table.render(style: :markdown)  # | col | col | (valid Markdown)
table.render(style: :compact)   # Space-aligned, no borders

Column Alignment

table = Philiprehberger::Table.new(
  headers: %w[Name Amount],
  rows: [%w[Alice 100], %w[Bob 50]],
  align: { 0 => :left, 1 => :right }
)

Supported alignments: :left (default), :right, :center.

ANSI Colors

ANSI escape sequences are stripped for width measurement but preserved in output, so colored text renders correctly.

API

Method Description
Table.new(headers:, rows: [], align: {}) Create a new table grid with headers, optional rows, and column alignment
Grid#render(style: :unicode) Render the table as a string (:unicode, :ascii, :markdown, :compact)
Grid#to_s Render with the default Unicode style
Styles.fetch(name) Return a style definition hash; raises KeyError for unknown styles

Development

bundle install
bundle exec rspec
bundle exec rubocop

License

MIT