Graphina 📊📈
Description
A Ruby gem for creating terminal-based data visualizations with real-time graphical displays using Unicode characters and ANSI styling 🎨📊
Documentation
Complete API documentation is available at: GitHub.io
Features
- Real-time Data Visualization: Create dynamic, continuously updating graphs in terminal environments
- Unicode Graphics: Utilize Unicode block characters for high-resolution terminal graphics (2px vertical resolution)
- ANSI Color Support: Full color management with 256-color and true-color (24-bit) support
- Multiple Display Modes: Single and double resolution modes for different terminal capabilities
- Flexible Data Sources: Support for custom data providers via Proc objects
- Multiple Formatting Options: Built-in formatters for bytes, hertz, celsius, and percentage values
- Efficient Rendering: Delta-based updates to minimize terminal I/O overhead
- Signal Handling: Graceful shutdown and terminal resize handling
- String-based Color Derivation: Automatically derive consistent colors from titles and labels
Installation
Add this gem to your Gemfile:
gem 'graphina'And install it using Bundler:
bundle installOr install the gem directly:
gem install graphinaUsage
1. Basic Usage with Random Data
# Simple usage with random data
graphina2. Custom Title and Text Colors
# Custom title with specific colors
graphina -t "CPU Usage (faked)" -f blue -b black3. More complex CPU Usage Monitoring example
# Monitor CPU usage in real-time
graphina -t 'CPU Usage' -n 1 -F as_percent -e "top -l 1 -n 0 | grep 'CPU usage' | awk '{print \$3+\$5}' | sed 's/%//'"4. Custom Data Source
# Using the library directly in Ruby code
require 'graphina'
graph = Graphina::Graph.new(
title: 'CPU Usage',
value: ->(i) { rand(100) },
format_value: :as_percent,
sleep: 1,
color: 33
)
graph.start5. Custom Command with External Data
# Using external command for data
graph = Graphina::Graph.new(
title: 'Temperature',
value: ->(i) { `sensors | grep 'Tctl' | awk '{print \$2}'`.to_f },
format_value: :as_celsius,
sleep: 2
)
graph.startCommand Line Options
Usage: graphina [OPTIONS]
OPTIONS are
-t TITLE Title for the graph (default: 'Data')
-n SECONDS Update interval in seconds (default: 5)
-r MODE Resolution mode (:single or :double, default: :double)
-f COLOR Foreground color (default: :white)
-b COLOR Background color (default: :black)
-c COLOR Primary color (default: derived from title)
-C COLOR Secondary color (default: derived from primary)
-F FORMAT Format function (:as_bytes, :as_hertz, :as_celsius, :as_percent, :as_default, default: :as_default)
-h this help
Author
Florian Frank 🧑💻