Project

ruby_rich

0.0
A long-lived project that still receives updates
A Ruby gem providing rich text formatting, progress bars, tables and other console output enhancements
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 5.0
~> 13.0

Runtime

~> 3.6.1
~> 4.5.2
~> 0.7.1
~> 0.9.0
~> 0.8.2
 Project Readme

RubyRich - Advanced Ruby Terminal UI Toolkit

RubyRich Demo

A comprehensive Ruby terminal UI toolkit inspired by Python Rich, providing elegant formatting, advanced layouts, and professional terminal output.

โœจ Features

Core Text Features

  • ๐ŸŽจ Rich Markup Language - Intuitive [bold red]text[/bold red] syntax
  • ๐Ÿ–ฅ๏ธ Terminal Output - Elegant formatted output with automatic color detection
  • ๐Ÿ“ Text Styling - Chainable text styles with RGB/HEX color support

Advanced Content Rendering

  • ๐Ÿ–ผ๏ธ Syntax Highlighting - Built-in support for 200+ programming languages
  • ๐Ÿ“„ Markdown Rendering - Full markdown support with terminal-optimized output
  • ๐ŸŒณ Tree Display - Beautiful hierarchical data visualization
  • ๐Ÿ“Š Enhanced Tables - Auto-expanding tables with rich formatting

Layout & UI Components

  • ๐Ÿงฉ Panel Layouts - Create nested layouts with borders and styles
  • ๐Ÿ“‹ Multi-Column Layouts - Professional newspaper-style column formatting
  • ๐Ÿšฆ Status Indicators - Comprehensive status symbols and progress tracking
  • ๐Ÿ“ˆ Advanced Progress Bars - Multiple styles, ETA, rate calculation, and multi-progress support

Development Tools

  • ๐Ÿ” Object Inspection - Rich object debugging and inspection
  • ๐Ÿ“ Enhanced Logging - Structured logging with rich formatting
  • โšก High Performance - Optimized for large datasets and real-time updates

๐Ÿ“ฆ Installation

Add to Gemfile:

gem 'ruby_rich'

Or install directly:

gem install ruby_rich

๐Ÿš€ Quick Start

require 'ruby_rich'

# Rich markup language
puts RubyRich::RichText.markup("[bold green]Success![/bold green] Task completed.")

# Syntax highlighting
code = "def hello\n  puts 'world'\nend"
puts RubyRich.syntax(code, 'ruby')

# Markdown rendering
markdown = "# Title\n\nThis is **bold** text."
puts RubyRich.markdown(markdown)

# Tree structure
tree = RubyRich.tree("Project")
tree.add("src").add("main.rb")
tree.add("README.md")
puts tree.render

# Status indicators
puts RubyRich.status(:success, text: "All systems operational")
puts RubyRich.status(:warning, text: "High memory usage detected")

# Enhanced progress bar
RubyRich::ProgressBar.with_progress(100, title: "Processing", show_rate: true) do |bar|
  100.times { |i| bar.advance(1); sleep(0.01) }
end

๐Ÿ“š Advanced Features

Rich Markup Language

# Basic colors and styles
puts RubyRich::RichText.markup("[red]Error message[/red]")
puts RubyRich::RichText.markup("[bold]Important text[/bold]")
puts RubyRich::RichText.markup("[italic blue]Styled text[/italic blue]")

# Combined styles
puts RubyRich::RichText.markup("[bold red]Critical Alert![/bold red]")

Syntax Highlighting

# Automatic language detection
puts RubyRich.syntax("def hello; puts 'world'; end")

# Explicit language specification
python_code = "def fibonacci(n):\n    return n if n <= 1 else fibonacci(n-1) + fibonacci(n-2)"
puts RubyRich.syntax(python_code, 'python')

# Supported languages: Ruby, Python, JavaScript, JSON, HTML, CSS, SQL, and 200+ more

Markdown Rendering

markdown_text = <<~MARKDOWN
# Project Documentation

## Features
- **Rich formatting**
- *Syntax highlighting*
- `Code blocks`

### Code Example
```ruby
puts "Hello, Ruby Rich!"

This is a quote block

Visit our website MARKDOWN

puts RubyRich.markdown(markdown_text)


### Tree Structure Display
```ruby
# Manual tree construction
tree = RubyRich.tree("My Project")
src = tree.add("src")
src.add("main.rb")
src.add("utils.rb")
tree.add("README.md")

# From file paths
paths = ["app/models/user.rb", "app/views/users/index.html", "config/routes.rb"]
file_tree = RubyRich::Tree.from_paths(paths, "Rails App")

# From hash structure
data = {
  "Database" => {
    "Users" => ["john", "jane"],
    "Posts" => ["post1", "post2"]
  }
}
hash_tree = RubyRich::Tree.from_hash(data, "System")

Multi-Column Layouts

layout = RubyRich.columns(total_width: 80)

# Add columns with different configurations
left_col = layout.add_column(title: "News", align: :left)
right_col = layout.add_column(title: "Updates", align: :right)

left_col.add("Breaking: Ruby Rich 2.0 released!")
left_col.add("New features include advanced layouts")
right_col.add("Performance improved by 300%")
right_col.add("Memory usage reduced by 50%")

puts layout.render(show_headers: true, show_borders: true)

# Custom column ratios
layout.set_ratios(2, 1)  # 2:1 ratio

Status Indicators

# Basic status indicators
puts RubyRich.status(:success)     # โœ… Success
puts RubyRich.status(:error)       # โŒ Error
puts RubyRich.status(:warning)     # โš ๏ธ Warning
puts RubyRich.status(:info)        # โ„น๏ธ Info

# System status
puts RubyRich.status(:online)      # ๐ŸŸข Online
puts RubyRich.status(:offline)     # ๐Ÿ”ด Offline
puts RubyRich.status(:maintenance) # ๐Ÿ”ง Maintenance

# Status board
board = RubyRich::Status::StatusBoard.new(width: 50)
board.add_item("Web Server", :online, description: "Nginx running on port 80")
board.add_item("Database", :warning, description: "High connection count")
board.add_item("Cache", :error, description: "Redis connection failed")
puts board.render

Enhanced Progress Bars

# Basic progress bar with details
bar = RubyRich::ProgressBar.new(
  1000, 
  width: 40, 
  title: "Processing",
  show_percentage: true,
  show_rate: true,
  show_eta: true
)

bar.start
1000.times { |i| bar.advance(1); sleep(0.01) }
bar.finish(message: "โœ… Processing completed!")

# Different styles
styles = [:default, :blocks, :arrows, :dots, :line]
styles.each do |style|
  bar = RubyRich::ProgressBar.new(50, style: style, title: style.to_s)
  # ... progress ...
end

# Multiple progress bars
multi = RubyRich::ProgressBar::MultiProgress.new
bar1 = multi.add("File 1", 100)
bar2 = multi.add("File 2", 100) 
bar3 = multi.add("File 3", 100)
multi.start
# ... update bars individually ...
multi.finish_all

Enhanced Tables

# Rich content in tables
table = RubyRich::Table.new(headers: ["Feature", "Status", "Notes"])
table.add_row([
  RubyRich::RichText.markup("[cyan]Syntax Highlighting[/cyan]"),
  RubyRich::RichText.markup("[green]โœ… Complete[/green]"),
  "200+ languages supported"
])
table.add_row([
  RubyRich::RichText.markup("[cyan]Markdown Rendering[/cyan]"),
  RubyRich::RichText.markup("[yellow]๐Ÿšง Beta[/yellow]"),
  "Full CommonMark support"
])

puts table.render

๐ŸŽจ Themes and Customization

# Custom theme setup
RubyRich::RichText.set_theme({
  primary: { color: :blue, bold: true },
  secondary: { color: :cyan },
  accent: { color: :yellow, bold: true }
})

# Use themed styles
text = RubyRich::RichText.new("Important message", style: :primary)
puts text.render

๐Ÿ”ง Configuration

# Global console configuration
console = RubyRich::Console.new
console.set_layout(spacing: 2, align: :center)
console.style(:header, color: :blue, bold: true)

# Custom progress bar styles
RubyRich::ProgressBar::STYLES[:custom] = {
  filled: 'โ–“', empty: 'โ–‘', prefix: 'โŸจ', suffix: 'โŸฉ'
}

๐Ÿงช Testing & Examples

All examples and tests are located in the examples/ directory.

Run the comprehensive test suite:

ruby examples/test_all_features.rb

Run the complete feature demonstration:

ruby examples/demo_all_features.rb

Individual feature examples:

ruby examples/test_markup.rb      # Rich markup language
ruby examples/test_syntax.rb      # Syntax highlighting
ruby examples/test_markdown.rb    # Markdown rendering
ruby examples/test_tree.rb        # Tree structures
ruby examples/test_columns.rb     # Multi-column layouts
ruby examples/test_status.rb      # Status indicators
ruby examples/test_enhanced_progress.rb  # Progress bars

See examples/README.md for detailed information about each example file.

๐Ÿ“Š Performance

Ruby Rich is optimized for performance:

  • Processes 10,000+ markup elements per second
  • Renders large tables (1000+ rows) in milliseconds
  • Minimal memory footprint with efficient object management
  • Thread-safe for concurrent operations

๐Ÿค Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push branch (git push origin feature/amazing-feature)
  5. Create Pull Request

๐Ÿ“„ License

MIT License - See LICENSE

๐Ÿ™ Acknowledgments

  • Inspired by Python's Rich library
  • Built with โค๏ธ for the Ruby community
  • Special thanks to all contributors and testers

Ruby Rich - Making terminal applications beautiful, one line at a time. โœจ