The Ruby toolbox that you can use for building CLI projects

Features

All too often projects that interact with command line create their own interface logic that gathers input from users and displays information back. Many times utility files are created that contain methods for reading system or terminal properties. Shouldn't we focus our energy on building the actual client? Our time and energy should be spent on creating the tools not the foundation.

  • Table rendering with an easy-to-use API.
  • Terminal output colorization.
  • Terminal & System detection utilities.
  • Text manipulation (wrapping/truncation).
  • Shell user interface.
  • Configuration file management.
  • Multilevel logger.
  • Plugin ecosystem.
  • No dependencies to allow for easy gem vendoring.
  • Fully tested with major ruby interpreters.

Quick Start

While installling TTY is simple, there are few requirements. TTY is installed and managed via rubygems, the ruby package manager.

Installation

$ gem install tty

Data Tables

Handling of tabular data

table = TTY::Table.new header: ['h1', 'h2'], rows: [['a1', 'a2'], ['b1', 'b2']]

Shell Interactions

The library provides small DSL to help with parsing and asking precise questions in the shell.

shell  = TTY::Shell.new
shell.ask "What is your name?" do
  argument :required
  default  'Piotr'
  validate /\w+\s\w+/
  valid    ['Piotr', 'Piotrek']
  modify   :capitalize
end.read_string

Terminal

term = TTY::Terminal.new
# => red bold text on green background
term.color.set 'text...', :bold, :red, :on_green

View source on github

Brought to you by Piotr Murach