Project

graphina

0.0
No release in over 3 years
Gem that provides terminal-based data visualization capabilities, enabling developers to create dynamic, real-time graphical displays of numerical data directly within terminal environments using Unicode characters and ANSI styling.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.0
~> 2.8

Runtime

~> 1.45
 Project Readme

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 install

Or install the gem directly:

gem install graphina

Usage

1. Basic Usage with Random Data

# Simple usage with random data
graphina

2. Custom Title and Text Colors

# Custom title with specific colors
graphina -t "CPU Usage (faked)" -f blue -b black

3. 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.start

5. 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.start

Command 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 🧑‍💻

License

MIT License 📄