Termline::Tables

Termline includes a simple table helper for printing structured data in the terminal.

In most cases, you should use the public shortcut:

Termline.table(data, header: true)

Basic Usage

data = [
  { name: "Luis", role: "Admin", status: "Active" },
  { name: "Ana", role: "Developer", status: "Pending" },
  { name: "Marco", role: "Support", status: "Disabled" }
]

Termline.table(data)

Example output:

| NAME                     | ROLE                     | STATUS
| - - - - - - - - - - - - -| - - - - - - - - - - - - -| - - - - - - - - - - - -
| Luis                     | Admin                    | Active
| Ana                      | Developer                | Pending
| Marco                    | Support                  | Disabled

Using an Array of Hashes

The most common use case is an array of hashes:

data = [
  { engine: "Lesli", tests: 93, coverage: "98.4%" },
  { engine: "LesliBell", tests: 41, coverage: "91.2%" },
  { engine: "LesliAdmin", tests: 67, coverage: "95.0%" }
]

Termline.table(data)

When the input is an array of hashes:

Using an Array of Arrays

You can also pass an array of arrays:

data = [
  ["Luis", "Admin", "Active"],
  ["Ana", "Developer", "Pending"],
  ["Marco", "Support", "Disabled"]
]

Termline.table(data)

When the input is an array of arrays:

Header Option

Headers are enabled by default for hash-based data:

Termline.table(data, header: true)

You can disable the header row manually:

Termline.table(data, header: false)

ActiveRecord Support

If the input is an ActiveRecord::Relation, it is automatically converted into an array of hashes using serializable_hash:

users = User.limit(5)
Termline.table(users)

This makes it easy to print database records directly in the terminal.

Method Signature

Termline.table(data, header: true)

Parameters

data

Supported input types:

header

Controls whether the header row is displayed.

Default:

true

Behavior

Termline.table automatically:

Internally, this method delegates to Termline::Table.builder, but the recommended public API is Termline.table.

Advanced Usage

For most cases, Termline.table is the recommended API.

If you need lower-level control or want to integrate directly with the internal table builder, you can call:

Termline::Table.builder(data, header: true)

Example:

data = [
  { name: "Luis", role: "Admin", status: "Active" },
  { name: "Ana", role: "Developer", status: "Pending" }
]

Termline::Table.builder(data, header: true)

Use this only when you need direct access to the internal builder. For normal usage, prefer:

Termline.table(data, header: true)

Example with Application Data

Termline.info "Available users"

Termline.table([
  { id: 1, name: "Luis", email: "[email protected]" },
  { id: 2, name: "Ana", email: "[email protected]" }
])

 Edit this page

Last Update: 2026/03/25