rdx-stderr

Crates.iordx-stderr
lib.rsrdx-stderr
version0.8.4
created_at2025-07-30 18:30:20.90349+00
updated_at2025-08-12 18:23:26.505336+00
descriptionThe Rustadex Stderr Package. An opinionated, ergonomic library for pretty-okay CLI terminal output, made of sticks bubble gum and vintage bash scripts.
homepage
repositoryhttps://github.com/rustadex/stderr
max_upload_size
id1773881
size614,420
Qodeninja (qodeninja)

documentation

README

๐Ÿ“– Rustadex Stderr (rdx-stderr)

An opinionated, ergonomic library for pretty-okay CLI terminal output, made of sticks bubble gum and vintage bash scripts.

Crates.io Version MSRV License: MIT OR Apache-2.0 Status: PRD Ready

๐ŸŽฏ What is Stderr?

rdx-stderr is a Rust logging library inspired by years of handcrafted Bash scripts, designed to make your CLI applications beautiful and informative. It provides semantic logging functions, rich formatting utilities, and sophisticated tracing capabilities.

โœจ Key Features:

  • ๐Ÿ“Š Hierarchical Tracing: Visual function call trees with automatic entry/exit

  • ๐ŸŽจ Rich Formatting: Tables, banners, boxes with customizable styling

  • ๐Ÿ”ง Interactive Elements: Confirmations, prompts with intelligent defaults

  • โš™๏ธ Modular Architecture: Use only what you need via Cargo features

  • ๐ŸŒˆ Context Management: Smart banners for state changes

  • ๐ŸŽญ Customizable Glyphs: Unicode symbols that work everywhere

A demo of the rdx-stderr logger in action

A demo of the rdx-stderr logger in action

๐Ÿš€ Quick Start

Add to your Cargo.toml:

[dependencies]
rdx-stderr = "0.8.2"

# Or with specific features:
rdx-stderr = { version = "0.8.2", features = ["trace", "interactive", "formatting"] }

Basic Logging

use rdx_stderr::Stderr;

let mut log = Stderr::new();
log.info("Hello, world!");
log.warn("Something's not quite right");
log.okay("All systems go!");

With Hierarchical Tracing

use rdx_stderr::{Stderr, qtrace_fn};

let mut log = Stderr::new();

qtrace_fn!("parse_config", "starting configuration parsing");
qtrace_fn!("parse_config", "loaded 42 settings");
qtrace_fn!("validate_config", "checking required fields");
qtrace_fn!("validate_config", "validation successful");

Global Logger

use rdx_stderr::logger;

fn main() {
    logger.info("This works from anywhere!");
    logger.warn("Watch out!");
}

โœจ What's New (v0.8)

  • Hierarchical Tracing: Advanced function call tracing with visual tree structure
  • Context Management: Smart context tracking with automatic banner display
  • Enhanced Table System: Comprehensive table formatting for CLI data display
  • Feature Modularity: Granular feature flags for minimal builds
  • Auto Function Names: Optional automatic function name detection for tracing
  • Interactive Builders: Flexible confirmation prompts with styling options
  • Configurable Glyphs: 80+ Unicode glyphs with customizable sets
  • Performance Optimized: Efficient rendering for CLI responsiveness

โšก Philosophy: Fast, Expressive, Bash DNA

  • Terminal output should be beautiful and actionable, not just noise
  • Defaults are high signal, but you can theme, override, and hack anything
  • Built to match (and outclass) custom Bash stderr libs
  • Modular by design - use only what you need

โœฆ Features

๐ŸŽฏ Core Logging

  • ๐ŸŒˆ Drop-in Stderr logger or global logger
  • ๐Ÿ”ฅ Rich message types: info, warn, error, okay, debug, trace, magic
  • ๐Ÿงฉ Debug pretty-printing for Rust types
  • ๐ŸŒ€ Ergonomic API โ€” str, Display, Debug, all accepted

๐Ÿ” Advanced Tracing

  • ๐ŸŒฒ Hierarchical function call tracing with visual tree structure
  • ๐Ÿท๏ธ Automatic function name detection (optional feature)
  • โฑ๏ธ RAII scoped tracing with automatic entry/exit logging
  • ๐ŸŽจ Labelled trace helpers (add, sub, found, done, item)

๐ŸŽฏ Context Management

  • ๐Ÿ“ Smart context tracking with automatic banner display
  • ๐Ÿ”„ Context change detection (banners only show when context changes)
  • โšก Ephemeral context support for temporary operations
  • ๐ŸŽช Context scoping for isolated operations

๐Ÿ“Š Table & Formatting

  • ๐Ÿ“‹ Simple tables for data display
  • ๐Ÿ“ Column layouts for compact lists
  • ๐ŸŽ›๏ธ Flag tables for bitmap visualization
  • ๐Ÿ“ฆ Multiple box styles (light, heavy, double)
  • ๐ŸŽจ Banners and dividers

๐Ÿ’ฌ Interactive Features

  • โ“ Flexible confirmation prompts with styling
  • ๐Ÿ“ฆ Boxed prompts with border customization
  • ๐ŸŽจ Colored prompts and custom styling
  • ๐Ÿ“ Help text formatting

๐ŸŽจ Customization

  • ๐ŸŽญ 80+ configurable Unicode glyphs

  • ๐ŸŽจ Custom color schemes

  • ๐Ÿท๏ธ Application labeling

  • โš™๏ธ Runtime configuration toggles


๐Ÿงฉ Modular Features

rdx-stderr uses Cargo features for modular functionality:

  • default: Includes all features (trace, interactive, formatting, auto-fn-names)
  • minimal: Just core logging functionality
  • trace: Hierarchical function tracing with visual tree structure
  • interactive: User prompts, confirmations, and interactive elements
  • formatting: Tables, boxes, banners, and advanced text formatting
  • auto-fn-names: Automatic function name detection for tracing
# Minimal build - just basic logging
rdx-stderr = { version = "0.8.2", default-features = false, features = ["minimal"] }

# Full-featured build
rdx-stderr = { version = "0.8.2", features = ["default"] }

src/
โ”œโ”€โ”€ lib.rs              # Main library interface
โ”œโ”€โ”€ rdx/
โ”‚   โ”œโ”€โ”€ stderr.rs       # Core module with feature re-exports
โ”‚   โ”œโ”€โ”€ esc/            # Colors, glyphs, styling
โ”‚   โ”‚   โ”œโ”€โ”€ colors.rs
โ”‚   โ”‚   โ”œโ”€โ”€ glyphs.rs
โ”‚   โ”‚   โ”œโ”€โ”€ style.rs
โ”‚   โ”‚   โ””โ”€โ”€ boxes.rs
โ”‚   โ”œโ”€โ”€ utils/          # Utilities and helpers  
โ”‚   โ”‚   โ”œโ”€โ”€ helpers.rs
โ”‚   โ”‚   โ”œโ”€โ”€ flag.rs
โ”‚   โ”‚   โ””โ”€โ”€ grid.rs
โ”‚   โ”œโ”€โ”€ stderr/         # Feature implementations
โ”‚   โ”‚   โ”œโ”€โ”€ stderr.rs   # Core logging
โ”‚   โ”‚   โ”œโ”€โ”€ trace.rs    # Hierarchical tracing
โ”‚   โ”‚   โ”œโ”€โ”€ interactive.rs # Prompts & confirmations
โ”‚   โ”‚   โ”œโ”€โ”€ formatting.rs  # Tables, banners, boxes
โ”‚   โ”‚   โ””โ”€โ”€ static_logger.rs # Global logger
โ”‚   โ”œโ”€โ”€ macros.rs       # Convenience macros
โ”‚   โ””โ”€โ”€ meta.rs         # Version and help info
โ””โ”€โ”€ examples/           # Usage demonstrations

Feature Design

The modular architecture allows you to include only what you need:

  • Core (stderr.rs): Always available - basic logging functions

  • Trace Extension: Hierarchical function call tracking

  • Interactive Extension: User prompts and confirmations

  • Formatting Extension: Tables, banners, and advanced layout

  • Auto Function Names: Automatic function name detection

Environment Controls

# Enable different message types
export TRACE_MODE=0    # Show trace messages
export DEBUG_MODE=0    # Show debug messages  
export DEV_MODE=0      # Show dev messages
export SILLY_MODE=0    # Show magic/silly messages
export QUIET_MODE=0    # Enable quiet mode

# Run your application
cargo run

๐Ÿ“Š Hierarchical Tracing

Track function calls with visual hierarchy:

use rdx_stderr::{qtrace_fn, qtrace_auto, qtrace_scope};

fn process_data() {
    qtrace_fn!("process_data", "starting data processing");
    
    parse_input();
    validate_data();
    
    qtrace_fn!("process_data", "processing complete");
}

fn parse_input() {
    qtrace_auto!("parsing user input");  // Uses function name automatically
    
    // Scoped tracing with automatic entry/exit
    qtrace_scope!("validation", {
        qtrace_auto!("checking format");
        qtrace_auto!("format valid");
    });
}

Output:

ฮป process_data: starting data processing
โ”œโ”€ ฮป parse_input: parsing user input  
โ”‚  โ””โ”€ ฮป validation: checking format
โ”‚     โ””โ”€ ฮป validation: format valid
โ””โ”€ ฮป process_data: processing complete

๐ŸŽจ Rich Formatting

Tables

use rdx_stderr::Stderr;

let mut log = Stderr::new();

log.simple_table(&[
    &["Name", "Age", "City"],
    &["Alice", "30", "New York"],
    &["Bob", "25", "San Francisco"],
    &["Charlie", "35", "Chicago"],
])?;

Banners & Boxes

log.banner("System Status", '=')?;
log.boxed("CRITICAL: System maintenance in progress")?;

Context Banners

// Smart context management - only shows banner when context changes
log.set_context("@myapp.VAR.config");
log.info("First operation");  // Shows context banner

log.info("Second operation"); // No banner (same context)

log.set_context("@myapp.VAR.secrets");
log.info("Third operation");  // Shows new context banner

โœ… Interactive Elements

Simple Confirmations

if log.confirm("Delete all files?")?.unwrap_or(false) {
    log.warn("Deleting files...");
} else {
    log.info("Operation cancelled");
}

Styled Confirmations

let critical = "ERASE DISK?\nThis action cannot be undone.";
if log.confirm_builder(critical)
      .boxed(true)
      .style(BorderStyle::Heavy)
      .ask()?
      .unwrap_or(false) {
    log.error("Proceeding with disk erasure");
}

๐ŸŽญ Customizable Glyphs

Create your own visual style:

use rdx_stderr::{Stderr, GlyphSet, LogLevel};

// Custom emoji glyphs
let custom_glyphs = GlyphSet {
    info: "๐Ÿ“‹",
    warn: "โš ๏ธ", 
    error: "โŒ",
    okay: "โœ…",
    trace: "๐Ÿ”",
    debug: "๐Ÿ›",
    magic: "โœจ",
};

let mut log = Stderr::new().with_glyphs(custom_glyphs);
log.info("Info with custom emoji glyph");

// Or set individual glyphs
log.set_glyph(LogLevel::Info, "๐Ÿš€");
log.info("Info with rocket glyph");

๐Ÿงช Macro Convenience

Quick logging with macros:

use rdx_stderr::{qinfo, qwarn, qerror, qpretty};

qinfo!("System started successfully");
qwarn!("Configuration file not found");
qerror!(my_error_struct); // Auto pretty-prints Debug types
qpretty!("โšก", &complex_data); // Boxed, multiline pretty-dump

๐Ÿ” Debug & Inspection

Beautiful debug output for any type implementing Debug:

#[derive(Debug)]
struct AppState { 
    count: u32, 
    active: bool, 
    users: Vec<String> 
}

let state = AppState { 
    count: 42, 
    active: true, 
    users: vec!["alice".into(), "bob".into()] 
};

// Pretty debug output
log.info_debug(&state);

// Inspection interface
log.inspect().warn(&state);

๐ŸŽจ Color & Style System

Rich color and styling support:

use rdx_stderr::{Color, Glyph, Style};

let mut log = Stderr::new();

// Built-in semantic colors
log.okay("Success message in green");
log.warn("Warning message in yellow"); 
log.error("Error message in red");

// Custom glyphs
println!("Chess piece: {}", Glyph::PAWN);
println!("Arrow: {}", Glyph::ARROW_RIGHT);


๐Ÿ“š Examples

Basic CLI Application

use rdx_stderr::Stderr;

fn main() {
    let mut log = Stderr::new();
    
    log.info("Starting application");
    
    match process_files() {
        Ok(count) => log.okay(&format!("Processed {} files", count)),
        Err(e) => {
            log.error(&format!("Processing failed: {}", e));
            std::process::exit(1);
        }
    }
}

With Rich Output

use rdx_stderr::{Stderr, qtrace_fn};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut log = Stderr::new();
    
    log.banner("File Processor v1.0", '=')?;
    
    qtrace_fn!("main", "application started");
    
    // Show processing status
    log.simple_table(&[
        &["File", "Status", "Lines"],
        &["config.toml", "โœ“", "42"],
        &["data.json", "โœ“", "156"],
        &["README.md", "โœ“", "89"],
    ])?;
    
    if log.confirm("Process all files?")?.unwrap_or(false) {
        qtrace_fn!("main", "user confirmed processing");
        log.okay("All files processed successfully!");
    } else {
        log.warn("Processing cancelled by user");
    }
    
    Ok(())
}

๐Ÿ” Hierarchical Tracing

Manual Function Tracing

use stderr::Stderr;

fn main() {
    let mut log = Stderr::new();
    
    log.trace_fn("parse_config", "starting configuration");
    log.trace_fn("parse_config", "reading config file");
    log.trace_fn("validate_settings", "checking database URL");
    log.trace_fn("validate_settings", "database connection OK");
    log.trace_fn("parse_config", "configuration complete");
}

Output:

ฮปโ”„โ”„โ”„[parse_config]
    โ”†
    โ””โ”„โ”„> starting configuration
    โ””โ”„โ”„>> reading config file
ฮปโ”„โ”„โ”„[validate_settings]
    โ”†
    โ””โ”„โ”„> checking database URL
    โ””โ”„โ”„>> database connection OK
ฮปโ”„โ”„โ”„[parse_config]
    โ”†
    โ””โ”„โ”„>> configuration complete

Automatic Function Names

use stderr::{Stderr, qtrace_auto};

#[cfg(feature = "auto-fn-names")]
fn my_function() {
    qtrace_auto!("This automatically shows 'my_function' as the function name");
    qtrace_auto!("Performing some work");
    
    nested_function();
    
    qtrace_auto!("Work complete");
}

#[cfg(feature = "auto-fn-names")]
fn nested_function() {
    qtrace_auto!("Inside nested function");
}

Scoped Tracing (RAII)

use stderr::Stderr;

fn complex_operation() {
    let mut log = Stderr::new();
    
    let mut scope = log.trace_scope("complex_operation");
    scope.step("initializing resources");
    scope.step("processing data");
    scope.step_debug("intermediate result", &some_data);
    scope.step("finalizing");
    
    // Automatic exit trace when scope is dropped
}

Labelled Trace Helpers

use stderr::Stderr;

fn main() {
    let mut log = Stderr::new();
    
    log.trace_add("Creating new user account");
    log.trace_found("Located existing preferences");
    log.trace_item("Processing item #42");
    log.trace_done("User account setup complete");
    log.trace_sub("Cleaning up temporary files");
}

๐ŸŽฏ Context Management

Smart Context Banners

use stderr::Stderr;

fn main() {
    let mut log = Stderr::new();
    
    // First context - shows banner
    log.set_context("@myapp.VAR.config");
    log.info("Working in config context");
    
    // Same context - no banner
    log.set_context("@myapp.VAR.config");
    log.info("Still in config context");
    
    // Different context - shows new banner
    log.set_context("@myapp.VAR.secrets");
    log.warn("Switched to secrets context");
    
    // Clear context
    log.clear_context();
    log.info("Back to neutral context");
}

Output:

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€ Context: @myapp.VAR.config โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
[ฮป] Working in config context
[ฮป] Still in config context
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€ Context: @myapp.VAR.secrets โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
[โ–ณ] Switched to secrets context
[ฮป] Back to neutral context

Ephemeral Context

use stderr::Stderr;

fn main() {
    let mut log = Stderr::new();
    
    log.set_context("@main.VAR.config");
    log.info("In main context");
    
    // Temporary context without changing persistent cursor
    log.with_context("@temp.VAR.test", || {
        log.info("Temporary operation");
        log.warn("This won't change the main context");
    });
    
    log.info("Back in main context");
}

๐Ÿ“Š Table & Data Formatting

A demo of the rdx-stderr logger in action

Simple Tables

use stderr::Stderr;

fn main() -> std::io::Result<()> {
    let mut log = Stderr::new();
    
    log.simple_table(&[
        &["Name", "Type", "Size", "Modified"],
        &["config.env", "file", "1.2KB", "2024-01-15"],
        &["secrets/", "dir", "--", "2024-01-14"],
        &["api_keys.json", "file", "856B", "2024-01-13"],
    ])?;
    
    Ok(())
}

Column Layouts

use stderr::Stderr;

fn main() -> std::io::Result<()> {
    let mut log = Stderr::new();
    
    let items = [
        "config", "secrets", "api_keys", "database",
        "redis", "jwt", "oauth", "webhooks",
        "logging", "monitoring", "alerts", "backup"
    ];
    
    log.columns(&items, 4)?;
    
    Ok(())
}

Flag Tables (Bitmap Visualization)

use stderr::{Stderr, BorderStyle, flag_table, term_width};

fn main() {
    let mut log = Stderr::new();
    
    let flags: u32 = 0b1010_1100_0011_0101;
    let labels = &[
        "READ", "WRITE", "EXEC", "DELETE",
        "CREATE", "UPDATE", "LIST", "ADMIN",
        "DEBUG", "TRACE", "BACKUP", "RESTORE",
        "MONITOR", "ALERT", "SYNC", "ASYNC


๐Ÿ—๏ธ Architecture

src/
โ”œโ”€โ”€ lib.rs              # Main library interface
โ”œโ”€โ”€ rdx/
โ”‚   โ”œโ”€โ”€ stderr.rs       # Core module with feature re-exports
โ”‚   โ”œโ”€โ”€ esc/            # Colors, glyphs, styling
โ”‚   โ”‚   โ”œโ”€โ”€ colors.rs
โ”‚   โ”‚   โ”œโ”€โ”€ glyphs.rs
โ”‚   โ”‚   โ”œโ”€โ”€ style.rs
โ”‚   โ”‚   โ””โ”€โ”€ boxes.rs
โ”‚   โ”œโ”€โ”€ utils/          # Utilities and helpers  
โ”‚   โ”‚   โ”œโ”€โ”€ helpers.rs
โ”‚   โ”‚   โ”œโ”€โ”€ flag.rs
โ”‚   โ”‚   โ””โ”€โ”€ grid.rs
โ”‚   โ”œโ”€โ”€ stderr/         # Feature implementations
โ”‚   โ”‚   โ”œโ”€โ”€ stderr.rs   # Core logging
โ”‚   โ”‚   โ”œโ”€โ”€ trace.rs    # Hierarchical tracing
โ”‚   โ”‚   โ”œโ”€โ”€ interactive.rs # Prompts & confirmations
โ”‚   โ”‚   โ”œโ”€โ”€ formatting.rs  # Tables, banners, boxes
โ”‚   โ”‚   โ””โ”€โ”€ static_logger.rs # Global logger
โ”‚   โ”œโ”€โ”€ macros.rs       # Convenience macros
โ”‚   โ””โ”€โ”€ meta.rs         # Version and help info
โ””โ”€โ”€ examples/           # Usage demonstrations

๐Ÿงช Testing & Validation

The library includes comprehensive test drivers and examples:

# Run all examples
cargo run --example trace_driver --all-features
cargo run --example interactive_driver --all-features
cargo run --example formatting_driver --all-features

# Test specific features
cargo test --features trace
cargo test --features interactive
cargo test --features formatting

๐Ÿค Used By

rdx-stderr is actively used by:

  • BookDB: Context-aware key-value store with rich CLI output
  • Various CLI tools: Where beautiful terminal output matters
  • Internal Rustadex projects: Providing consistent UX across tools

Using rdx-stderr in your project? Let us know!


๐Ÿ—บ๏ธ Roadmap

Current (v0.8.x)

  • โœ… Modular feature architecture
  • โœ… Hierarchical tracing system
  • โœ… Rich formatting capabilities
  • โœ… Interactive confirmations
  • โœ… Context management

Future (v0.8.3)

  • Progress bars and spinners
  • Configuration file support
  • Plugin architecture for custom formatters
  • Terminal capability detection
  • Enhanced color palette support

License

This project is licensed under either of:

at your option.

Commit count: 0

cargo fmt