Sai

Sai Version Sai Codacy grade Sai Codacy coverage Sai License Sai Docs Sai Open Issues

An elegant color management system for crafting sophisticated CLI applications

# Create beautiful CLI applications with intuitive color management
puts Sai.rgb(255, 128, 0).bold.decorate('Warning: Battery Low')
puts Sai.hex('#4834d4').italic.decorate('Processing request...')
puts Sai.bright_cyan.on_blue.underline.decorate('Download Complete!')

# Adjust color brightness
puts Sai.red.darken_text(0.3).decorate('Subtle Error Message')
puts Sai.blue.lighten_text(0.5).decorate('Highlighted Info')

# Analyze and manipulate ANSI-encoded text
text = Sai.sequence("\e[31mError:\e[0m Connection failed")
puts text.without_color  # Keep formatting, remove colors
puts text.stripped      # Get plain text without any formatting

Sai (彩) - meaning 'coloring' or 'paint' in Japanese - is a powerful and intuitive system for managing color output in command-line applications. Drawing inspiration from traditional Japanese artistic techniques, Sai brings vibrancy and harmony to terminal interfaces through its sophisticated color management.

Features

  • Rich color support (True Color, 256 colors, ANSI, and basic modes)
  • Automatic terminal capability detection and color mode adaptation
  • RGB, Hex, and named color support with bright variants
  • Comprehensive text styling (bold, italic, underline, etc.)
  • Advanced ANSI sequence parsing and manipulation
  • Intelligent color downgrading for compatibility
  • Respects NO_COLOR environment variable

Extended Color Palettes

Looking for additional color palettes? Check out Sai-Mei, which extends Sai with many curated color collections, including:

  • Web colors from CSS Color Module Level 4
  • Tailwind CSS color system
  • Extended 256-color xterm palette
# Install Sai-Mei alongside Sai
gem 'sai'
gem 'sai-mei'

# Then use sophisticated color palettes
require 'sai/mei'
Sai::Mei.css.install      # CSS colors
Sai::Mei.tailwind.install # Tailwind colors
Sai::Mei.xterm.install    # Terminal 256 colors

Installation

Add this line to your application's Gemfile:

gem 'sai'

Or install it yourself as:

gem install sai

[!IMPORTANT]
If you're upgrading from version 0.3.1, please see our Migration Guide for important changes.

Quick Start

require 'sai'

# Basic usage
puts Sai.red.decorate('Error!')
puts Sai.bright_blue.on_white.decorate('Info')

# Using RGB colors
puts Sai.rgb(255, 128, 0).decorate('Custom color')
puts Sai.on_rgb(0, 255, 128).decorate('Custom background')

# Color manipulation
puts Sai.blue.lighten_text(0.5).decorate('Lightened blue')
puts Sai.red.darken_text(0.3).decorate('Darkened red')

# Applying styles
puts Sai.bold.underline.decorate('Important')
puts Sai.red.bold.italic.decorate('Error!')

# Working with ANSI sequences
text = Sai.sequence("\e[31mError:\e[0m Details here")
puts text.without_color    # Remove colors but keep formatting
puts text.without_style    # Remove formatting but keep colors
puts text.stripped        # Get plain text

Documentation

Contributing

We welcome contributions! Please see our Contributing Guidelines for:

  • Development setup and workflow
  • Code style and documentation standards
  • Testing requirements
  • Pull request process

Before contributing, please review our Code of Conduct.

License

The gem is available as open source under the terms of the MIT License.